Quick Revision Tips

  1. 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.

  2. 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 

  3. A static method can't be overridden to non-static and vice versa.

  4. The variables in java can have the same name as method or class.
  5. All the static variables are initialized when the class is loaded.
  6. An interface can extend more than one interface, while a class can extend only one class.
  7. 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.

  8. A final class cannot have abstract methods.

  9. All methods of a final class are automatically final.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. An overriding method may not throw a checked exception unless the overridden method also throws that exception or a superclass of that exception.

  16. Interface methods can't be native, static, synchronized, final, private, protected or abstract.

  17. The String class is a final class, it can't be subclassed.

  18. The Math class has a private constructor, it can't be instantiated.

  19. 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.

  20. The various methods of Java.lang.Object are
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString and wait. 

  21. Garbage collection in java cannot be forced. The methods used to call garbage collection thread are System.gc() and Runtime.gc()

  22. Inner class may be private, protected, final, abstract or static.

  23. To refer to a field or method in the outer class instance from within the inner class, use Outer.this.fieldname .
  24. Inner classes may not declare static initializers or static members unless they are compile time constants i.e. static final var = value;
  25. A nested class cannot have the same name as any of its enclosing classes.
  26. 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();
        }
    }

  27. 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.

  28. Using the synchronized keyword in the method declaration, requires a thread obtain the lock for this object before it can execute the method.
  29. A synchronized method can be overridden to be not synchronized and vice versa.
  30. 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 ({}).

  31. The notify() mthod moves one thread, that is waiting on this object's monitor, into the Ready state. This could be any of the waiting threads.
  32. The notifyAll() method moves all threads, waiting on this object's monitor into the Ready state.
  33. The argument to switch can be either byte, short , char or int.

  34. 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.

  35. For the RandomAccessFile constructor, the mode argument must either be equal to "r" or "rw".
  36. In java, console input is accomplished by reading from System.in .
  37. System.in is an object of type InputStream; System.out and System.err are objects of type PrintStream.
  38. Both FileInputStream and FileOutputStream classes throws FileNotFoundException. In earlier versions of java, FileOutputStream() threw an IOException when an output could not be created.
  39. System.in is an object of type InputStream; System.out and System.err are objects of type PrintStream.
  40. 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.

  41. 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. 

  42. The (-0.0 == 0.0) will return true, while (5.0==-5.0) will return false.

  43. 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.

  44. The default Layout Manager for Panel and Applet is Flow. For Frame and Window its BorderLayout.

  45. The FlowLayout always honors the a component's preferred size.

  46. 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.

  47. 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.

  48. The example of array declaration along with initialization - int k[] = new int[]{1,2,3,4,9};

  49. 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

  50. A constructor cannot be native, abstract, static, synchronized or final.

Note : Complete listing is available in the registered version.