Every fresher-level Core Java question — JVM, OOP, strings, keywords, exceptions, serialization — as a one-line answer with a link to the full answer.
Published September 25, 2026
This page condenses every question from the Fresher to 2 Years course in these areas into a single line: the question, linked to its full answer, and the one-sentence answer you should be able to give instantly. Read down the list and answer each question aloud before reading the line. Wherever you hesitate, follow the link and revise the full answer — interviewers at your level expect these basics to be fluent, and they often open with them before going deeper.
JDK, JRE, JVM & the main Method — Interview Questions — open the lesson
javac, for example) are Java programs that need it.public static void main(String[] args). — It's the entry point the JVM looks for when you launch a class. Each keyword has a reason — public class Greeter { public static void main(String[] args) {main is not declared static? — Up to Java 20, the class compiles, but launching it fails with the error "Main method is not static in class X, please define the main method as: public static void main(String[] args)".main method? — Not in the true sense, because static methods aren't overridden. A subclass can declare its own static main, but that hides the parent's method; it doesn't override it.main method? — Yes. main is an ordinary static method, so you can declare other main methods with different parameter lists.main method? — No. The launcher calls only the entry-point signature, main(String[] args). The overloads run only if your code calls them.main method? — Not in modern Java. Up to Java 6, you could print from a static initialiser block, which ran when the class loaded, before the launcher complained about the missing main.JVM Memory & Garbage Collection — Interview Questions — open the lesson
finalize() in garbage collection? — finalize() was a hook the GC could call before reclaiming an object, meant for releasing resources. It is deprecated (since Java 9, and marked for removal in Java 18), and you should never rely on it.Data Types, Wrapper Classes & Equality — Interview Questions — open the lesson
byte, short, int, long, float, double, char, boolean) that are not objects.null, and have no methods. Non-primitive (reference) types hold a reference to an object on the heap.null? — No. A primitive always holds a value. Fields get a default (0, false, …), and local variables must be assigned before use, or the code won't compile.== and .equals()? — - For primitives, == compares values. - For objects, == compares references (is it the same object?), while .equals() compares logical content, as defined by the class.Byte, Short, Integer, Long, Float, Double, Character and Boolean in java.lang.List<Integer>, Map<String, Long>) can't hold primitives, because type parameters must be reference types.int → Integer). Unboxing is the reverse.==. Integer.valueOf caches the values −128 to 127. Inside that range, equal values share one object, so == happens to return true.NullPointerException? — Whenever a null wrapper is unboxed, because the compiler calls .intValue() on null.Classes, Objects, Packages & Access Modifiers — Interview Questions — open the lesson
new keyword. 2. Reflection, with Constructor.newInstance(). 3. clone(). 4. Deserialization. 5. Factory or builder methods, which use one of the above internally.class Marker {}. It still inherits everything from Object (toString, equals, hashCode, …), and you can create instances of it.Object class provide? — equals(), hashCode(), toString(), getClass(), clone(), wait(), notify(), notifyAll(), and the deprecated finalize().java.util or com.shop.orders.public, protected, default (package-private, meaning no keyword), and private.private for fields and internal helpers. - package-private for classes that only collaborate inside one module. - protected for extension points meant for subclasses. - public only for the API that other code is meant…private or protected? — No. A top-level class can only be public or package-private. private and protected only make sense relative to an enclosing class, so they're allowed on nested classes.Inheritance, Composition, this & super — Interview Questions — open the lesson
extends.Car can be used anywhere a Vehicle is expected. That's what makes polymorphism possible.class A extends A {} is a compile error ("cyclic inheritance involving A"). The same applies to longer cycles, such as A extends B with B extends A.C extended both A and B, and both defined greet(), it would be ambiguous which one C inherits.Car extends Vehicle, so a Car IS-A Vehicle. HAS-A is composition: Car has an Engine field, so a Car HAS-A Engine.this and super keywords? — this refers to the current object. super refers to the parent-class part of the current object. It's used to call the parent's constructor, or its version of an overridden method.this be reassigned? What happens if you use super in a class with no explicit parent? — this is effectively final. this = other; is a compile error. And every class except Object has a superclass (Object by default), so super.toString() or super() compiles fine in a class that doesn't write extends.this or super be used in a static method? — No. Static methods belong to the class, not to any object, so there's no current instance for this or super to refer to.super relate to polymorphism? — Polymorphism lets an overriding method replace the parent's behaviour. super.method() lets the override extend that behaviour instead of replacing it: run the parent logic, then add to it.Polymorphism, Overloading & Overriding — Interview Questions — open the lesson
int total() and long total() in the same class is a compile error. The compiler chooses an overload from the call's arguments, and a call like total(); gives it nothing to decide with.public can't become protected). - It can't throw new or broader checked exceptions. - static, final and private…@Override annotation do? — It tells the compiler that you intend to override a method. If no matching method exists in a supertype, for example because of a typo or a wrong parameter type, compilation fails instead of silently creating a new overload.Abstraction, Interfaces & Encapsulation — Interview Questions — open the lesson
List, Map and Set, and you can swap ArrayList for LinkedList without changing the calling code.abstract, or it won't compile. An abstract class can't be instantiated with new.Comparable, PaymentGateway, Runnable), and whenever you want multiple implementations or easy mocking.InterfaceName.method(), and it's not inherited by implementing classes, so it can't be overridden. - A default method is an instance method with a body.Comparable and Comparator? — Comparable defines a class's natural ordering. The class itself implements compareTo, and there's exactly one such ordering.Constructors, Singleton, Anonymous Classes & Immutability — Interview Questions — open the lesson
void), and runs automatically when you use new.this(...).new. The typical uses are: - Singletons. - Utility classes with only static methods (such as Collections and Math). - Static factory methods, which control how instances are created (List.of, Optional.of).…private. 2. Hold the single instance in a private static field. 3. Expose it through a public static accessor.null and each create an instance — public static Cache getInstance() { if (instance == null) instance = new Cache();String, Integer, LocalDate, BigDecimal, and records with immutable fields.final, so no subclass can add mutability. 2. Make all fields private final. 3. Don't provide setters. 4.Design Patterns & SOLID Basics — Interview Questions — open the lesson
interface ShippingStrategy { BigDecimal cost(Order o); } class StandardShipping implements…if/else over types, the need to add behaviour, a notification fan-out. 2.interface GpsDevice { Position currentPosition(); } class VehicleTracker {Strings, String Pool, StringBuilder & StringBuffer — Interview Questions — open the lesson
String instances. String literals, and strings you explicitly intern(), are stored there once and reused.String and StringBuffer? — String is immutable. Every "modification" creates a new object. StringBuffer is a mutable sequence of characters that you change in place.StringBuilder different from StringBuffer, and when should you use each? — They have the same API. StringBuilder (Java 5) is not synchronized, so it's faster, and it's the right choice almost always, because string building usually happens inside one method on one thread.StringBuffer is better than String. — When one character buffer must be modified by several threads. For example, several worker threads appending fragments to a shared diagnostic report, where each append must be atomic."java") is pooled: equal literals share one instance. new String("java") always creates a new, separate object, even though an equal string already exists in the pool.String immutable in Java? — For security, safe sharing (pooling), thread safety and hash caching.static & final Keywords — Interview Questions — open the lesson
static keyword mean? — static marks a member as belonging to the class rather than to any object. There's one copy, shared by all instances, and it's accessible without creating an object: Math.max(a, b), Integer.MAX_VALUE.static { … } block runs once, when the class is initialised (on first use), before any object is created or any static method runs.throws clause, so checked exceptions must be caught inside the block.this, because no particular object is involved, so it can't refer to instance fields or methods.final keyword do? — It means "can't be changed", in three places: - A final variable can be assigned only once. - A final method can't be overridden. - A final class can't be extended (String, Integer, LocalDate).final variables? — - Constants: static final int MAX_SIZE = 100;. - Immutable fields in value objects and injected dependencies. - Local variables captured by lambdas or anonymous classes, which must be final or effectively final. - Parameters, as documentation that they're never reassigned.final contribute to immutability and thread safety? — final fields can't be reassigned, and the Java Memory Model gives them a special guarantee. Once a constructor finishes, any thread that sees the object also sees the final fields' fully initialised values, without synchronisation (provided this didn't escape during…final? — Very few. The JIT compiler is already good at inlining non-final methods (it tracks which classes are actually loaded and deoptimises if that changes), so marking methods final rarely makes code faster.final improve performance by reducing method-call overhead? — In early JVMs, somewhat. On modern HotSpot, not meaningfully. The JIT uses class hierarchy analysis to inline methods that have only one loaded implementation, whether or not they're final, and it inlines polymorphic call sites that are hot.Exceptions, Generics, Enums & Reflection — Interview Questions — open the lesson
Exception, but not of RuntimeException) are verified at compile time. You must either catch them or declare them with throws.try, catch and finally? — - try wraps the code that might throw. - catch handles a specific exception type. - finally always runs afterwards, whether or not an exception occurred, and is used for cleanup.try or catch executes a return, does finally still run? — Yes. finally runs after the return value is computed but before control goes back to the caller.try without catch? — Yes. try–finally (no catch) runs cleanup while letting the exception propagate to the caller. try-with-resources can also stand alone, with no catch and no finally.try block itself costs essentially nothing. Throwing an exception is what's expensive, mainly because the stack trace is captured, and unwinding the stack takes time.finally block not execute? — - When the JVM stops before reaching it: System.exit() in try or catch, Runtime.halt(), a JVM crash, or the process being killed (kill -9, power loss). - When the try block never finishes, because of an infinite loop or a deadlock. - When the thread is a daemon…try have multiple finally blocks? How do you handle several exceptions in one catch? — No. Each try can have at most one finally (but many catch blocks). To handle several exception types the same way, use multi-catch (Java 7+) — try { importFile(path);Throwable, Exception and Error? — Throwable is the root of everything that can be thrown. Exception represents conditions an application might reasonably handle.finally and finalize()? — finally is a language block that runs deterministically after try/catch. finalize() was a method the garbage collector might call before reclaiming an object.List<String>, Map<K, V>, <T> T first(List<T>)).enum is a type with a fixed set of named constants, such as OrderStatus { PLACED, PAID, SHIPPED, DELIVERED }.java.lang.reflect) lets code inspect and use classes at runtime: list fields, methods, constructors and annotations, create instances, call methods, and read or write fields, even private ones, when access is allowed.Serialization & transient — Interview Questions — open the lesson
serialVersionUID? — It's a version number for a serializable class. During deserialization, the JVM compares the UID stored in the byte stream with the UID of the class currently loaded.serialVersionUID changes between serialization and deserialization? — Deserialization fails with a java.io.InvalidClassException ("local class incompatible: stream classdesc serialVersionUID = X, local class serialVersionUID = Y").transient mean? — Mark them transient. A transient field is skipped during serialization, and gets its default value (null, 0, false) after deserialization.transient (or null at the time), or if you handle it with custom serialization logic.writeObject() and readObject() used for? — They're private hook methods that a serializable class can declare to customise its own serialization. You call defaultWriteObject()/defaultReadObject() for the normal fields, then write or read extra data.ObjectOutputStream keeps a table of the objects already written in the stream. When it meets the same object again, it writes a back-reference (a handle) instead of serializing the object a second time.Q: How should I use this list in the last week before an interview? A: Do one pass per day. Cover the answer text, say your answer out loud, then check it. Mark every question you could not answer crisply, and spend your study time only on the marked ones by opening the linked full answer. By the third pass the marked list should be short.
Q: The interviewer asks one of these basics — should I give only the one-liner? A: Lead with the one-liner, then add one concrete detail or example from your own work. At this level the follow-up usually probes the mechanism behind the basic answer, so be ready to go one layer deeper using the key points in the full lesson.
Q: Some answers here were corrected compared with common prep sheets — why? A: Several widely shared answers are outdated or wrong (for example, Java version details, removed Spring APIs, or SQL queries that miss edge cases). The full lessons call these out under "Common trap" — reading those is the fastest way to stand out from candidates who memorised the same sheets.