Engineering, Design, Marketing, and More

Java interview questions

The most popular questions

Use our complementary questions and answers to filter and hire the best. Questions crowdsourced by our clients, answers by Punch. We provide these complementary questions to help our clients more quickly create tests for potential hires at their organizations.

Get a question answered
Punch offers four divisions of services: design, engineering, staffing, and demand

Interview questions for your next interview

Question
What is an immutable object?
Answer
Immutable classes are Java classes whose objects can not be modified once created. Any modification in Immutable object results in new object. For example String is immutable in Java. Mostly Immutables are also final in Java, in order to prevent subclasses from overriding methods in Java which can compromise Immutability.
Question
What is the difference between StringBuffer and StringBuilder in Java?
Answer
Stringbuffer methods are synchronized while StringBuilder is Non Synchronized.

Find developers today

Hire a Punch engineer

Punch offers four divisions of services: design, engineering, staffing, and demand. Our four divisions form the core of our People Forward Approach.

Contact us
Find developers today
Question
What is classloader?
Answer
The classloader is a subsystem of JVM that is used to load classes and interfaces. There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc.
Question
Can you override private or static methods in Java?
Answer
You can not override private or static method in Java, if you create a similar method with same return type and same method arguments that's called method hiding.
Question
What is the ThreadLocal class? How and why would you use it?
Answer
The ThreadLocal class in Java enables you to create variables that can only be read and written by the same thread. Thus, even if two threads are executing the same code, and the code has a reference to a ThreadLocal variable, then the two threads cannot see each other's ThreadLocal variables.
Question
What is the difference between sleep() and wait()?
Answer
sleep() is a blocking operation that keeps a hold on the monitor / lock of the shared object for the specified number of milliseconds.

wait(), on the other hand, simply pauses the thread until either (a) the specified number of milliseconds have elapsed or (b) it receives a desired notification from another thread (whichever is first), without keeping a hold on the monitor/lock of the shared object.
Question
What is the difference between HashSet and TreeSet?
Answer
HashSet is superior in almost every way: O(1) add, remove and contains, vs. O(log(N)) for TreeSet. However, TreeSet is indispensable when you wish to maintain order over the inserted elements or query for a range of elements within the set.
Question
What are advantages of a lambda expression?
Answer
We can pass a lambda expression as an object to a method. This reduces the overhead involved in passing an anonymous class. We can also pass a method as a parameter to another method using lambda expressions.
Question
What is ThreadFactory?
Answer
ThreadFactory is an interface that is meant for creating threads instead of explicitly creating threads by calling new Thread(). Its an object that creates new threads on demand. Using thread factories removes hardwiring of calls to new Thread, enabling applications to use special thread subclasses, priorities, etc.
Question
What is Serialization and deserialization?
Answer
Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.

Find developers today

Hire a Punch engineer

Punch offers four divisions of services: design, engineering, staffing, and demand. Our four divisions form the core of our People Forward Approach.

Contact us
Find developers today
Question
Why are Generics used in Java?
Answer
Generics provide compile-time type safety that allows programmers to catch invalid types at compile time. Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods or, with a single class declaration, a set of related types.
Question
What is daemon thread?
Answer
Daemon thread is a low priority thread, which runs intermittently in the background doing the garbage collection operation for the java runtime system.
Question
Explain the architecture of a Servlet.
Answer
The core abstraction that must be implemented by all servlets is the javax.servlet.Servlet interface. Each servlet must implement it either directly or indirectly, either by extending javax.servlet.GenericServlet or javax.servlet.http.HTTPServlet. Finally, each servlet is able to serve multiple requests in parallel using multithreading.
Question
What is the difference between Exception and Error in Java?
Answer
‘Exception’ and ‘Error’ classes are both subclasses of the Throwable class. The Exception class is used for exceptional conditions that a user’s program should catch. The Error class defines exceptions that are not expected to be caught by the user program.
Question
What is connection Pooling and why do we need it?
Answer
Connection Pooling facilitates reuse of the same connection object to serve a number of client requests. Every time a client request is received, the pool is searched for an available connection object and it's highly likely that it gets a free connection object. Otherwise, either the incoming requests are queued or a new connection object is created and added to the pool (depending upon how many connections are already there in the pool and how many the particular implementation and configuration can support). As soon as a request finishes using a connection object, the object is given back to the pool from where it's assigned to one of the queued requests.

Ask a question

Ask a question, and one of our engineers will answer it.

We keep our questions nice and simple to be useful for everyone, and we may not answer or publish every question.

Your number is stored privately and never shared.
By submitting a question, you agree to our terms.
Request sent. Thank you!
Send another one