What are the most asked Java interview questions for freshers?

Core Java fresher rounds focus on the JVM, == versus equals, immutable strings, ArrayList, HashMap, checked exceptions, overriding, and a small thread story.

Priyanka 4 November 2026 Java
Java interview questions for freshers
Summarize this article in
Quick Answer

Prepare JDK versus JVM, == versus equals and hashCode, why String is immutable, ArrayList versus LinkedList, HashMap buckets, checked versus runtime exceptions, overriding versus overloading, and one project bug.

Key takeaways

  • == compares references. equals compares values. Override hashCode when you override equals.
  • String is immutable. Do not use == to compare string values.
  • ArrayList is the default list. HashMap keys must not change after insertion.
  • Checked exceptions must be handled or declared. Do not catch Exception everywhere.
  • Java passes the reference by value. Reassigning the parameter does not change the caller’s variable.

What are the most asked Java interview questions for freshers?

Java fresher rounds in India usually test whether you can explain objects, the difference between identity and equality, why String is immutable, how ArrayList and HashMap behave, and how checked exceptions differ from unchecked ones. A second wave of questions covers interfaces, overriding, and a very small concurrency story. Spring Boot is a separate conversation if the role is a web API. Use this page for the language. Use the Spring Boot interview questions page when the panel moves to controllers and dependency injection.

Answer with a definition, a tiny example, and the bug the concept prevents. If you cannot write the example, the definition will not survive the follow-up. The list below is a preparation guide for freshers, not a claim that every company prints the same paper.

What is the difference between JDK, JRE, and JVM?

The JVM is the virtual machine that runs bytecode. The JRE is the runtime: the JVM plus the libraries you need to run a program. The JDK is what you install to develop: the JRE plus the compiler and tools such as javac. A fresher machine needs the JDK. A server that only runs a built jar needs a runtime. You do not need a history of every vendor distribution. You do need to say that Java source is compiled to bytecode, and the JVM executes that bytecode, which is why the same class file can run on different operating systems that have a JVM.

The follow-up is often “is Java compiled or interpreted?” A fair fresher answer is: source is compiled to bytecode, and the JVM interprets or just-in-time compiles that bytecode to native code. You are not expected to tune the JIT. You are expected not to say “Java is only interpreted” or “Java is only a compiler like C.”

What is the difference between == and equals?

== on objects compares references, meaning whether both variables point at the same object. equals is a method that classes override to compare values. For String, equals compares the characters. Two strings built separately can be equal and still fail ==, except when the pool reuses a literal. Do not rely on == for string values. Use equals, and check for null before you call it, or use Objects.equals so a null does not throw.

If you override equals, you must override hashCode. Equal objects must have the same hash code, or HashMap and HashSet will lose them. Unequal objects may share a hash code. That collision is allowed. The interview bug is a class used as a map key whose equals was changed and whose hashCode was left as the identity hash. Describe the symptom: the key you just inserted cannot be found.

Why is String immutable, and what is the string pool?

A String cannot be changed after it is created. Methods that look like they edit a string return a new string. Immutability makes sharing safe, including sharing literals from the string pool, and it makes a string a calmer map key because its hash cannot change underneath the map. The pool reuses identical literals so "Hi" written twice can be the same object. new String("Hi") forces a separate object. That distinction is why == on strings is a trap question.

For many edits, use StringBuilder in a single thread. StringBuffer is the synchronised older cousin. A fresher who concatenates strings in a loop with + may create many temporary objects. Say you would use a builder when the loop is large, and you would not micro-optimise a single concatenation. The interviewer wants judgment, not a ban on the plus operator.

How do ArrayList and LinkedList differ?

ArrayList stores elements in a resizable array. Index access is fast. Inserting in the middle shifts elements. LinkedList stores nodes with links. Index access walks the list. Inserting in the middle is cheaper if you already hold the node, which a typical get-by-index loop does not. For almost every fresher project, ArrayList is the default. LinkedList is the answer when you truly add and remove at the ends and you do not jump by index. Saying “LinkedList is always faster to insert” without that condition is the mistake.

