Core Java Interview Questions (Before OOPs)
1. What is Java?
Java is a high-level, object-oriented, and platform-independent programming language. It follows
the principle of Write Once, Run Anywhere because Java code is compiled into bytecode that runs
on the Java Virtual Machine (JVM).
2. Why is Java platform independent?
Java is platform independent because its source code is compiled into bytecode, which can run on
any system that has a compatible JVM installed.
3. Difference between JDK, JRE, and JVM?
JDK (Java Development Kit) is used for developing Java applications and includes development
tools. JRE (Java Runtime Environment) is used to run Java applications. JVM (Java Virtual
Machine) executes the bytecode.
4. What are primitive data types in Java?
Java has eight primitive data types: byte, short, int, long, float, double, char, and boolean. These
store simple values and are not objects.
5. Difference between == and equals()?
The == operator compares memory references, while equals() compares the actual content of
objects.
6. Why is String immutable in Java?
String is immutable to ensure security, better performance, and efficient memory utilization through
the String pool concept.
7. What is an array in Java?
An array is a collection of elements of the same data type stored in contiguous memory locations.
8. Difference between for loop and while loop?
A for loop is used when the number of iterations is known, while a while loop is used when the
iterations depend on a condition.
9. What is Garbage Collection?
Garbage Collection is an automatic memory management process that removes unused objects
from heap memory.
10. Difference between Stack and Heap memory?
Stack memory stores local variables and method calls, while heap memory stores objects and is
managed by the Garbage Collector.