Java Software Engineer Interview Preparation Guide
Download PDF
Add New Question

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
Post Your Answer

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.
Post Your Answer

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

Test t = null;
t.someMethod();

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.
Post Your Answer

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.
Post Your Answer

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.
Post Your Answer

6 :: Tell me can an enum be extended?

No. Enum types are final by design.
Post Your Answer

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.
Post Your Answer

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).
Post Your Answer

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;
Post Your Answer

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
Post Your Answer
Add New Question