Master Java Interview Essentials: JVM, Collections, Concurrency, and System Fundamentals
This article provides concise explanations of core Java and system concepts—including JVM class loading, HashMap implementation, concurrency utilities, IPC mechanisms, garbage collection, sorting algorithms, networking protocols, Linux scheduling, deadlock conditions, hashing techniques, and database normalization—useful for technical interviews and foundational study.
(1) How does the JVM load a class? What methods are in the parent delegation model?
Class lifecycle includes loading, (verification, preparation, resolution) linking, initialization, usage, and unloading. Class loading consists of loading, verification, preparation, resolution, and initialization. Loading obtains the binary stream via the fully qualified name, creates a Class object in the heap. Verification checks magic number 0xCAFEBABE, version, metadata, and bytecode symbol references. Preparation assigns default values to static variables. Resolution replaces symbolic references with direct references for classes, fields, and methods. Initialization runs static initializers and <clinit> methods, ensuring the superclass <clinit> runs first.
The parent‑delegation model requires every class loader (except the bootstrap loader) to have a parent loader; delegation is performed by checking findLoadedClass(), then attempting to load with loadClass(), and custom loaders override findClass(). Classes loaded by different loaders are considered distinct, affecting Class.equals(), isAssignableFrom(), isInstance(), and instanceof results.
(2) How is HashMap implemented?
In JDK 1.7 and earlier, HashMap maintains an array of Entry objects, each holding a key, value, hash, and next pointer. put computes the key’s hashCode to locate an index. If the slot is empty, the entry is stored; otherwise the chain is traversed, using equals() to detect duplicates, and the new entry is appended. get locates the bucket by hash and traverses the chain until a matching key is found.
When collisions become severe, JDK 1.8 replaces long chains with red‑black trees once a threshold is reached, improving lookup from O(n) to O(log n).
(3) Differences between HashMap and ConcurrentHashMap; thread‑safety of ConcurrentHashMap
HashMap is not thread‑safe; ConcurrentHashMap is. ConcurrentHashMap divides the map into segments (small HashMaps). Each segment can be locked independently, allowing high concurrency. It also uses final and volatile fields to ensure visibility.
(4) Differences between HashMap and Hashtable; thread‑safety of Hashtable
HashMap permits null keys and values; Hashtable does not.
HashMap is non‑thread‑safe; Hashtable is thread‑safe.
HashMap’s iterator is fail‑fast and throws ConcurrentModificationException on structural changes; Hashtable provides both enumerator (non‑fail‑fast) and iterator.
Hash algorithms differ, giving HashMap better distribution.
Resize algorithm: Hashtable expands to 2 * old + 1; HashMap doubles the array size.
(5) Common inter‑process communication (IPC) mechanisms
Traditional IPC includes:
Pipe (half‑duplex, parent‑child only)
Named pipe (half‑duplex, unrelated processes)
Semaphore (counting lock for shared resources)
Message queue (kernel‑managed message list)
Signal (asynchronous notification)
Shared memory (fastest IPC, often combined with signals)
Socket (network‑level communication)
In Java, IPC can be achieved via sockets, RMI, CORBA, or memory‑mapped files using MappedByteBuffer.
(6) JVM memory areas
Program Counter (PC) register – points to the current bytecode.
Java stack – stores local variables, operand stack, dynamic linking, and return addresses.
Native method stack – supports native method execution.
Heap – holds object instances.
Method area – stores loaded class metadata, constants, static variables, and compiled code.
(7) JVM garbage collection, generations, and what they store
The GC identifies unreachable objects via reachability analysis. Young generation uses a copying algorithm; old generation uses mark‑sweep or mark‑compact. Young generation holds newly created objects; old generation holds long‑lived objects; the permanent generation (or metaspace) stores class metadata, constants, static variables, and class methods.
(8) GC roots in reachability analysis
Objects referenced from stack frames.
Static fields and constants in the method area.
Objects referenced from JNI native stacks.
(9) Quick sort algorithm and complexity
Quick sort selects a pivot, partitions the array into elements less than or equal to the pivot and greater than the pivot, then recursively sorts the partitions. Average time complexity O(N log N), worst‑case O(N²), best‑case O(N log N).
(10) Balanced binary trees, insertion and deletion
A balanced binary tree has left and right subtrees whose height difference does not exceed 1. AVL trees rebalance via left/right rotations after insert/delete. Red‑black trees insert a red node and recolor/rotate to maintain properties; insertion may require up to two rotations, deletion up to three.
(11) How TCP ensures reliable transmission; three‑way handshake
TCP uses a three‑way handshake and sliding window for reliability and flow control.
1️⃣ Client sends SYN with initial sequence number X.
2️⃣ Server replies with SYN‑ACK, acknowledging X + 1.
3️⃣ Client sends ACK, acknowledging the server’s sequence number.
(12) Differences between TCP and UDP
TCP provides connection‑oriented, reliable byte‑stream service with retransmission, ordering, flow control, and congestion control. UDP is connection‑less, unreliable, and faster because it lacks these mechanisms.
(13) Sliding window algorithm
During a TCP session, each side advertises its receive window size. The sender transmits up to that many bytes, then waits for ACKs that may adjust the window, allowing continuous flow control.
(14) Linux process scheduling
Linux uses preemptive multitasking with time‑slicing; each process receives a quantum of CPU time, and the scheduler may preempt a running process to give another process its slice.
(15) Conditions for deadlock
Deadlock arises when resources are limited and process execution order is unfavorable. The four necessary conditions are mutual exclusion, hold‑and‑wait, no preemption, and circular wait. The Banker’s algorithm can guarantee a safe state without deadlock.
(16) Common hash algorithms
Direct addressing
Digit analysis
Mid‑square method
Folding method
Division‑remainder method (using a prime divisor)
Random number method
Collision resolution techniques include open addressing, double hashing, and chaining (including consistent hashing).
(17) Consistent hashing
Consistent hashing maps both servers and keys onto a ring; a key is stored on the next clockwise server. Adding or removing a server only remaps a small fraction of keys. Virtual nodes improve load balance.
(18) Distributed locks
Distributed locks coordinate access to shared resources across multiple nodes. Implementations include database row locks, Redis set‑nx (with expiration) or Redlock algorithm, and Zookeeper’s write‑to‑a‑path with watches and temporary nodes.
(19) Database normalization forms
1NF ensures atomic columns. 2NF requires non‑key columns to depend on the whole primary key. 3NF eliminates transitive dependencies.
(20) MySQL index structures and when to use them
MySQL supports B+‑tree and hash indexes. Hash indexes are efficient for equality queries with low duplicate values. Indexes are unnecessary for very small tables (< 2 000 rows) or when selectivity is low (cardinality / row count close to 0).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
