Java Programming Interview Questions and Answers – Test Your Skill Sets

Free Java courses with 37 real-time projects - Learn Java

In our last Java interview questions series we discussed part 6. Today, we will see 7th part of Java programming interview questions. These tricky interview questions for Java will help both freshers as well as experienced to crack Java interview.

So, let’s start Java Programming Interview Questions.

Mostly Asked Java Programming Interview Questions

Below, we are discussing some frequently asked Java Programming Interview Questions:

Q.1 How would you implement a Thread pool?

It is a generic implementation of a thread pool that takes the following input size of the pool to be constructed and the name of the class that implements runnable and constructs a thread pool with active threads that are waiting for activation.

Q.2 What are the benefits and drawbacks of reference counting In Garbage Collection?

An advantage of this scheme is that it will run in little chunks of time closely linked with the execution of the program. It is suitable for real-time environments where the program can’t be interrupted for a very long time

Q.3 Why we say Java as Pass-by-value?

Because of the way it handles sending parameters to methods, Java is sometimes referred to as a “pass-by-value” language. When you give a parameter to a method in Java, the parameter’s value is copied and sent to the method. This indicates that a copy of the original value serves as the basis for the method’s operations, and any modifications performed to the parameter inside the method have no impact on the original value outside of it.

When working with objects, this behaviour can occasionally be perplexing since it may appear as though Java is passing objects by reference. But it’s important to keep in mind that Java transmits references by value, which is why it’s known as “pass-by-value.” Understanding how Java handles method arguments and how changes to parameters inside of methods impact the original data outside of those methods depends on knowing the difference between “pass-by-value” and “pass-by-reference”.

Q.4 What are the access modifiers available In Java?

Access modifier specifies where a method or attribute often use.

The public is accessible from anyplace.

Protected is accessible from the same class and its subclasses.

Package/Default are accessible from the same package.

Private is only accessible from within the class.

Q.5 What’s the difference between a Switch Statement and an If Statement?

The switch statement is used to pick from multiple alternatives. The case values should be promoted to a to int value whereas If the statement is used to select from 2 alternatives. It uses a Boolean expression to decide that an alternative should be executed.

Java Programming Interview Questions for freshers

These are the some Java Programming Interview Questions for beginners:

Q.6 Explain synchronized methods and synchronized Statements?

Synchronized methods are methods that are declared with the keyword synchronized and in this, the thread executes a synchronized method only once it’s acquired the lock for the method’s object or class. Synchronized statements are similar to synchronized methods. It’s a block of code declared with synchronized keyword whereas a synchronized statement is often executed solely once a thread has acquired the lock for the object or class documented within the synchronized statement.

Q.7 What are the different ways that in which a thread will enter into waiting for the state?

There are 3 ways for a thread to enter into a waiting state. Also when you invoke its sleep() method, by interference on I/O, by unsuccessfully an attempt to acquire an object’s lock, or by invoking an object’s wait() method.

Q.8 What’s the difference between Static and Non Static variables?

A static variable associates with the class as a whole rather than with specific instances of a class. There’ll be only one value for the static variable for all instances of that category. Non-static variables take on unique values with each object instance.

Q.9 What’s the difference between notify and notifyall method?

Notify wakes up one thread that’s waiting for object’s monitor. In the case, if any threads are waiting on this object, one in every one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. notifyAll Wakes up all threads that are waiting on this object’s monitor. A thread waits on an object’s monitor by calling one of the wait ways.

Q.10 What are the different type of exceptions in Java?

During the execution of a programme, unexpected circumstances or mistakes are dealt with using exceptions in Java. There are 2 varieties of exceptions in java – Checked exceptions and unchecked exceptions. Checked exceptions are those that the compiler needs you to specify in the method signature using the “throws” keyword or explicitly manage using try-catch blocks. IOException, SQLException, and ClassNotFoundException are a few examples of checked exceptions.