Know that both implement List, so your method can accept a List and not care. Also know that ArrayList is not synchronised. If multiple threads add to it, you need a safer structure or explicit locking. That sentence is the bridge to the concurrency question, and it is enough unless they ask you to write a lock.

How does HashMap work at fresher depth?

A HashMap stores key-value pairs. It uses the key’s hashCode to choose a bucket, then equals to find the right key inside that bucket. A get is usually fast and can degrade if many keys collide. Null is allowed for one key in HashMap. Hashtable is the older synchronised class and does not allow a null key. ConcurrentHashMap is the one to name when several threads share a map. You do not need to draw a red-black tree unless you are comfortable. Modern Java may store a dense bucket as a tree. Mentioning “collisions get expensive, and Java can tree-ify a bucket” is a strong fresher sentence. Inventing the threshold number is not required.

The practical bug is a mutable key. If you change a field that participates in hashCode after the put, the map looks in the new bucket and cannot find the entry. Use an immutable key, often a String or a record whose fields do not change. Say that out loud. It connects String immutability to the collection, which is what a good interview feels like.

What is a checked exception, and what is a runtime exception?

A checked exception must be caught or declared on the method. IOException is the example freshers meet when they read a file. A runtime exception, such as NullPointerException or IllegalArgumentException, does not force that declaration. It usually means a programming mistake or a bad argument. Errors, such as OutOfMemoryError, are a third branch you normally do not catch.

Do not catch Exception at the bottom of every method and print the stack as if that handled it. Catch what you can recover from. Let the rest travel to a boundary that logs a useful message. In a Spring API that boundary is often an exception handler, which is why this answer should point at the Spring page if the role is web. In core Java, the boundary might be main, where you log and exit with a non-zero status.

Throw IllegalArgumentException when a caller passed a negative age. Do not throw a checked exception for that. Checked exceptions are for conditions the caller might reasonably handle, such as a missing file. Overusing checked exceptions makes every method signature noisy. Say that trade-off if they ask which you prefer. Many codebases prefer unchecked exceptions for application errors and keep checked exceptions at the edges.

How do you explain inheritance, overriding, and overloading?

Inheritance lets a class reuse a parent. Overriding replaces a parent method with a child method that has the same signature. The call uses the object’s real type, which is polymorphism. Overloading is several methods in the same class with the same name and different parameters. The compiler picks the overload from the arguments. Overriding is decided at runtime. That one contrast answers a question people otherwise mix into a single word, “polymorphism.”

Use an example you can write: a base class Payment with a method charge, and a child UpiPayment that overrides charge. A variable of type Payment that holds a UpiPayment still runs the child method. If you only overload charge with a different parameter list, you have not overridden anything. The annotation Override helps the compiler catch a signature that does not match. Mention it. It is a small habit that signals you have compiled real code.

When do you choose an interface instead of an abstract class?

An interface is a contract: a set of methods a class promises to offer. A class can implement several interfaces. An abstract class is a partial implementation: it can hold fields and method bodies, and a class can extend only one of them. Choose an interface when you are describing a role, such as Notifier. Choose an abstract class when several types share real code and a common state, and you want one place for that code. Freshers who make a deep abstract tree for a three-class project are designing for a company they do not have.

Java interfaces can have default methods. Mention them only if you have used one. A default method lets you add a behaviour without breaking old implementors. It is not a reason to stop using abstract classes. If you have never written a default method, say the interface is the contract and move to an example you did write.

What do final, finally, and finalize mean?

These three words are a classic trap because they look alike and mean unrelated things. final on a variable means you cannot reassign it. final on a method means a child cannot override it. final on a class means you cannot extend it. String is a final class. finally is a block that runs after try and catch, whether or not an exception fired. It is where you release a resource you did not open in a try-with-resources statement. finalize was an old hook the garbage collector might call. Do not use it. Do not build a design on it. If the interviewer smiles when you say you would not use finalize, you have answered the question they were actually asking.

Try-with-resources is the modern habit: declare a closeable resource in the try header and it closes for you. Files and JDBC connections belong there. A fresher who still only knows a manual close in finally is acceptable if the close is in finally and a null check exists. Prefer the newer form if you can write it.

