Tech

Java

Java is a mature, strongly-typed, object-oriented language that underpins enterprise software, Android development, and large-scale backend systems. Its "write once, run anywhere" philosophy via the JVM has made it a staple in financial institutions, healthcare, and Fortune 500 companies. Interviewers probe JVM internals, garbage collection, the Collections framework, concurrency, and object-oriented design principles.

What you get

Questions

20

Difficulty

3 levels

Answer Formats

2

Use the toggle on each card to move between an interview-ready answer and a simpler explanation. Questions are sorted from beginner to advanced, and the keywords are highlighted. You can also blur the answers to practice recalling them from memory.

Questions

Practice the answers out loud.

All topics

Question 1

What is Java and what are its key features?

Beginner

How to answer in an interview

Java is a class-based, object-oriented, platform-independent programming language that compiles to bytecode run by the Java Virtual Machine (JVM). Key features include automatic memory management via garbage collection, strong type checking, built-in multithreading support, and its 'write once, run anywhere' portability across operating systems.

Question 2

Explain the difference between JVM, JRE, and JDK.

Beginner

How to answer in an interview

The JVM (Java Virtual Machine) executes Java bytecode and provides platform independence. The JRE (Java Runtime Environment) includes the JVM plus libraries needed to run Java applications, but not development tools. The JDK (Java Development Kit) includes the JRE plus development tools like the compiler, needed to write and build Java programs.

Question 3

What does 'write once, run anywhere' mean in Java?

Beginner

How to answer in an interview

It refers to Java's platform independence: source code is compiled into bytecode, an intermediate representation that isn't tied to any specific operating system. Any machine with a compatible JVM installed can run that same bytecode, so developers don't need to rewrite code for each platform.

Question 4

What is the difference between == and .equals() in Java?

Beginner

How to answer in an interview

'==' compares object references, checking whether two variables point to the exact same object in memory, while .equals() compares the actual content or value of two objects, and its behavior can be overridden by classes like String to compare meaningful content instead of memory addresses.

Question 5

Explain the four core OOP principles as applied in Java.

Beginner

How to answer in an interview

Encapsulation bundles data and methods together while restricting direct access using access modifiers like private. Inheritance allows a class to acquire properties and behavior from a parent class using 'extends'. Polymorphism allows objects to take multiple forms, through method overriding and overloading. Abstraction hides implementation details, exposing only essential features through abstract classes or interfaces.

Question 6

What is the difference between method overloading and method overriding?

Beginner

How to answer in an interview

Method overloading occurs when multiple methods in the same class share a name but differ in parameter list, resolved at compile time. Method overriding occurs when a subclass provides its own implementation of a method already defined in its parent class, with the same signature, resolved at runtime based on the actual object type.

Question 7

Explain the 'final' keyword in Java.

Beginner

How to answer in an interview

The 'final' keyword restricts modification: a final variable's value cannot be reassigned once initialized, a final method cannot be overridden by subclasses, and a final class cannot be extended or subclassed at all.

Question 8

What is a constructor and what is constructor overloading?

Beginner

How to answer in an interview

A constructor is a special method invoked automatically when an object is created, used to initialize its state, and it shares the same name as its class with no return type. Constructor overloading means defining multiple constructors with different parameter lists in the same class, allowing objects to be created in different ways.

Question 9

Explain the 'static' keyword in Java.

Beginner

How to answer in an interview

The 'static' keyword indicates that a member belongs to the class itself rather than any specific instance, meaning it's shared across all objects of that class. Static variables hold a single shared value, and static methods can be called without creating an instance of the class.

Question 10

What is the difference between an abstract class and an interface?

Intermediate

How to answer in an interview

An abstract class can have both abstract and concrete methods, constructors, and instance variables, but a class can only extend one abstract class. An interface traditionally only declared abstract methods, though since Java 8 it can include default and static methods; a class can implement multiple interfaces, effectively enabling a form of multiple inheritance.

Question 11

Explain the difference between checked and unchecked exceptions.

Intermediate

How to answer in an interview

Checked exceptions are checked at compile time, requiring the method to either handle them with a try-catch or declare them with 'throws', such as IOException. Unchecked exceptions, which extend RuntimeException, are not checked at compile time and typically indicate programming errors, such as NullPointerException.

Question 12

What is garbage collection in Java?

Intermediate

How to answer in an interview

Garbage collection is Java's automatic memory management process that identifies and reclaims memory occupied by objects that are no longer reachable or referenced by the program, freeing developers from manual memory deallocation. The JVM uses algorithms like mark-and-sweep and generational collection to efficiently reclaim heap memory.

Question 13

What is the difference between String, StringBuilder, and StringBuffer?

Intermediate

How to answer in an interview

String is immutable, so any modification creates a new object, which can be inefficient for many concatenations. StringBuilder is mutable and not thread-safe, making it faster for single-threaded string manipulation. StringBuffer is also mutable but is synchronized and thread-safe, at a small performance cost compared to StringBuilder.

Question 14

Explain multithreading in Java.

Intermediate

How to answer in an interview

Multithreading allows a Java program to execute multiple threads concurrently, sharing the same process resources, implemented by extending the Thread class or implementing the Runnable interface. It's used to perform tasks in parallel, such as handling multiple client requests simultaneously, improving application responsiveness and resource utilization.

Question 15

What is synchronization in Java?

Intermediate

How to answer in an interview

Synchronization controls access to shared resources by multiple threads, using the 'synchronized' keyword on methods or blocks to ensure only one thread can execute that section at a time, preventing race conditions and data inconsistency in concurrent environments.

Question 16

What is the Java Collections Framework, and what are the main interfaces?

Intermediate

How to answer in an interview

The Java Collections Framework provides a unified architecture for storing and manipulating groups of objects, with core interfaces including List, an ordered collection allowing duplicates like ArrayList; Set, a collection disallowing duplicates like HashSet; and Map, which stores key-value pairs like HashMap. It provides standard implementations, algorithms, and iterators for working with these data structures.

Question 17

What is the difference between ArrayList and LinkedList?

Intermediate

How to answer in an interview

ArrayList is backed by a dynamic array, offering fast O(1) random access but slower insertions and deletions in the middle due to element shifting. LinkedList is backed by a doubly linked list, offering fast O(1) insertions and deletions once positioned, but slower O(n) random access since it must traverse nodes sequentially.

Question 18

What is the difference between HashMap and Hashtable?

Intermediate

How to answer in an interview

HashMap is not synchronized, allows one null key and multiple null values, and offers better performance in single-threaded contexts. Hashtable is synchronized, making it thread-safe but slower, and it doesn't allow null keys or values. In modern code, ConcurrentHashMap is generally preferred over Hashtable for thread-safe use cases.

Question 19

Explain the Java memory model: heap vs stack.

Advanced

How to answer in an interview

The stack stores method call frames, local variables, and references, following a last-in-first-out structure that's automatically cleaned up when a method returns. The heap stores all objects and is managed by the garbage collector, persisting until objects are no longer reachable, making the heap generally larger but slower to access than the stack.

Question 20

What are Java 8 streams and lambda expressions?

Advanced

How to answer in an interview

Lambda expressions introduced in Java 8 provide a concise way to represent anonymous functions, enabling functional-style programming. Streams provide a declarative API for processing sequences of elements, supporting operations like map, filter, and reduce, often used with lambdas to write concise, readable data transformation pipelines without explicit loops.

More in Tech

Keep browsing related topics.

Browse all