In this article, we will explore Core Java interview questions and How to explain current Projects in an interview. By familiarizing yourself with these questions and their potential answers, you can better prepare for your next senior Java developer interview and showcase your expertise in the field.
(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).
Download the sample copy here: Guide To Clear Java Developer Interview[Free Sample Copy]
Guide To Clear Spring-Boot Microservice Interview[Free Sample Copy]
Typically, an interview starts with the “Tell me about yourself” question. If you’re unsure about the order, please let me know, and I can provide guidance on how to introduce yourself.
To increase your chances of getting selected, it’s important to prepare your project thoroughly. You can follow these points as a guide:
- Current Project Overview: Provide a brief overview of the project you are currently working on.
- Problem Definition: Explain the problem that this project aims to solve by discussing the problem statement in detail.
- Solution: Talk about the solution that has been implemented for the identified problem.
- Your Contribution: Share information about your specific contributions to the project and highlight what you have delivered.
It’s essential to be well-prepared to answer any questions related to your project, so make sure you have a good understanding of the points mentioned above.
The interviewer may ask you to explain the project’s architecture and tech stack. It is crucial to thoroughly prepare for this and be ready to provide a clear explanation of the project’s architecture and the technologies used.
and then real Q and A starts to check the knowledge of the candidate.
What is the use of Java Generics in Java?
It’s a way to create reusable code and enhance type safety in Java programs. The use of Java Generics allows you to write generic classes, interfaces, and methods that can work with different data types while maintaining compile-time type safety
Can we override private and static methods in java?
It is not possible to override private methods or static methods.
- Private methods: Private methods are methods that are only accessible within the class where they are defined. They cannot be accessed or overridden by any subclass. Private methods are intended for internal implementation details and are not part of the public API of the class. Subclasses cannot see or access private methods, so there is no concept of overriding them.
- Static methods: Static methods belong to the class itself rather than any specific instance of the class. They can be called using the class name and do not depend on any object state. Static methods are not inherited by subclasses, and they cannot be overridden. When a subclass defines a static method with the same signature as a static method in the parent class, it is called method hiding, not method overriding. The subclass method does not override the parent class method, but rather creates a new method that is specific to the subclass.
What is the use of default methods in Java?
- Interface evolution: They allow adding new methods to interfaces without breaking existing implementations.
- Backward compatibility: Default methods enable enhancing interfaces without breaking existing code.
- Interface extension methods: They provide a way to define utility methods or common behavior within an interface.
- Multiple inheritances of behavior: Default methods allow an interface to inherit behavior from multiple interfaces.
What is the use of static methods in Java?
- Utility methods: Static methods in interfaces provide utility functions that can be used by implementing classes without the need for an instance of the interface.
- Helper methods: They can encapsulate common logic or provide helper functionality related to the interface.
- Code organization: Static methods help in organizing related functionality within the interface itself, making the code more structured and maintainable.
- Interface-specific behavior: Static methods allow interfaces to provide default implementation or behavior that can be shared among multiple implementing classes.
Can we call the non-static method from the static method and why not?
In Java, you cannot directly call a non-static method from a static method. Static methods belong to the class itself and do not have access to instance-specific members, such as non-static fields or methods. Non-static methods require an instance of the class to be invoked, and static methods do not have an associated instance.
However, you can call a non-static method from a static method if you have an instance of the class. This means you either need to create an instance of the class inside the static method or pass an instance of the class as a parameter to the static method.
public class MyClass {
public void nonStaticMethod() {
// Method implementation
}
public static void staticMethod() {
MyClass myObject = new MyClass(); // Create an instance of the class
myObject.nonStaticMethod(); // Call the non-static method using the instance
}
}
Can abstract class can have final methods in it?
No, an abstract class cannot have final methods in it. The final
keyword is used to indicate that a method or class cannot be overridden or extended, respectively. Since an abstract class is intended to be subclassed and extended, declaring a method as final
would contradict the purpose of an abstract class.
If two interfaces have the same two defaults methods what will happen, and how to resolve that?
If two interfaces define the same default method with the same method signature, it will cause a compilation error. This situation is known as a “diamond problem”
To resolve the diamond problem in Java 8 interfaces, you have a few options:
- Override the default method: In the class implementing both interfaces, you can override the conflicting default method and provide your own implementation. This resolves the ambiguity by explicitly specifying which implementation to use.
- Specify the desired default method explicitly: You can use the interface name followed by the method name to explicitly call the default method you want to use. For example, if two interfaces,
A
andB
, have a default method calleddoSomething()
, you can callA.super.doSomething()
orB.super.doSomething()
to specify which default method implementation to invoke.
What is the covariant return type in Java?
Covariant return type refers to the concept in object-oriented programming where a subclass (derived class) can have a method that returns a more specific type than the type returned by the same method in the superclass (base class). This allows for more flexibility and specialization in the inheritance hierarchy.
What is LinkedHashmap? how it maintains the insertion order, if we add the same key twice what will happen, will it maintain the same order?
A LinkedHashMap
is a data structure that combines the features of a hash map and a linked list to provide predictable iteration order based on insertion order.
This class extends HashMap and maintains a linked list of the entries in the map, in the order in which they were inserted.
public class Test{
public static void main(String[] args) {
Map<String, Integer> lmap = new LinkedHashMap<>();
lmap.put("key1", 1);
lmap.put("key2", 2);
lmap.put("key3", 3);
lmap.put("key1", 4);
System.out.println(lmap);
}
}
Output : {key1=4, key2=2, key3=3}
So the answer is, Yes even if we insert a duplicate key it will override the value and maintain the order as per the above program output.
Let me know if these questions are helping you.
Till now I have published 17 articles on Java Developer interview Questions, I am sure if you have gone through this, this will help you clear the Java backend role
Java Developer Interview Questions Series:
Senior Java Developer Interview Questions Series-1 (Core Java)
Senior Java Developer Interview Questions Series-2
Core-Java Developer Interview Questions Series-3
Senior Java Developer Interview Questions series-5 (OOPs, Core Java 8, Spring, Coding,prep material)
13 New Java Developer Interview Question Series-6 (Microservices and Java Coding)
Coding Interview Question for Experienced Java Developer role series-7
Most Common Java Developer Interview Questions series-12(Core Java,OOP)
Practical Coding Interview Questions on Spring Data-JPA and Java Stream API Series -14
Senior Java Developer Interview Questions series-15
Must Know Java 8 Stream Interview Questions for Java Developers series-16
Senior Java Dev Interview Question 2023-series-17(Contains All the Interview questions till now)
If you are looking for some interview guides for the Java Developer role you can use the below resources for your prep as well.
Free PDF’s
Grokking the Java Interview [Free Sample Copy]
Grokking the Spring Boot Interview [Free Sample Copy]
Thanks for reading
- 👏 Please clap for the story and subscribe 👉
- 📰 Read more content on my Medium (30 stories on Java Developer interview)
Find my books here: