Fundamentals 47 min read

Comprehensive Java Interview Guide: OOP, Concurrency, Collections, JVM, and More

This article provides a thorough overview of core Java concepts frequently asked in interviews, covering object‑oriented fundamentals, polymorphism, interfaces vs abstract classes, data types, memory management, concurrency mechanisms, collections, JVM internals, and best‑practice coding examples.

Java Captain
Java Captain
Java Captain
Comprehensive Java Interview Guide: OOP, Concurrency, Collections, JVM, and More

Object‑Oriented Programming Basics

Encapsulation, inheritance, and polymorphism are the three core features of OOP; abstraction is often added as a fourth.

Benefits of Polymorphism

Replaceability – existing code can be swapped with new implementations.

Extensibility – new subclasses can be added without altering existing structures.

Interface provision – superclasses define a common method signature that subclasses implement or override.

Flexibility.

Simplification.

Implementing Polymorphism in Code

Three main approaches: (1) interface implementation, (2) subclass overriding, (3) method overloading within the same class.

How the JVM Implements Polymorphism

Through dynamic binding, the actual object type is determined at runtime and the appropriate method is invoked.

Interfaces and Abstract Classes

Interfaces emphasize specification, extensibility, and callbacks; abstract classes provide a common type, encapsulate repeated code, and define abstract methods with consistent signatures.

Interface vs. Abstract Class Comparison

Aspect

Abstract Class

Interface

Default methods

Can have concrete implementations

Prior to Java 8, no implementations

Implementation

Subclass uses extends and must implement abstract methods unless itself abstract

Class uses implements and must implement all declared methods

Constructors

Can define constructors

Cannot define constructors

Instantiability

Cannot be instantiated directly

Represents a completely separate type

Access modifiers

Methods can be public, protected, or package‑private

Methods are implicitly public; other modifiers are not allowed

Multiple inheritance

Only one superclass allowed

A class can implement multiple interfaces

Adding new methods

Can provide default implementations without breaking subclasses

Adding a method forces all implementing classes to provide an implementation

Static vs. Instance Members

Static variables belong to the class and reside in the method area; instance variables reside on the heap and are referenced from the thread stack.

Immutable Objects

Immutable objects cannot change state after creation; any modification results in a new object (e.g., String, Integer).

Java Object Creation Methods

Using new Reflection

Cloning

Serialization

Frameworks often discourage direct new to reduce coupling.

String Handling

String literals are interned; intern() checks the constant pool and adds the string if absent. Equality checks with == compare references, while equals() compares content.

Common Object Methods

equals()
clone()
getClass()
notify()

, notifyAll(),

wait()
toString()

Reference Types

Strong, soft, weak, and phantom references affect garbage‑collection eligibility.

Equality and Hashing

==

compares references for objects; equals() can be overridden for logical equality. Equal objects must have identical hashCode() values.

Numeric Operations

Floating‑point comparisons may yield unexpected results (e.g., 3*0.1==0.3 is false). Compound assignment operators perform implicit casting.

Concurrency Basics

Threads are the basic execution unit; processes provide isolation. Daemon threads do not prevent JVM shutdown. Context switching occurs when the CPU switches between runnable threads.

Thread Creation

Implement Runnable or extend Thread; the former is preferred due to Java’s single‑inheritance limitation.

Thread Control Methods

start()

creates a new thread and invokes run(); calling run() directly executes in the current thread. sleep() pauses without releasing locks; wait() / notify() must be used within synchronized blocks and release/reacquire monitors.

Locks and Synchronization

Java provides intrinsic locks via synchronized and explicit locks via ReentrantLock, which offer features like timed try‑lock and interruptible lock acquisition.

Thread Pools

Thread pools reuse threads, limit concurrency, and handle task rejection policies when queues are full.

Atomicity and Visibility

Operations like ++ are not atomic. volatile guarantees visibility and prevents reordering; reads/writes of long and double become atomic when declared volatile.

Concurrent Collections

ConcurrentHashMap

uses segment locks (pre‑Java 8) or CAS‑based algorithms (Java 8) to allow high concurrency. CopyOnWriteArrayList and other concurrent utilities provide fail‑safe iteration.

Garbage Collection

Algorithms include mark‑sweep, mark‑compact, copying, and generational collection. Objects are reclaimed based on reachability analysis.

JVM Fundamentals

The JVM provides platform independence, loads classes via a hierarchical class‑loader model, and separates memory into heap (objects) and stack (frames, primitives).

Additional Topics

Differences between ArrayList and LinkedList, HashMap vs. WeakHashMap, and best practices for serialization, date handling, and I/O are also discussed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMinterviewCollectionsOOPfundamentals
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.