๐Ÿ’ก Top 10 Core Java Interview Questions

Welcome back to The Code Hut! ๐Ÿš€ Whether you’re preparing for a Java interview or brushing up your knowledge, these are the most common core Java questions you should know. Each question includes a short explanation or code example.

1. What is the difference between JDK, JRE, and JVM? ๐Ÿ–ฅ️

JVM: Runs Java bytecode and provides platform independence.
JRE: JVM + libraries required to run Java programs.
JDK: JRE + development tools like compiler and debugger.

2. Explain Java memory model (Heap vs Stack) ๐Ÿง 

Heap: Stores objects and instance variables; garbage-collected.
Stack: Stores method calls, local variables; follows LIFO.

3. What are Java access modifiers? ๐Ÿ”’

Access levels: private, default, protected, public. They control visibility of classes, methods, and fields.

4. Difference between == and equals() ⚖️


String a = new String("Java");
String b = new String("Java");

System.out.println(a == b);      // false, compares references
System.out.println(a.equals(b)); // true, compares values

5. Difference between abstract class and interface ๐Ÿ—️

Abstract class can have fields and method implementations; interface defines a contract (Java 8+ allows default methods). Classes can implement multiple interfaces but extend only one abstract class.

6. What is a Java Stream? ๐ŸŒŠ

Streams allow functional-style operations on collections:


List nums = List.of(1, 2, 3, 4);
nums.stream()
    .filter(n -> n % 2 == 0)
    .forEach(System.out::println); // 2 4

7. Difference between checked and unchecked exceptions ⚠️

Checked: Must be handled or declared (e.g., IOException).
Unchecked: Runtime exceptions, not required to be handled (e.g., NullPointerException).

8. What are Java 8 functional interfaces? ๐Ÿงฉ

Interfaces with a single abstract method, used for lambdas: Runnable, Callable, Function, Predicate.

9. Explain final, finally, and finalize ๐Ÿ”„

final: Constants, methods that cannot be overridden, classes that cannot be extended.
finally: Block executed after try/catch.
finalize: Method called by GC before object destruction (deprecated).

10. Difference between String, StringBuilder, and StringBuffer ✏️

String: Immutable.
StringBuilder: Mutable, not thread-safe.
StringBuffer: Mutable, thread-safe.

✅ Conclusion

These are the most frequently asked core Java questions in interviews. Make sure you understand these concepts and practice coding examples to boost your confidence for any Java interview.

Labels for this post: Java, Interview Prep, Core Java

Comments

Popular posts from this blog

๐Ÿ› ️ The Code Hut - Index

๐Ÿ›ก️ Resilience Patterns in Distributed Systems

๐Ÿ›ก️ Thread-Safe Programming in Java: Locks, Atomic Variables & LongAdder