JAVA Training at Lotus IT Hub are designed to
achieve and enhance professional skills in JAVA .
The training is designed for individuals who wish
to build skills in JAVA .
As the leader in Software Training and Quality Assurance Training . Lotus IT Hub has the most comprehensive list Courses in Software. Our Courses are taught only by experts with a minimum of 4 years of Industrial Experience.
Sample Interview question and answer
1.What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no
return type, and is invoked using the new operator.A method is an ordinary member function of a class. It has its own name,a return type
(which may be void), and is invoked using the dot operator.
2.What is the purpose of garbage collection in Java, and when is it used?
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be
reclaimed and reused.A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
3.What is Polymorphism?
The Polymorphism can be referred as one name many forms. It is the ability of methods to behave differently, depending upon the object
who is calling it. The key features of Polymorphism are :
1. Allows using one interface for multiple implementations.
2. Supports Method Overloading: Multiple methods with same name, but different formal argument.
3. Supports Method Overridden: Multiple methods have the same name, same return type, and same formal argument list.
4.Explain garbage collection.
The Java uses the garbage collection to free the memory. By cleaning those objects that are no longer reference by any of the program.
Step involve in cleaning up the garbage collection :
Garbage Object Collection : First step is to collection and group all those object which are no more reference with any of the program.
We can use the different methods to collect the garbage object like using runtime.gc() or system.gc().
Run Finalize method : To free up those object which is collected by the garbage collector java must execute the Finalize method to
delete all those dynamically created object.
5.What is the Set interface?
- A set interface is a collection of element which cannot be duplicated.
- The set interface contains methods inherited from the collection.
- It provides methods to access the elements of a finite mathematical set.
- Two Set objects are equal if they contain the same elements.
- It models the mathematical set abstraction.
6.What if I write static public void instead of public static void?
Program compiles and runs properly.
7.What if I do not provide the String array as the argument to the method?
Program compiles but throws a runtime error "NoSuchMethodError".
8.What is the first argument of the String array in main() method?
The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.
9.If I do not provide any arguments on the command line, then the String array of main() method will be empty or null?
It is empty. But not null.
10.How can one prove that the array is not null but empty using one line of code?
Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.
11.What environment variables do I need to set on my machine in order to be able to run Java programs?
CLASSPATH and PATH are the two variables.

No comments:
Post a Comment