On the other hand, unchecked exceptions, usually referred to as runtime exceptions, do not need the programmer to explicitly handle them. The compiler does not need managing them because they are often the result of programming mistakes. NullPointerException, ArrayIndexOutOfBoundsException, and IllegalArgumentException are examples of frequently occurring unchecked exceptions.

Java also contains the Error class, which represents grave problems like StackOverflowError and OutOfMemoryError that are often out of the application’s control and shouldn’t be caught or addressed. When creating strong and dependable Java programmes, handling exceptions correctly is crucial because it enables graceful error recovery or appropriate application closure when extraordinary circumstances occur.

Java Programming Interview Questions for Experienced

These are the some Java Programming Interview Questions for professionals:

Q.11 Explain about the select method with an example?

Select part is useful in selecting text or part of the text.

Q.12 Will there be an abstract class with no abstract methods in it?


Q.13 Can we outline private and protected modifiers for variables in interfaces?


Q.14 What’s Garbage Collection? What’s the method that’s responsible for doing that in Java?

Reclaiming the unused memory by the invalid objects. The garbage collector is liable for this method.

Q.15 Will there be an abstract class with no abstract methods In It?


Q.16 Will an interface has an Inner class?


public interface abc
static int i=0;
void dd();
class a1 {
a1() {
int j;
public static void main(String a1[]) } }

Q.17 Explain user defined exception?

Other than the packages Java package libraries have already defined, the user will define his own exception classes by extending Exception class.

Q.18 What’s the difference between logical data independence and physical data independence?

Logical information Independence – Meaning immunity of external schemas to change in conceptual schema.

Physical information Independence – Meaning immunity of conceptual schema to changes within the internal schema.

Advanced Java Programming Interview Questions

Q.19 What are the practical benefits of importing a specific class instead of an entire Package?

It makes no difference in the generated class files since only the classes that literally use, reference by the generated class file. There’s another practical benefit to importing single classes, and this arises once 2 (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and so try to use “Timer”, I get an error while compiling (the class name is ambiguous between each packages).

Let’s say what you really wished was the javax.swing.Timer class and the solely classes you plan on using in java.util are collection and HashMap. in this case, some people can prefer to import java.util.Collection and import java.util.HashMap rather than importing java.util.*. this can currently enable them to use Timer, Collection, HashMap, and different javax.swing classes while not using totally qualified class names in.

Q.20 State the number of methods that you implement if implement the Serializable Interface?

The Serializable interface is simply a “marker” interface, with no methods of its own to implement. different ’marker’ interfaces are



Q.21 What does the “abstract” keyword mean in front of a method? A Class?

Abstract keyword declares either a way or a class. If a method has an abstract keyword before it, we call it an abstract method. An abstract method has nobody. It has only arguments and returns type. Abstract methods act as placeholder methods that implement within the subclasses.

Abstract classes can’t instantiate. If a class is said as abstract, no objects of that class creates. If a class contains any abstract method it should declare as abstract.

Q.22 When you’ll create A String Object As String Str = “abc”; Why can’t A Button Object Be Created As Button Bt = “abc”;? Justify.

You can’t create a button by Button bt= “abc”; is because “abc” is a literal string (something slightly different than a String object, by-the-way) and but may be a Button object. The only object in Java that may assign a literal String is java.lang.String. Important to note that you aren’t calling a java.lang.String constructor once you type String s = “abc”;

Q.23 Will Rmi and Corba based applications interact?

Yes, they’ll. RMI is available with IIOP as the transport protocol instead of JRMP.

Q.24 Describe Pass by reference and pass value?

Pass by value means all Java method arguments. However, Java will manipulate objects by reference, and all object variables themselves ar references.

Q.25 What’s a “stateless” Protocol?

Without getting into lengthy debates, it generally accepted that protocols like HTTP are stateless i.e. no retention of state between a transaction. That is a single request-response combination.

So, this was all in best Java Programming Interview Questions. Hope you like it.


Hence, you have completed the 7th part of Java Programming Interview Questions Series. Hope these Interview Questions for Java helped you. Still, if any doubt regarding Java Programming Interview Questions, ask in the comment tab.

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

Leave a Reply

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