Java: Interview Questions and Answers





Q: What do you know about Java?
A: Java is a high-level programming language originally developed by Sun Microsystems and released in 1995.
Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

Q: What are the supported platforms by Java Programming Language?
A: Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX/Linux like HP-Unix, Sun Solaris, Redhat Linux, Ubuntu, CentOS, etc.

Q: List two Java IDE’s?
A: Netbeans, Eclipse, etc.

Q: List some Java keywords(unlike C, C++ keywords)?
A: Some Java keywords are import, super, finally, etc.

Q: What do you mean by Object?
A: Object is a runtime entity and it’s state is stored in fields and behavior is shown via methods.
 Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.

Q: What do you mean by Constructor?
A: Constructor gets invoked when a new object is created. Every class has a constructor.
 If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class.

Q: What is the default value of float and double datatype in Java?
A: Default value of float and double datatype in different as compared to C/C++. For float its 0.0f and for double it’s 0.0d
Q: How finally used under Exception Handling?
A: The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.

Q: What is Encapsulation?
A: It is the technique of making the fields in a class private and providing access to the fields via public methods.
 If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class.
Therefore encapsulation is also referred to as data hiding.

Q: What is the purpose of garbage collection in Java, and when is it used?
A: 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.

Q: What if the static modifier is removed from the signature of the main() method?

A: Program compiles. But at runtime throws an error "NoSuchMethodError".


Q:  What if I write static public void instead of public static void?

A: Program compiles and runs properly.

Q:. What is the difference between an Interface and an Abstract class?

A: An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.

An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.




No comments:

Post a Comment

We are here to listen you, Comment your valueable opinion...!!!