Core Java Interview Questions- Part 9

Core Java Interview Questions- Part 9Java is a language that has stood the test of time. It’s used to build programs that run on everything from phones to bank systems. If you’re trying to get a job in tech, learning Java is a smart choice. But learning the language is just the first step—acing the interview is the next.
Employers use Java interviews to test how well you know the language. They want to see if you understand key ideas like inheritance, abstraction, interfaces, loops, and collections. They might also test your problem-solving skills by asking you to write code or fix bugs.
This page is full of Java interview questions that many companies ask. Each question comes with a simple explanation to help you understand the concept better. Going through these questions will help you prepare for both technical rounds and coding tests.
No matter your experience level, these questions can help you sharpen your skills. Take your time to study them, and don’t be afraid to go back to the basics. The more you practice, the more confident you’ll feel when it’s time to sit for the interview.

Answer:

Java does not support multiple inheritance where one class can inherit properties from more than one class. It is known as the diamond problem.

Answer:

Aggregation is a term that defines a one-way relationship between two objects. In Java, Aggregation depicts the HAS-A relationship, meaning that a class contains another class reference.

Answer:

Recursion is a technique of making a function call itself. It provides a way to break down complex problems into simple problems that can be solved quickly.

Answer:

Autoboxing is a process of converting primitive data types into an object of their corresponding wrapper class. Unboxing is the reverse of the autoboxing process.

Answer:

An Iterator is an object used to loop through collections, like HashSet & ArrayList. It is called an “iterator” because “iterating” is the technical term for looping. You must import it from java.util package to use an Iterator.

Answer:

HashMap means a collection framework functionality used for storing data into key and value pairs. It internally uses linked lists to support the storage functionality.

Answer:

A Stack is a (LIFO) Last In First Out data structure that supports two fundamental operations called pop & push. The push operation helps to add an element at the top of the stack, while the pop operation is useful for removing an element from the top.

Answer:

TreeMap in Java is a navigable map interpretation built around the concepts of red & black trees. Its keys are always sorted in ascending order.

Answer:

Java supports the following types of constructors:

  • Default Constructor or No-argument constructor
  • Parameterized Constructor
  • Copy Constructor

Answer:

A singleton class in Java is a class that can have one instance of it in an application. If a new instance is created for the same class, it points to the first instance. Thus, have the same values for all properties & attributes. A singleton class helps to create global points of access to objects. The singleton class primary usage is caching, logging, and device drivers that are all entities for universal access.

Answer:

There are two types of polymorphisms that can be performed through the following ways:

  • Static binding or compile-time polymorphism– Method overloading
  • Dynamic binding or runtime polymorphism – Method overriding

Answer:

An object is an entity that has a state & behavior. It is an instance of a class & an object is a real-world entity. You can create an object to access the defined members in the class.

Answer:

When a thread is working on an object & preventing other threads from working on the same object, it is called thread-safe. In Java, there is a collection of thread-safe classes like Hashtable, Properties, Vector, Stack, etc.

Answer:

When you start Java programming, the first method you will encounter is the public static void main(String [] args). The starting point of any Java program where it starts its execution is known as the main() method. It is an essential method of Java. JVM looks for the main method to start running a Java application.

Answer:

Declaration includes informing the compiler about the variable’s properties, but Definition is all about implementation & memory location. Declaration of a variable or function can occur multiple times, but a variable or function can only be defined once.

Answer:

Declaring a method in child class that already exists in the parent class is known as Method Overriding. To simply put, overriding means to override the functionality of an existing method.

Answer:

The sleep() is a method in Java used to pause the process for a few seconds or for the time we want it to be paused. In the case of the wait() method, the thread goes in the waiting mode & doesn’t come back automatically till we call notifyAll() or notify(). The major difference between wait() & sleep() methods is the former monitor or releases the lock when waiting, while the latter doesn’t monitor or releases the lock while waiting. The wait() method helps in inter-thread communication, while the sleep() method enables us to introduce pause on execution.

Answer:

Transient keyword in Java is useful to mark a variable not to be serialized when persisted to streams of bytes. It plays an essential role in meeting the security constraints in Java. Transient keyword ignores a variable’s original value & saves the default value of that data type.