Recentedly posted Jobs

Java Programming Interview Questions and Answers

Java Programming Interview Questions and Answers

Question 1 What are difference between JDK, JRE and JVM?

Ans. –JDK stands for Java Development Kit, which contains the JRE and other development tools.

JRE stands for Java Runtime Environment which is the implementation of JVM, and JVM is the Java Virtual Machine. JVM is an abstract machine which provides the runtime environment in which java byte code can be executed.

Question 2 What do you know by Java?

Ans. – Java is an Object Oriented Programming Language developed by Sun microsystems in 1995.  It is a platform independent language with respect to JVM.

Question 3 Can you distinguish between Object Oriented language and Object based Language?

Ans. –Object based languages is same like Object Oriented language only the difference is that there is no  feature of Inheritance in it. Some examples of it are – Javascript and VBScript.

Question 4 What does constructor mean in a class?

Ans. –Constructor special member function in any class which name is same as the class name. By default constructor are invoked at the time of object creation and we can use it for initializing and also can make own constructor.

Question 5 Define Interface?

Ans. –An interface is like way of describing the class requirements that want to conform to the interface. It is the way of describing what class should do but not describes how class should do that.

Question 6 What is a pointer and does Java support it?

Ans. –Pointer are reference data type. Java doesn’t support pointer because of improper handling of pointers leads to memory escapes and reliability issues.

Question 7 What is difference between public, protected and private?

Ans. –Public class members can be accessed to any class.

Protected are only accessible by subclasses that inherit it.

And Private members are only can be accessed by those of the being class.

Question 8 Difference between the constructor and normal functions?

Ans. –Constructor name is same as the class name and cannot return a value. These are only once called. The normal function can be the call at the time required and we can repeatedly call normal function when needed. Normal function also can return value.

Question 9 Tell about class-loader?

Ans. – The class-loader is used to load classes and interfaces. It is a subsystem of JVM. There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc.

Question 10 Can a lock be acquired on a class?

Ans. –Yes a lock can be acquired on a class.

Question 11 Explain the Polymorphism principle?

Ans. – Polymorphism is a concept of method overloading. Poly means Multi and morphism is used of tasks. Java does not support operator overloading.

Question 12 What will be the output of following –

public static void main(String[]args){
 int x =3, y =1;
if (x=y)
System.out.println(“not similar”);
Else
System.out.println(“similar”);
}

Ans. –An error will occur at if(x=y) and causes compilation fail.

Question 13 What are instance variables?

Ans.– Instances variables are those which are defined at the class level and not need to be initialized because it automatically initialized with their default value.

Question 14 Why java doesn’t support multiple inheritances?

Ans. –There is a basic reason behind this – first is ambiguity around Diamond problem and second reason is it complicates the design and creates problem while casting, constructor chain etc.

Question 15 Why character array is better than String for storing password in Java?

Ans. – Since Strings are immutable in Java that’s why if password stored in String than it is more prone to security threats. So, storing password in character is safe then in String.

Question 16 What is difference between Serializable and Externalizable interface in Java?

Ans. –Externalizable provides us writeExternal() and readExternal() method which gives us flexibility to control java serialization mechanism instead of relying on Java's default serialization. Correct implementation of Externalizable interface can improve performance of application drastically.

Questions 17 How do you add a new item in ArrayList?

Ans. –We can add new item in ArrayList using the code

List<String> list = new ArrayList<>();
list.add(“a”);
list.add(“h”);

Question 18 List any two IDE for Java?

Ans. –Eclipse and Netbeans is largely used.

Question 19 Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

Ans. –LinkedHashMap

Question 20 Which cannot directly cause a thread to stop executing?

Ans. – notify() method on an object, it wakes up a single thread that is waiting on the object’s monitor.

The above Java programming Interview Questions and Answers will help you in qualifying the Technical Interview based on Java Programming language. All the best

Get All New Job Updates in your Email

0 comments:

Post a Comment