Create a Scanner object object in order to invoke its methods. Object in java are created using the new operator.
Scanner scan = new Scanner(System.in);
scan.next*
enum should be define in a class and before the main() function
The compiler will issue an error if a static method attempts to use a non-static variable. A static method can reference static variables because static variables exist independent of specific objects. Therefor, all static methods, including the main method can access only static or local variables.
The this reference can be used to refer to the currently executing object.
The compiler will issue an error if a static method attempts to use a non-static variable. A static method can reference static variables because static variables exist independent of specific objects. Therefor, all static methods, including the main method can access only static or local variables.
The this reference can be used to refer to the currently executing object.
System.out.println(Runtime.getRuntime().maxMemory());
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
Declaring an array: int [] height = new int[10];
The index operator performs automatic bounds checking, which ensures that the index is in range for the array being referenced.
The index operator performs automatic bounds checking, which ensures that the index is in range for the array being referenced.
Java accepts variable-length parameters lists. By using some special syntax in the formal parameter list of the method, we can define the method to accept any number of parameters. The parameters are automatically put into an array for easy processing in the method. For example
public void printGrades (Grade ... grades)
{
for (Grade letterGrade : grades)
System.out.println(letterGrade);
}
The varying parameters much come last in the formal arguments. A single method cannot accept two sets of varying parameters.
Two dimensional array
int [][] table = new int[5][10];
for (int row = 0; row < table.length; row++)
for (int col = 0; col < table[row].length; col++)
The super reference: super can be used in a class to refer to its parent class. Using the super reference, we can access a parent's members. Like the this reference, what the word super refers to depends on the class in which it is used.
A common use of the super reference is to invoke a parent's constructor. A child's constructor is responsible for calling its parent's constructor. Generally, the first line of a constructor should use the super reference call to a constructor of the parent class. If no such call exists, java will automatically make a call to super with no parameter ar the beginning of the constructor.
An abstract class canot be instantiated an usually contains one more abstract methods, which have no definition. A class is declared as abstract by including the abstract modifier in the class header. Any class that contains one or more abstract methods must be declared as abstract. In abstract classes, the abstract modifier must be applied to each abstract method.
We can create a polymorphic reference in Java in two ways: using inheritance and using interfaces.
A java Interface is a collection of constants and abstract methods. A class that implements an interface use the reserved word implements followed by the interface name in the class header. Multiple classes can implement the same interface, providing their own definitions for the methods.
public interface Encryptable
{
public void encrypt();
public String decrypt();
}
public class Secret implements Encryptable
{
public void encrypt() {}
}
class ManyThings implements Interface1, Interface2, Interface3
{
// Implements all methods of all interfaces
}
public void printGrades (Grade ... grades)
{
for (Grade letterGrade : grades)
System.out.println(letterGrade);
}
The varying parameters much come last in the formal arguments. A single method cannot accept two sets of varying parameters.
Two dimensional array
int [][] table = new int[5][10];
for (int row = 0; row < table.length; row++)
for (int col = 0; col < table[row].length; col++)
The super reference: super can be used in a class to refer to its parent class. Using the super reference, we can access a parent's members. Like the this reference, what the word super refers to depends on the class in which it is used.
A common use of the super reference is to invoke a parent's constructor. A child's constructor is responsible for calling its parent's constructor. Generally, the first line of a constructor should use the super reference call to a constructor of the parent class. If no such call exists, java will automatically make a call to super with no parameter ar the beginning of the constructor.
An abstract class canot be instantiated an usually contains one more abstract methods, which have no definition. A class is declared as abstract by including the abstract modifier in the class header. Any class that contains one or more abstract methods must be declared as abstract. In abstract classes, the abstract modifier must be applied to each abstract method.
We can create a polymorphic reference in Java in two ways: using inheritance and using interfaces.
A java Interface is a collection of constants and abstract methods. A class that implements an interface use the reserved word implements followed by the interface name in the class header. Multiple classes can implement the same interface, providing their own definitions for the methods.
public interface Encryptable
{
public void encrypt();
public String decrypt();
}
public class Secret implements Encryptable
{
public void encrypt() {}
}
class ManyThings implements Interface1, Interface2, Interface3
{
// Implements all methods of all interfaces
}
No comments:
Post a Comment