Search This Blog

Monday, January 12, 2009

Java Questions

  • Interview Questions on Java
  • What if the main method is declared as private?

    The program compiles properly but at runtime it will give “Main method not public.” message.

    What is meant by pass by reference and pass by value in Java?

    Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value.

    If you’re overriding the method equals() of an object, which other method you might also consider?

    hashCode()

    What is Byte Code?

    Or

    What gives java it’s “write once and run anywhere” nature?


    All Java programs are compiled into class files that contain bytecodes. These byte codes can be run in any platform and hence java is said to be platform independent.

    Expain the reason for each keyword of public static void main(String args[])?

    public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.

    static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.

    void: main does not return anything so the return type must be void

    The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line.
  • What is the difference between final, finally and finalize?

    Or

    What does it mean that a class or member is final? 

    o final - declare constant
    o finally - handles exception
    o finalize - helps in garbage collection
  • There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.

    Explain the Inheritance principle.

    Inheritance is the process by which one object acquires the properties of another object. Inheritance allows well-tested procedures to be reused and enables changes to make once and have effect in all relevant places

    What is implicit casting?

    Implicit casting is the process of simply assigning one entity to another without any transformation guidance to the compiler. This type of casting is not permitted in all kinds of transformations and may not work for all scenarios.

    Example

    int i = 1000;

    long j = i; //Implicit casting

    Is sizeof a keyword in java?

    The sizeof operator is not a keyword.

    What is a native method?

    A native method is a method that is implemented in a language other than Java.

    In System.out.println(), what is System, out and println?

    System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object.



No comments:

Post a Comment