Q1. What is Java, and what are its key features? Java is a class-based, object-oriented, platform-independent programming language. Key features: platform independence (via bytecode + JVM), automatic memory management (garbage collection), strong static typing, multithreading support, robust standard library, security model (no direct pointer access), and "write once, run anywhere" (WORA).
Q2. What is the difference between JDK, JRE, and JVM?
- JVM (Java Virtual Machine): Runs bytecode; provides the runtime environment (class loading, execution, memory management).
- JRE (Java Runtime Environment): JVM + core libraries needed to run Java applications.
- JDK (Java Development Kit): JRE + development tools (compiler
javac, debugger,jar, etc.) needed to build Java applications.
Q3. Why is Java called "platform independent"?
Java source code is compiled to bytecode (.class files), not native machine code. Bytecode runs on any device with a compatible JVM, so the same compiled artifact runs on Windows, Linux, macOS, etc.
Q4. What is the difference between compile-time and runtime?
Compile-time errors are caught by the compiler (syntax, type mismatches) before execution. Runtime errors/exceptions occur while the program is executing (e.g., NullPointerException, ArrayIndexOutOfBoundsException).
Q5. What is the main method signature, and why is it structured that way?
public static void main(String[] args)public: JVM can call it from outside the class.static: called without instantiating the class.void: returns nothing to the JVM.String[] args: command-line arguments.
Q6. What is the difference between == and .equals()?
== compares references (memory addresses) for objects, or actual values for primitives. .equals() compares logical/content equality, and its behavior depends on whether the class overrides it (default Object.equals() is reference equality).
Q7. What is autoboxing and unboxing?
Autoboxing is the automatic conversion of a primitive to its wrapper class (e.g., int → Integer). Unboxing is the reverse. The compiler inserts these conversions automatically, e.g., Integer i = 5; (boxing) and int j = i; (unboxing).
Q8. What are wrapper classes?
Classes that wrap primitive types into objects: Integer, Long, Double, Float, Character, Boolean, Byte, Short. Needed for use in collections (which require objects), and provide utility methods (parsing, conversion).