What is a safe fresher answer about threads?

A thread is a path of execution. Two threads that update the same counter without coordination will lose updates. synchronized, or a higher-level tool such as a concurrent collection or an executor, is how you stop that. sleep pauses a thread. It does not release a lock by itself in the way wait does. wait, notify, and a raw synchronized block are worth recognising. They are a poor default for new code. An ExecutorService is the tool to name when you have several tasks and you do not want to start raw Thread objects by hand.

The fresher trap is to synchronise every method “for safety” and then be unable to explain the cost. Locking everything serialises the work and can deadlock if two methods take the same locks in opposite orders. Say you would protect the shared data, keep the locked section short, and take locks in a consistent order. A deadlock story in one sentence is enough: two threads each hold one lock and wait for the other.

How do you present a Java project?

Walk one path. A request arrives, a class validates it, a collection or a repository stores it, and a result returns. Name one bug: a NullPointerException on a missing field, an equals method that broke a HashMap, or a list that was shared and mutated by the caller. Say how you fixed it. Then say what you would add with another week, which might be tests or a real database. A project that is only a main method printing a menu can still pass if you explain the data and the bug. A project with ten frameworks you cannot open will not.

If the role mentions APIs, revise Spring next, not more collection trivia. If the role mentions problem solving, write arrays and hash maps in Java using the DSA interview questions guide. Language answers and problem-solving answers are different muscles. Panels often test both on the same day.

Students in Pondicherry can practise this on Java training and then rehearse the spoken version in placement preparation. The course does not sit the interview. The blank editor does. After an offer arrives, read the pay with the CTC worksheet so the package conversation stays as concrete as the HashMap answer.

What to practise in the week before the drive

Write equals and hashCode for a tiny class and put it in a HashMap. Break it on purpose by mutating the key, then fix the design. Read a file with try-with-resources. Throw IllegalArgumentException for a bad input and let a NullPointerException surprise you once so you can explain the stack. Implement one interface with two classes and show overriding. Start one ExecutorService, submit two tasks, and shut it down. That set is more persuasive than a notebook of highlighted slides.

On the day, listen to the question until the end. Many Java questions are two questions joined by “and.” Answer the first, then the second. If you do not know, say the part you know and the part you would check in the documentation. Guessing a method name and then failing to explain its parameters is a worse impression than a clean gap.

Does Java pass objects by reference?

Java passes arguments by value. The value of an object variable is a reference, so the method receives a copy of that reference and can change the object’s fields. It cannot make the caller’s variable point at a different object. If the method does argument = new Something(), the caller still holds the old object. If the method does argument.setName("Asha"), the caller sees the new name. This is the distinction freshers blur when they say “objects are pass by reference.” Say “the reference is passed by value.” Then give the two examples. The follow-up is a method that swaps two variables. The swap will not stick, because the method only swapped its copies of the references. That is a favourite whiteboard check.

Primitives are simpler. The method receives a copy of the number. Changing the parameter does not change the caller’s number. Wrapper objects such as Integer are objects, and they are immutable, so you cannot change the int inside. A method that looks like it increments an Integer is really rebinding a local variable. If you need a counter a method can update, use an int array of one slot or, better, return the new value. Returning the value is the design you should recommend.

What do public, private, and protected change?

private means only the class itself can use the member. public means any class can. protected means the class, its children, and other classes in the same package. Package-private, which is the default when you write no modifier, means other classes in the same package. Freshers who make every field public cannot explain encapsulation. Keep fields private and expose a method when a change must follow a rule, such as “balance cannot go negative.” A getter that returns a mutable list lets the caller change your internal list. Return an unmodifiable view or a copy when the caller should not edit your state.

Access rules are also how you talk about API design in a small project. The service can be public. The helper that parses one odd date format can stay package-private. You do not need a module-info speech. You need one field you hid and one method you allowed. If everything in your project is public, say you would hide the fields first. That is a credible improvement.

What should a fresher say about garbage collection?

