Java Interview Questions

lella keerthi
4 min readSep 29, 2021

1. What is a ClassLoader?

A classloader in Java is a subsystem of Java Virtual Machine, dedicated to loading class files when a program is executed; ClassLoader is the first to load the executable file. Java online training

Java has Bootstrap, Extension, and Application classloaders.

2. What are the Memory Allocations available in JavaJava?

Java has five significant types of memory allocations.

  • Class Memory
  • Heap Memory
  • Stack Memory
  • Program Counter-Memory
  • Native Method Stack Memory

3. Will the program run if we write static public void main?

Yes, the program will successfully execute if written so. Because, in Java, there is no specific rule for the order of specifiers

4. What is the default value stored in Local Variables?

Neither the Local Variables nor any primitives and Object references have any default value stored in them.

5. Explain the expected output of the following code segment?

public class Simplilearn

{

public static void main (String args[])

{

System.out.println(100 + 100 +“Simplilearn”);

System.out.println(“E-Learning Company” + 100 + 100);

}

}

The answers for the two print statements are as follows.

  • 200Simplilearn
  • E-Learning Company100100

6. What is an Association?

An Association can be defined as a relationship that has no ownership over another. For example, a person can be associated with multiple banks, and a bank can be related to various people, but no one can own the other. know more at Java training

7. Define Copy Constructor in Java

A Copy Constructor in Java is a constructor that initializes an object through another object of the same class.

8. What is a Marker Interface?

An empty interface in JavaJava is referred to as a Marker interface. Serializable and Cloneable are some famous examples of Marker Interface.

9. What is Object Cloning?

An ability to recreate an object entirely similar to an existing object is known as Object Cloning in Java. Java provides a clone() method to clone a current object offering the same functionality as the original object.

10. Why is Java not completely object-oriented?

Java is not considered as a 100% object-oriented programming language because it still makes use of eight or more primitive data types like int, float double, etc.

11. Define Wrapper Classes in Java.

In Java, when you declare primitive datatypes, then Wrapper classes are responsible for converting them into objects(Reference types).

12. Define Singleton Classes in Java.

In Java, when you make the constructor of a class private, that particular class can generate only one object. This type of class is popularly known as a Singleton Class. know more at Java online course

13. Define package in Java.

The package is a collective bundle of classes and interfaces and the necessary libraries and JAR files. The use of packages helps in code reusability.

14. Can you implement pointers in a Java Program?

Java Virtual Machine takes care of memory management implicitly. Java’s primary motto was to keep programming simple. So, accessing memory directly through pointers is not a recommended action. Hence, pointers are eliminated in Java.

15. Differentiate between instance and local variables.

For instance, variables are declared inside a class, and the scope is limited to only a specific object.

A local variable can be anywhere inside a method or a specific block of code. Also, the scope is limited to the code segment where the variable is declared.

16. Explain Java String Pool.

A collection of strings in Java’s Heap memory is referred to as Java String Pool. In case you try to create a new string object, JVM first checks for the presence of the object in the pool. If available, the same object reference is shared with the variable, else a new object is created. know more at Java online training in Hyderabad

17. What is an Exception?

An Exception in Java is considered an unexpected event that can disrupt the program’s normal flow. These events can be fixed through the process of Exception Handling.

18. What is the final keyword in Java?

The term final is a predefined word in Java that is used while declaring values to variables. When a value is declared using the final keyword, then the variable’s value remains constant throughout the program’s execution.

19. What happens when the main() isn’t declared as static?

When the main method is not declared as static, then the program may be compiled correctly but ends up with a severe ambiguity and throws a run time error that reads “NoSuchMethodError.”

20. What is JDK? Mention the variants of JDK?

JDK is an abbreviation for Java Development Kit. It is a combined Package of JRE and Developer tools used for designing Java Applications and Applets. Oracle has the following variants.

  • JDK Standard Edition
  • JDK Enterprise Edition
  • JDK Micro Edition

21. What are Brief Access Specifiers and Types of Access Specifiers?

Access Specifiers are predefined keywords used to help JVM understand the scope of a variable, method, and class. We have four access specifiers.

  • Public Access Specifier
  • Private Access Specifier
  • Protected Access Specifier
  • Default Access Specifier

23. Can a constructor return a value?

Yes, A constructor can return a value. It replaces the class’s current instance implicitly; you cannot make a constructor return a value explicitly.

24. Explain ‘this’ keyword in Java.

The term “this” is a particular keyword designated as a reference keyword. The “this” keyword is used to refer to the current class properties like method, instance, variable, and constructors.

25. Explain ‘super’ keyword in Java.

The term “super” is a particular keyword designated as a reference keyword. The “super” keyword refers to the immediate parent class object. know more at Java online training course

26. Explain Method Overloading in Java.

The process of creating multiple method signatures using one method name is called Method Overloading in Java. Two ways to achieve method overloading are:

  1. Varying the number of arguments
  2. Changing the return type of the Method

--

--