Top 4 Java Interview Questions
Browse 4 real-world technical and behavioral interview questions about Java. Review scenarios, edge cases, and architectural best practices.
Skip the definitions. Show me encapsulation, abstraction, inheritance and polymorphism, each in about ten lines of code, and then tell me when inheritance is the wrong tool.
OOP examples beat definitions: a class refusing a bad withdrawal shows encapsulation, a caller depending on an interface shows abstraction, a subclass reusing a parent method shows inheritance, and one loop running different overrides shows polymorphism. Inheritance is wrong when the child breaks a parent promise.
Implement a thread-safe pool of N connections with acquire, release and a timeout.
A thread-safe connection pool pairs a Semaphore of N permits, which bounds how many connections exist and gives acquire its timeout, with a queue of idle connections. Acquire returns a lease that releases exactly once from a finally block, and a broken connection is discarded without losing its permit.
Given an access log, write a utility that reports request count, error rate and p95 latency per endpoint.
Group lines by a normalised path so that /orders/1 and /orders/2 collapse to one endpoint, compute the percentile by nearest rank on the sorted latencies, and count the lines you could not parse instead of silently dropping them.
How do you optimise Java Virtual Machine (JVM) garbage collection to eliminate tail latency spikes in a game server?
Analyse JVM tuning strategies to prevent Stop-The-World (STW) pauses and ensure predictable microsecond response times for game server logic. It also connects garbage collection to the point an interviewer is testing.