☕
Core Java Interview Questions
Fundamental concepts including JVM, variables, data types, and operators.
JVMVariablesData TypesOperatorsControl Flow
1Explain JVM Architecture and its components.
Medium▼
Explain JVM Architecture and its components.
The JVM (Java Virtual Machine) consists of three main subsystems:
1. **Class Loader Subsystem**: Loads, links, and initializes class files.
2. **Runtime Data Areas**:
- Method Area: Class structures, static variables
- Heap Area: Objects and arrays
- Stack Area: Method calls, local variables
- PC Register: Current instruction address
- Native Method Stack: Native method information
3. **Execution Engine**:
- Interpreter: Executes bytecode line by line
- JIT Compiler: Compiles hot code to native machine code
- Garbage Collector: Manages memory
2What is the difference between JDK, JRE, and JVM?
Easy▼
What is the difference between JDK, JRE, and JVM?
**JVM (Java Virtual Machine)**: The abstract machine that executes Java bytecode. It provides platform independence but is itself platform-dependent.
**JRE (Java Runtime Environment)**: Implementation of JVM. Includes JVM + Core Libraries + Supporting Files. It allows you to run Java applications but not develop them.
**JDK (Java Development Kit)**: Full development environment. Includes JRE + Development Tools (javac, debugger, javadoc). Required for writing and compiling Java code.
3What is the significance of the "static" keyword?
Easy▼
What is the significance of the "static" keyword?
The `static` keyword means that a member belongs to the class itself rather than to any specific instance.
- **Static Variable**: Shared among all instances. Only one copy exists.
- **Static Method**: Can be called without creating an object. Cannot access instance variables directly.
- **Static Block**: Executed once when the class is loaded. Used for static initialization.
- **Static Class**: Only nested classes can be static.
4Why is String immutable in Java?
Medium▼
Why is String immutable in Java?
1. **Security**: Strings are widely used for sensitive info (passwords, connections). Immutability prevents modification after creation.
2. **Thread Safety**: Immutable objects are inherently thread-safe.
3. **String Constant Pool**: Saves memory by sharing identical string literals. This is only safe because strings cannot change.
4. **Caching HashCode**: The hash code is cached at creation, making it great for Map keys.
5Difference between equals() and == operator.
Easy▼
Difference between equals() and == operator.
- `==` operator checks for **reference equality**. It returns true if both references point to the exact same object in memory.
- `.equals()` method checks for **logical equality** (content comparison). By default in Object class, it behaves like `==`, but classes like String override it to compare values.
Practice these concepts
Test your knowledge with our online compiler and practice problems.