Top 30 Core Java Interview Questions & Answers 2023

Welcome to our collection of Core Java Interview Questions! In this article, we have curated a list of essential Core Java interview questions that cover the fundamental concepts of Java programming. Whether you are a beginner or an experienced developer, these questions will help you prepare for your Java job interviews. Each question is accompanied by a concise answer to provide you with a quick understanding of the topic.

Table of Contents

Let’s get started and enhance your Java knowledge for a successful interview!

OOPS: Core Java Interview Questions

In this section, we will focus on core Java interview questions on OOPs Concepts.

What are differences between Inheritance,Composition and Aggregation?

Please take a moment to read through the following article Inheritance vs Composition vs Aggregation for more comprehensive explanation.

When to use Inheritance and when to use Composition?

Please take a moment to read through the following article choosing between inheritance and composition for more comprehensive explanation.

Why Does Java Not Support Multiple Inheritance?

Please take a moment to read through the following article why-does-java-not-support-multiple-inheritance for more comprehensive explanation.

Abstraction vs Encapsulation vs Data Hiding

Please take a moment to read through the following article Abstraction vs Encapsulation vs Data Hiding for more comprehensive explanation.

Compile time polymorphism vs Run time polymorphism

what are the rules for method overloading and method overriding?
Please take a moment to read through the following article Polymorphism in Java to for more comprehensive explanation.

Static Binding vs Dynamic Binding

Binding is a process of associating a method call with the proper method body.

We can distinguish two types of binding in Java: static and dynamic.

The main difference between static binding and dynamic binding is that static binding occurs at compile time and dynamic binding at runtime.

Static binding uses class information for binding. It’s responsible for resolving class members that are private or static and final methods and variables.
Also, static binding binds overloaded methods.

Dynamic binding, on the other hand, uses object information to resolve bindings. That’s why it’s responsible for resolving virtual and overridden methods.

Please read Polymorphism in Java  for more details.

Immutable Class

In this section, we will focus on core Java interview questions on Immutable Classes.

  1. What do you mean by Immutable Class?
  2. Give some examples of Immutable Class.
  3. How to create a Immutable class in Java?
    Please read Immutable Classes to get the answers for the above question.

String: Core Java Interview Questions

In this section, we will focus on core Java interview questions on String Class.

  1. Why is String immutable?
  2. What are the different ways to create String Object?
  3. What is String Constant Pool?
  4. What do you mean by String Interning?

Please read All About String in Java to get the Answers for the Above Questions

Click the link String vs StringBuffer vs StringBuilder

Core Java Interview Questions

Basic Core Java Interview Questions

In this section, we will focus on basic core Java interview questions.

What is Object Class? What are the important methods of the Object Class?

Please read Object Class for the Answer.

What do you mean by Boxing and Unboxing?

Please read Boxing and Unboxing for the Answer.

What are Widening and Narrowing Primitive Conversions ?

Please read Widening and Narrowing Primitive Conversions for understanding the concept in a better way.

What do you mean by Upcasting and Downcasting?

Please read Reference Type casting for the answer.

What do you mean by Pass By Value and Pass by Reference?In Java , how are the variables passed to the methods? Is it Pass By Value or Pass by Reference?

Please read Pass By value to get the answer.

How many types of initializers are there in java?

Click Java Initializers to get the answer.

What is the use of the keyword strictfp?

Read strictfp to know more about it.

How is the Java platform independent?

Platform independent language means once compiled you can execute the program on any platform (OS).

Java is platform-independent but JVM( Java Virtual Machine) is platform dependent. How?

Java compiler converts the source code to bytecode, which is Intermidiate Language. Bytecode can be executed on any platform (OS) using JVM.

What are access modifiers in Java? protected vs default access modifier

Please read Access Modifiers

What are non access modifiers in Java?

Please read Non-access modifiers

What’s the purpose of Static methods and static variables?

Please read static keyword

What is native keyword used for?

Please read native keyword

What is switch case? Give example.

Please read Java Switch

Why does Java not support Multiple Inheritance?

Please read  Why does Java not support Multiple Inheritance?

What do you mean by Boxing and Unboxing ?

Please read Boxing and Unboxing

What Are Two Types of Casting in Java? Which Exception May Be Thrown While Casting? How Can We Avoid It?

Please read Reference Type Casting

Differentiate between == and equals() ?

Answer 

equals method is used to check the equality of two objects based on it’s contents.

equals versus ==

If two references point to the same object then only “==” returns true
For example:

String str1 = new String(“abc”);
String str2 = str1; // Here str1 and str2 are pointing to the same Object
String str3 = new String(“abc”);//str3 is pointing to another Object
System.out.println(“str1 == str2 :”+ (str1 == str2));// this will print true
System.out.println(“str1 == str3 :”+ (str1 == str3));// this will print false

But equals checks for equality of the Objects. String class’s equals method returns true if both the Strings contain same sequence of characters. For the above example the content for both the String Objects is same i.e., “abc”

System.out.println(“str1.equals(str2) :”+ (str1.equals(str2)));// this will print true
System.out.println(“str1.equals(str3) :”+ (str1.equals(str3)));// this will print true

Note: if objectRef1 == objectRef2 returns true, then objectRef1.equals(objectRef2) must return true.

Please also read equals and hashCode

What is final keyword in Java?

Please read final keyword

Explain public static void main(String args[ ]) in Java

Answer:

The execution Java program starts with public static void main(String args[ ]), also called the main() method.

public: It is an access modifier defining the accessibility of the class or method. Any Class can access the main() method defined public in the program.

static: The keyword indicates the variable, or the method is a class method. The method main() is made static so that it can be accessed without creating the instance of the class. When the method main() is not made static, the compiler throws an error because the main() is called by the JVM before any objects are made, and only static methods can be directly invoked via the class.

void: It is the return type of the method. Void defines the method does not return any type of value.

main: JVM searches this method when starting the execution of any program, with the particular signature only.

String args[]: The parameter passed to the main method.

Leave a Reply

Your email address will not be published. Required fields are marked *