Quick Revision Tips
An identifier in java must begin with a letter , a dollar sign($), or an underscore (-); subsequent characters may be letters, dollar signs, underscores, or digits.
There are three top-level elements that
may appear in a file. None of these elements is required. If they are present,
then they must appear in the following order:
-package declaration
-import statements
-class definitions
A static method can't be overridden to non-static and vice versa.
The variables in an interface are implicitly final and static.If the interface , itself, is declared as public the methods and variables are implicitly public.
A final class cannot have abstract methods.
All methods of a final class are automatically final.
While casting one class to another subclass
to superclass is allowed without any type casting.
e.g.. A extends B , B b = new A(); is valid but not the reverse.
The String class in java is immutable.
Once an instance is created, the string it contains cannot be changed.
e.g. String s1 = new String("test"); s1.concat("test1"); Even after calling
concat() method on s1, the value of s1 will remain to be "test". What actually
happens is a new instance is created.
But the StringBuffer class is mutable.
The short circuit logical operators && and || provide logical AND and OR operations on boolean types and unlike & and | , these are not applicable to integral types. The valuable additional feature provided by these operators is the right operand is not evaluated if the result of the operation can be determined after evaluating only the left operand.
The difference between x = ++y; and
x = y++;
In the first case y will be incremented first and then assigned to x. In
second case first y will be assigned to x then it will be incremented.
The initialization values for different
data types in java is as follows
byte = 0, int = 0, short = 0, char
= '\u0000', long = 0L, float = 0.0f, double = 0.0d, boolean = false,
object referenece(of any object) = null.
An overriding method may not throw a checked exception unless the overridden method also throws that exception or a superclass of that exception.
Interface methods can't be native, static, synchronized, final, private, protected or abstract.
The String class is a final class, it can't be subclassed.
The Math class has a private constructor, it can't be instantiated.
The two kinds of exceptions in java
are : Compile time (Checked ) and Run time (Unchecked) exceptions. All subclasses
of Exception except the RunTimeException and its subclasses are checked
exceptions.
Examples of Checked exception : IOException, ClassNotFoundException.
Examples of Runtime exception :ArrayIndexOutOfBoundsException,NullPointerException,
ClassCastException, ArithmeticException, NumberFormatException.
The various methods of Java.lang.Object
are
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString
and wait.
Garbage collection in java cannot be forced. The methods used to call garbage collection thread are System.gc() and Runtime.gc()
Inner class may be private, protected, final, abstract or static.
An example of creation of instance
of an inner class from some other class:
class Outer
{
public class Inner{}
}
class Another
{
public void amethod()
{
Outer.Inner i = new Outer().new
Inner();
}
}
The range of Thread priority in java is 1-10. The minimum priority is 1 and the maximum is 10. The default priority of any thread in java is 5.
There are two ways to mark code as synchronized:
a.) Synchronize an entire method by putting the synchronized modifier in
the method's declaration.
b.) Synchronize a subset of a method by surrounding the desired lines of
code with curly brackets ({}).
The argument to switch can be either byte, short , char or int.
Breaking to a label (using break <labelname>;) means that the loop at the label will be terminated and any outer loop will keep iterating. While a continue to a label (using continue <lablename>;) continues execution with the next iteration of the labeled loop.
A static method can only call static variables or other static methods, without using the instance of the class. e.g. main() method can't directly access any non static method or variable, but using the instance of the class it can.
The if() statement in java takes only boolean as an argument. Please note that if (a=true){}, provided a is of type boolean is a valid statement and the code inside the if block will be executed.
The (-0.0 == 0.0) will return true, while (5.0==-5.0) will return false.
An abstract class may not have even a single abstract method but if a class has an abstract method it has to be declared as abstract.
The default Layout Manager for Panel and Applet is Flow. For Frame and Window its BorderLayout.
The FlowLayout always honors the a component's preferred size.
The statement float f = 5.0; will give compilation error as default type for floating values is double and double can't be directly assigned to float without casting.
The equals() method in String class
compares the values of two Strings while == compares the memory address
of the objects being compared.
e.g. String s = new String("test"); String s1 = new String("test");
s.equals(s1) will return true while s==s1 will return false.
The example of array declaration along with initialization - int k[] = new int[]{1,2,3,4,9};
The octal number in java is preceded
by 0 while the hexadecimal by 0x (x may be in small case or upper case)
e.g.
octal :022
hexadecimal :0x12
A constructor cannot be native, abstract, static, synchronized or final.
Note : Complete listing is available in the registered version.