“Exploring Essential Interview Questions for Core Java Developers: Series-3”

Here, I’m providing actual technical interview questions. These questions mainly focus on subjects such as Core Java, Coding, Spring, and Design Patterns.

Ajay Rathod
5 min readApr 5, 2022

(A bit of context: I’ve conducted numerous interviews for software engineering positions in most of the MNCs. )

Are you preparing for a job interview as a Java developer?

Find my book Guide To Clear Java Developer Interview here Gumroad (PDF Format) and Amazon (Kindle eBook).

Guide To Clear Spring-Boot Microservice Interview here Gumroad (PDF Format) and Amazon (Kindle eBook).

Download the sample copy here: Guide To Clear Java Developer Interview[Free Sample Copy]

Guide To Clear Spring-Boot Microservice Interview[Free Sample Copy]

Core Java

How to create a custom hashmap of size 2GB?

It's a bad design. Having 1.7GB of data in memory on a HashMap, I would have done any of the two:

  1. Persist all the data (file/database) and have the top 1% or something in memory. Use some algorithm for deciding which IDs will be in memory and when.
  2. Use Memcached. The easiest way out. An in-memory distributed hashable. This is exactly what DHTs are used for.

Can we insert Null in Concurrent Hashmap?

Inserting null objects is not possible in ConcurrentHashMap as a key or value.

Can we insert the null key in the hashmap and hashtable?

Hashtable does not allow null keys but HashMap allows one null key and any number of null values

How to parse JSON to hashmap?

In order to convert JSON data into Java Map, we take the help of the JACKSON library. We add the following dependency in the POM.xml file to work with the JACKSON library. Use JSON library and use object mappers read values method to do that.

How to parse an XML file with JSON in Java?

Design Pattern & System Design

What is a singleton design pattern?

Singleton Pattern

  • Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the java virtual machine.
  • The singleton class must provide a global access point to get the instance of the class.
  • Singleton pattern is used for logging, driver objects, caching, and thread pool.
  • Singleton design pattern is also used in other design patterns like Abstract Factory, Builder, Prototype, Facade, etc.
  • Singleton design pattern is used in core java classes also, for example java.lang.Runtime, java.awt.Desktop.

Coding

Write a program to find duplicates in an array list.

class Solution {
public int findDuplicate(int[] nums) {
Set<Integer> seen = new HashSet<Integer>();
for (int num : nums) {
if (seen.contains(num))
return num;
seen.add(num);
}
return -1;
}
}

Print the Array list in descending order.

Collections.sort(arraylist, Collections.reverseOrder());

Database

What does JDBC forName() method does for you when you connect to any DB?

Class and the forName() is a static method of the java. lang. Class . The JDBC Drivers (String) will be loaded into the class dynamically at run time and the forName method contains a static block that creates the Driver class object and register with the DriverManager Service automatically.

Spring

What is the stateless bean in spring? name it and explain it.

A stateless session bean is a type of enterprise bean that is commonly used to do independent operations. It does not have any associated client state, but it may preserve its instance state.

Very Good Article on Baeldung

How does the Spring boot auto-detect feature work?

Spring provides a way to automatically detect the relationships between various beans. This can be done by declaring all the bean dependencies in the Spring configuration file. So, Spring is able to utilize the BeanFactory to know the dependencies across all the used beans.

The XML configuration-based autowiring functionality has five modes — no, byName, byType, constructor, and autodetect. The default mode is no.

Autowiring Modes
Spring supports the following autowiring modes:

no: It’s the default autowiring mode. It means no autowiring.
byName: The byName mode injects the object dependency according to the name of the bean. In such a case, the property name and bean name should be the same. It internally calls the setter method.
byType: The byType mode injects the object dependency according to type. So it can have different property names and bean names. It internally calls the setter method.
constructor: The constructor mode injects the dependency by calling the constructor of the class. It calls the constructor having a large number of parameters.
autodetect: In this mode, Spring first tries to autowire by the constructor. If this fails, it tries to autowire by using byType.

If need help regarding clearing the interview you can follow my articles.

Looking for more interview questions and answers?

Here are some recommended books I have used for my preparation.

These books are my recommendation for preparing for CoreJava, Spring-Boot, and Microservices Interview. It has 500+ Questions and answers.

You can get your copy here: Grokking the Java Interview

You can get your copy here Grokking the Spring Boot Interview

Other useful articles

Thanks for reading

  • 👏 Please clap for the story and follow me 👉
  • 📰 Read more content on my Medium (21 stories on Java Developer interview)

Find my books here:

--

--

Ajay Rathod

Software Engineer @Cisco | Java Programmer | AWS Certified | Writer | Find My Books on Java Interview here - https://rathodajay10.gumroad.com/