Java – Interview Questions
Explore a curated collection of Java interview questions covering a wide range of topics and difficulty levels—from beginner to advanced. Whether you’re just starting out or preparing for senior-level interviews, this page helps you practice effectively with clear questions, concise answers, and in-depth explanations.
Use the filter to quickly find questions by level and focus on the areas that matter most to you. Each question is designed to reinforce key concepts, improve your problem-solving skills, and prepare you for real-world technical interviews.
Start practicing, test your knowledge, and get interview-ready with structured, high-quality Java questions.
What is the difference between arrays and collections in Java?
Arrays have a fixed size and can store primitives directly. Collections are dynamic, provide richer APIs, and work with objects rather than primitives.
What is the difference between for loop and enhanced for loop?
A for loop gives full control over the index and iteration logic. An enhanced for loop is simpler and is used for straightforward traversal when you do not need the index.
What is the difference between Arrays.sort and Arrays.parallelSort?
Arrays.sort() performs sorting in a single thread, while Arrays.parallelSort() can split the work across multiple threads, which may improve performance for large arrays.
What is the purpose of the Arrays class in Java?
The Arrays class provides utility methods for working with arrays, including sorting, searching, comparing, filling, and converting arrays to strings or streams.
How are multidimensional arrays stored in memory in Java?
Multidimensional arrays in Java are stored as arrays of arrays. Each row is a separate array object, so rows can have different lengths.
What is a multidimensional array in Java?
A multidimensional array in Java is an array whose elements are themselves arrays, such as a two-dimensional array used for rows and columns.
What is short-circuit evaluation?
Short-circuit evaluation means Java stops evaluating a logical expression as soon as the result is already known, such as with && and ||.
What is the difference between && and & operators?
&& is the logical AND operator with short-circuit evaluation. & can act as a bitwise AND for integers or a non-short-circuit logical AND for booleans.
What is the difference between ++i and i++?
++i increments the value before it is used, while i++ uses the current value first and increments it afterward.
What is the difference between >> and >>> operators?
>> is the signed right shift operator and preserves the sign bit. >>> is the unsigned right shift operator and fills the leftmost bits with zeros.
What are bitwise operators in Java?
Bitwise operators operate on the individual bits of integer values. They include &, |, ^, ~, <<, >>, and >>>.
What is OffsetDateTime in Java?
OffsetDateTime represents a date and time with a specific UTC offset, such as +02:00, but without a full time-zone rule set.
Why should BigDecimal be used for financial calculations?
BigDecimal should be used for financial calculations because it provides precise decimal arithmetic and avoids the rounding errors common with floating-point types.
What is autoboxing and unboxing?
Autoboxing is the automatic conversion of a primitive value to its wrapper class, such as int to Integer. Unboxing is the reverse process.
Why is BigInteger slower than primitive types?
BigInteger is slower because it works with variable-size data structures and performs arithmetic in software rather than using fixed-size CPU primitives.
What is BigInteger used for?
BigInteger is used for integer values that are too large for primitive types like int or long. It supports arbitrary-precision arithmetic.
How does AtomicInteger achieve thread safety?
AtomicInteger achieves thread safety using low-level atomic CPU instructions and compare-and-set operations, which avoid race conditions without traditional locks.
What is AtomicInteger and when should you use it?
AtomicInteger is a thread-safe class for integer values that supports atomic operations like incrementing and updating. Use it when multiple threads need to update a counter without full synchronization.
What is the role of Locale in number formatting?
Locale determines how numbers are formatted, including decimal separators, grouping separators, currency symbols, and percentage formats.
How can you format numbers in Java?
You can format numbers in Java using classes such as NumberFormat, DecimalFormat, and String.format(), depending on the formatting needs.