Java Software Engineer Interview Preparation Guide
Download PDF

Java Software Engineer based Frequently Asked Questions in various Java Software Engineer job interviews by interviewer. These professional questions are here to ensures that you offer a perfect answers posed to you. So get preparation for your new job hunting

45 Java Software Engineer Questions and Answers:

1 :: Do you know how threadsafe is enum in Java?

Creation of an enum is guaranteed to be threadsafe. However, the methods on an enum type are not necessarily threadsafe

2 :: Explain me what is a good usecase of calling System.gc()?

One may call System.gc() when profiling an application to search for possible memory leaks. All the profilers call this method just before taking a memory snapshot.

3 :: Explain me why doesn’t the following code generate a NullPointerException even when the instance is null?

Test t = null;

public static void someMethod() {

There is no need for an instance while invoking a static member or method, since static members belongs to a class rather than an instance.

A null reference may be used to access a class (static) variable without causing an exception.

4 :: Do you know what is the advantage of generic collection?

They enable stronger type checks at compile time.

A Java compiler applies strong type checking to generic code, and issues errors if the code violates type safety. Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find.

5 :: Tell us what do you mean by aggregation?

Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child object can not belongs to another parent object. Let’s take an example of Department and teacher. A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy.

6 :: Tell me can an enum be extended?

No. Enum types are final by design.

7 :: Explain me when do you need to override the equals and hashCode methods in Java?

By defining equals() and hashCode() consistently, the candidate can improve the usability of classes as keys in hash-based collections such as HashMap.

8 :: Tell us what are checked and unchecked exceptions? When do you use them?

A checked exception is an exception that must be catch, they are checked by the compiler. An unchecked exception is mostly runtime exception, and is not required to be catch. In general, use checked exception when the situation is recoverable (retry, display reasonable error message).

9 :: Tell us how can you swap the values of two numeric variables without using any other variables?

You can swap two values a and b without using any other variables as follows:

a = a + b;
b = a - b;
a = a - b;

10 :: Tell us what are constructors in Java?

In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.

There are two types of constructors:

☛ Default constructor
☛ Parameterized constructor