You do not free objects with a manual delete. The garbage collector reclaims objects that are no longer reachable. You help by dropping references you no longer need, and by not storing every request in a static list “for later.” You do not call System.gc and expect a contract. It is a hint, and production code should not depend on it. Finalize is not your cleanup tool. Close files and connections with try-with-resources. If the interviewer asks about generations or collectors by name, say the idea is reachability, and name a collector only if you have actually read your runtime’s default. Inventing G1 settings you have never tuned is a quick way to be asked a follow-up you cannot answer.

A memory leak in Java is usually a reachable object you forgot about: a static map that grows with every user, or a listener you never removed. Describe that, not a cartoon of a collector failing. It connects to the Spring warning about storing request data on a singleton. The same mistake wears two outfits.

A short mock round you can rehearse

Ask a friend to pick three questions from this page and to demand an example after each definition. Time the answer at two minutes. If you hear yourself say “basically” three times without a class name, stop and write the class. Then code the smallest version: a private field, an equals method, and a HashMap put and get. The mock is finished only when the code runs. Reading the answer aloud from this page is not the mock. It is the rehearsal before the mock.

On the drive day, write the signature before the body. Many wrong Java answers fail because the method is void when it should return a value, or because a checked exception is ignored. Say the return type out loud. If you blank on a collection, choose ArrayList or HashMap and explain the choice. A simple structure you can finish beats a clever structure you abandon. When the panel asks a Spring question, answer the Java underneath first if the question is really about objects, then move to the annotation. The language is the floor. The framework is the next storey.

A short mock round you can rehearse

Ask a friend to pick three questions from this page and to demand an example after each definition. Time the answer at two minutes. If you hear yourself say “basically” three times without a class name, stop and write the class. Then code the smallest version: a private field, an equals method, and a HashMap put and get. The mock is finished only when the code runs. Reading the answer aloud from this page is not the mock. It is the rehearsal before the mock.

On the drive day, write the signature before the body. Many wrong Java answers fail because the method is void when it should return a value, or because a checked exception is ignored. Say the return type out loud. If you blank on a collection, choose ArrayList or HashMap and explain the choice. A simple structure you can finish beats a clever structure you abandon. When the panel asks a Spring question, answer the Java underneath first if the question is really about objects, then move to the annotation. The language is the floor. The framework is the next storey.

These answers are a preparation guide for students and freshers, including learners at Asmorix in Pondicherry. A company may ask a different follow-up. This page is not a leaked paper and it is not a promise of a result. Say the short answer, show one example, and revise the same day any question you could not code or click.

Frequently Asked Questions

What are the most asked Java interview questions for freshers?

JDK versus JRE versus JVM, == versus equals, String immutability, ArrayList versus LinkedList, HashMap, checked versus runtime exceptions, overriding versus overloading, interfaces, and a basic thread answer.

What is the difference between == and equals in Java?

== on objects compares references. equals compares values when the class overrides it. If you override equals, also override hashCode, or HashMap will lose the key.

Why is String immutable in Java?

A String cannot be changed after it is created. That makes sharing and the string pool safe, and it keeps a string’s hash stable when it is a map key.

What is the difference between ArrayList and LinkedList?

ArrayList is a resizable array with fast index access. LinkedList is a chain of nodes. For most fresher projects, ArrayList is the right default.

What is a checked exception?

A checked exception, such as IOException, must be caught or declared. A runtime exception, such as NullPointerException, does not. Catch what you can recover from.

Does Java pass objects by reference?

No. Java passes the reference by value. The method can change the object’s fields. It cannot swap the caller’s variable to a new object.

Have a question about batches or fees?

Talk to an Asmorix counsellor in Pondicherry. Compare syllabus, timings, and placement support before you enroll.

Editorial note: Salary figures and hiring trends in this guide are planning ranges drawn from public salary samples and Asmorix counselling in Pondicherry. They are not an offer. City, company, and the skills you can demo all move the number.

Written by

Priyanka

Priyanka writes career and training guides for Asmorix Technologies, covering IT courses, fresher salaries, interview prep, and job-ready skill paths for students in Pondicherry and across India.

Leave a Reply

Your email address will not be published. Required fields are marked