Senior Java Developer Interview Questions series-5 (OOPs, Core Java 8, Spring, Coding, prep material)

Typical Java discussion starts with OOPS and then it goes to Core Java where basics are evaluated and finally, they test your framework knowledge like Spring, Hibernate and etc. Here are some real interview questions asked and discussed in an interview. You can find a Free book on Preparation Material for Java.

Ajay Rathod
5 min readApr 22, 2022

--

(A bit of context: I’ve conducted numerous interviews for software engineering positions in most of the MNCs. Additionally, there have been instances where I faced challenges during coding interviews due to lack of preparation.)

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]

By: Marshall Brain

Object-oriented Programming :

What is Method Overloading/Overriding?

By JavaHungry

Can we override the static method? Why Can't we do that?

Static methods cannot be overridden because they are not dispatched on the object instance at runtime. The compiler decides which method gets called. Overloading is also called static binding, so as soon as the word static is used it means a static method cannot show run-time polymorphism.

Very good link to it, please refer to that.

What is the use of static keywords in java? (too basic right ?)

It means we’ll create only one instance of that static member that is shared across all instances of the class.

What is the Covariant type?

Covariant return type refers to the return type of an overriding method. It allows the narrowing down of the return type of an overridden method without any need to cast the type or check the return type. The covariant return type works only for non-primitive return types

Memory Management in Java

Explain memory management in java.

So, in java you don’t have to worry about memory management like CPP, It is good to know how this works in java. Especially after java 8 changes where there are major updates regarding it.

In java 8, Permgen is replaced by Metaspace, we should be able to answer what advantage it offers.

What is MetaSpace in java 8 memory? what benefits it offers?

Basically, up till java 7, JVM stores all the static content in this memory section. This includes all the static methods, primitive variables, and references to the static objects.

Furthermore, it contains data about bytecode, names, and JIT information. Before Java 7, the String Pool was also part of this memory. this was leading to OutOfMemoryError in java to reduce that Oracle removed permgen and added MetaSpace which grows automatically and reduces generating the famous OutOfMemoryError.

JAVA-8 Questions

What is a Functional interface in java-8?

Any interface which is having single abstract can be called a Functional Interface.

Examples:

interface FileFilter { boolean accept(File x); } interface ActionListener { void actionPerformed(…); } interface Callable { T call(); }

What are the types of Functional interfaces?

What are the Intermediate and terminal operations in java 8?

· filter()

· map()

· flatMap()

· distinct()

· sorted()

· peek()

· limit()

· skip()

What is the terminal operation in java?

Java Streams Terminal Operations such as AnyMatch, Collectors, Count, FindAny, FindFirst, Min, Max, NoneMatch, and AllMatch.

Coding

Write a Program to find the duplicates in an array using stream API.

int[] arr = {1,2,3,5,5,6,6,5} print only duplicates using stream operations?

class Test{

public static <T> Set<T>
findDuplicateInStream(Stream<T> stream)
{

// Set to store the duplicate elements
Set<T> items = new HashSet<>();

// Return the set of duplicate elements
return stream

// Set.add() returns false
// if the element was
// already present in the set.
// Hence filter such elements
.filter(n -> !items.add(n))

// Collect duplicate elements
// in the set
.collect(Collectors.toSet());
}

// Driver code
public static void main(String[] args)
{

// Initial stream
Stream<Integer> stream
= Stream.of(5, 13, 4,
21, 13, 27,
2, 59, 59, 34);

// Print the found duplicate elements
System.out.println(
findDuplicateInStream(stream));
}
}

Write a program to find the missing number in an Array.

int[] arr = {1,2,3,5,6} you need to find 4 that is missing in this.

Write a Program to Find a possible combination of the given string “GOD”?

Spring boot/Microservices

What is the Spring bean lifecycle?

A Spring bean needs to be instantiated when the container starts, based on Java or XML bean definition. The framework may also be required to perform some pre- and post-initialization steps to get the bean into a usable state.

After that, when the bean is no longer required, it will be removed from the IoC container. Like the initialization phase, the Spring framework may need to perform pre-and post-destruction steps to free the other system resources.

Difference Between BeanFactory and ApplicationContext?

https://www.baeldung.com/spring-beanfactory-vs-applicationcontext

What are the types of dependency injection and what benefit we are getting using that?

What are @ResponseBody Annotations?

What is horizontal scaling how to achieve that?

What is the difference between a container and a virtual machine?

What is a Builder Design pattern?

Some of the questions have not been answered here, because of the limited time I have. Surely I will be filling those spaces soon.

If you want any help regarding your prep, you can follow my articles.

How I got more than 10 offer letters as a Java Developer in 3 months.

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/