Skip to main content

1. Java Fundamentals

Java is an object-oriented, platform-independent programming language that runs on the JVM. It follows WORA — Write Once, Run Anywhere — principle.
  • JVM: Executes Java bytecode.
  • JRE: Contains JVM + core libraries to run Java apps.
  • JDK: Includes JRE + development tools (compiler, debugger).
public, protected, default, and private — control visibility of classes, methods, and variables across packages.
Stack: Stores local variables and method calls.
Heap: Stores objects created using new. Managed by garbage collector.
Wrapper classes convert primitive types into objects (e.g., intInteger). Used in collections and generics.

2. Object-Oriented Programming

  • Encapsulation: Hiding internal details via getters/setters.
  • Inheritance: Reusing code by extending classes.
  • Polymorphism: Method overriding and overloading.
  • Abstraction: Hiding implementation using abstract classes/interfaces.
Abstraction hides implementation complexity.
Encapsulation hides internal state and controls access.
  • Overloading: Same method name, different parameters (compile-time).
  • Overriding: Subclass redefines parent method (runtime).
  • this refers to current class instance.
  • super refers to parent class members or constructor.
Special methods invoked when objects are created. They initialize object state. Default, parameterized, and copy constructors are common types.

3. Java Basics & Control Flow

== compares references (memory address).
.equals() compares object content if overridden.
Used for class-level variables, methods, and blocks. Shared among all instances of a class.
break exits a loop; continue skips the current iteration and continues to the next one.
final makes variables constants, prevents method overriding, and stops class inheritance.
Allows passing variable number of arguments to a method using .... Example: void add(int... nums).

4. Collections Framework

A set of classes and interfaces (List, Set, Map, Queue) that store and manipulate groups of data efficiently.
  • ArrayList: Fast random access, slow insertion/deletion.
  • LinkedList: Fast insertion/deletion, slow random access.
  • HashMap: Not synchronized, allows null keys/values.
  • Hashtable: Synchronized, legacy, doesn’t allow nulls.
  • Set: No duplicates.
  • List: Ordered, allows duplicates.
  • Map: Key-value pairs, no duplicate keys.
Thread-safe collections like ConcurrentHashMap, CopyOnWriteArrayList designed for multithreaded environments.

5. Exception Handling

Mechanism to handle runtime errors, maintaining normal application flow using try, catch, finally, and throw.
Checked: Compile-time (e.g., IOException).
Unchecked: Runtime (e.g., NullPointerException).
Executes regardless of exception. Commonly used to release resources like closing files or DB connections.
Create by extending Exception or RuntimeException for domain-specific error handling.
  • throw is used inside methods to explicitly throw an exception.
  • throws declares exceptions a method can throw.

6. Multithreading & Concurrency

A thread is a lightweight subprocess that executes tasks concurrently. Created using Thread class or Runnable interface.
New → Runnable → Running → Waiting/Sleeping → Terminated.
start() begins a new thread; run() executes in the same thread like a normal method call.
Ensures only one thread accesses a critical section at a time. Achieved using synchronized keyword or locks.
Ensures visibility of changes to variables across threads, preventing cached values from being used.

7. Java 8 & Functional Programming

Short syntax for anonymous functions: (x, y) -> x + y. Used with streams and functional interfaces.
Streams process collections functionally with map, filter, and reduce operations — enabling clean and parallelizable code.
A container object that may or may not contain a non-null value — avoids NullPointerException.
Shortcut for lambda expressions using ::. Example: System.out::println.
Interfaces with a single abstract method (e.g., Runnable, Supplier, Consumer). Annotated with @FunctionalInterface.

8. Memory Management & Garbage Collection

JVM automatically reclaims memory of unused objects. You can suggest GC with System.gc(), but it’s not guaranteed.
  • Strong: Prevent GC.
  • Weak: Collected when weakly reachable.
  • Soft: Collected only when memory is low.
When unused objects remain referenced, preventing GC. Common in static collections or unclosed resources.
Optimize object creation, use streams carefully, close resources, and monitor heap usage.
Called before object is garbage-collected, but it’s deprecated — prefer try-with-resources for cleanup.

9. Spring & Framework Concepts

A Java framework providing dependency injection (IoC), AOP, and integration with databases and web apps.
DI is providing dependencies from outside instead of creating them inside. Spring handles it using annotations like @Autowired.
  • BeanFactory: Basic container.
  • ApplicationContext: Adds enterprise features like event handling and AOP.
Simplifies Spring setup with auto-configuration, embedded servers, and starter dependencies.
@Component, @Service, @Repository, @Controller, @RestController, @Autowired, @Configuration, @Bean.

10. Java Interview Best Practices

Use efficient collections, avoid unnecessary synchronization, cache results, and prefer streams only when needed.
Forgetting equals() and hashCode(), neglecting resource closure, and ignoring concurrency issues.
Practice DSA in Java, build small Spring Boot projects, and review core APIs like Collections, Streams, and Concurrency.
  • Difference between HashMap and Hashtable
  • Explain synchronized vs volatile
  • How does JVM memory work?
  • Explain OOP principles
  • What are lambda expressions and streams?
Understand thread pools, caching, connection pooling, microservices architecture, and Spring Boot patterns.

Conclusion & Interview Tips

Key Focus Areas

  • OOP concepts and Java 8+ features
  • Multithreading, collections, and memory management
  • Spring Boot fundamentals and dependency injection
  • Clean code and exception handling practices

During the Interview

  • Explain your logic clearly
  • Discuss time and space complexity
  • Mention trade-offs and alternatives
  • Demonstrate debugging and testing approaches
Java interviews emphasize understanding of OOP, JVM internals, concurrency, and frameworks like Spring. Focus on clarity, problem-solving, and practical application of concepts.
Good luck with your Java Developer interviews!