HP @ Java Interview Questions for HP

Way java is platform independent ?
  • 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.
What if the main method is declared as private?
  • The program compiles properly but at runtime it will give error Message as 'Main method not public'.
What is the purpose of garbage collection in Java ?
  • 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.
What are statements in JAVA ?
  • Statements are equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon
  • Assignment expressions
  • Method calls
  • Any use of ++ or --
  • Object creation expressions
what is difference between instance and object.?
  • Instance means just creating a reference(copy) . Object :means when memory location is associated with the object( is a runtime entity of the class) by using the new operator.
What is JNI?
  • JNI is an acronym of Java Native Interface. Using JNI we can call functions which are written in other languages from Java.
What is the meaning of supplying string[] args to main method?
  • public static void main(String args[]) This array of Strings is the mechanism through which the runtime system passes information to your application. Each String in the array is called a command line argument.
What is serialization?
  • Quite simply, object serialization provides a program the ability to read or write a whole object to and from a raw byte stream. It allows Java objects and primitives to be encoded into a byte stream suitable for streaming to some type of network or to a file-system, or more generally, to a transmission medium or storage facility. A seralizable object must implement the Serilizable interface. We use ObjectOutputStream to write this object to a stream and ObjectInputStream to read it from the stream.
In how many ways we can create an object? Explain with example.
  • Using New KeyWord
  • Using ClassForName.

 new class-name();
 class.ForName("Class-Name");  
Is synchronised a modifier?indentifier??what is it ?
  • It's a modifier. Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email