Core Java Interview Questions and Answers (2024)

Welcome to our Core Java Interview Questions and Answers guide! Whether you’re a seasoned Java developer or someone looking to embark on a career in Java programming, this resource is designed to help you prepare for interviews and deepen your understanding of core Java concepts.


We are sharing Java interview questions , these questions are frequently asked by the recruiters.Java interview questions can be asked from any core java topic . So I try my best to provide you the java interview questions and answers for experienced, Like as: Java or Core Java or java oops concepts or core java interview questions or core java interview questions and answers (2024) or What is core Java basics? What Is Core Java | … In Java | Core Java Topics | Core Java Syllabus | Core Java Interview Questions For 5 Years Experience | Core Java Interview Questions For Freshers Pdf | Core Java Interview Questions Answers| Java Interview Questions | Java Interview Questions For 10 Years Experience ? Boost your interview prep and excel in showcasing your Java skills. Let’s get started! Good luck!

Table of Contents

1. What is Java ? What , why and How ? | What Is Core Java ?

Java is a high-level programming language created by James Gosling in June 1991. Java allows developers to create software that can run on a variety of devices. It is often used to create various applications such as websites and mobile applications.

 


2. Tell me about  or What are the features or property of Java language ?


a. Simple Language: Java is an easy language to learn for software development or implementation.


b. ObjectOriented: In Java programs, everything is considered an object. Objects contains data and behavior (or functions). You can change the behavior  of an object through its properties (or data).


c. Platform Independent: Just write the Java code, It will run within all operating systems. Example: Operating system like as Windows, Linux, Unix or MacOS.


d. Portable:  Java program can run different computer systems because Java code convert into bytecode and this bytecode will run into any computer system.


e. Security In java, pointers work as interanlly, so easily nobody can find the location of object.


f. Robust: Java is robust(or Strong) and uses good memory management and also do the automatic garbage handler, Eception handler etc.


g. Multi-Threading: It run mutiple tasks together and it use the same memory location to execute multiple tasks.


h. Architecture NeutralJava contains the architecture neutral as it does not depend on architecture.

 

i. Distributed: Java also conatins the distributed applications, for example: RMI and EJB



3. What is OOP’s ? or what is OOP’s progamming ?                               (Most Imp Question)

OOP: It stands for Object Oriented Programming. By using the classes & objects , it creates the programs.


Actually, there are 26 concepts in OOP, but  this those languages contains atleast  4 or 6 main concepts that language known as oops based programming language.


a. Object

b. Class

c. Inheritance

d. Polymorphism

e. Abstraction

f. Encapsulation


Object: A object conatins 2 things in Java, state(or property) and behavior. In Java, everything is an object. 

Example: chairs, pens, tables, keyboards, bicycles extra.


Class: A group of items is called a class. Which is contains variables , methods , constuctors and objects extra.


Inheritance: When child class inherits all the properties of Parent class, it is called inheritance.

Exam: Parent-sibling and parent-sibling-child relationships.


Polymorphism: If a task is done in different ways, it is called polymorphism. Overriding and overloading are examples of polymorphism concept.

Exam – eat()   this method can use for many ways like eat the rise , eat the pizza or eat the bread extra 


Abstraction: To hide the internal details and to show functionality is known as the abstraction. 

Example: A common person use the the funtionalities like as calling , smsing or chating but he don’t know about the internal details of Phone, like as : coding software or hardware extra.


Encapsulation: Packaging or binding the program code and data into a unit is called encapsulation.

Exam: Model or Entity class is the example of encapsulation, In Model class members are private so you can’t use outside the class.


public class StudentModel {

private int id;

private String firstName;

private String lastName;

private String eMail;

private String address;

// setter and getter

}



4. What is Constructor ? and types of Constructor.                  (Imp Question)

Constructor: It is just a method(or special method), which is conatins some protocol and create value for Object at run time. 

It is like blue print of class(in java), Just like printing wedding card the store owner tells you the design, color and font of the card, it is called wedding card.



Features of constructor::

a. Constructor name also be same like as class name.

b.No retrun type of constructor.

c. abstract, static, final, native, strictfp, or synchronized these keywords can’t used. 



Constructor types: It have 2 Types


a. Default constructor (also called parameterless constructor)

b. Parameterized constructor


Constructor ChainingThe way oen constructor call or invoke to another constructor, known as consturtor chaining.It is 2 types :


a. Within the same class : One construtor call to another within the same class.Then we use this keyword.


b. Within 2 different classes: By using the super keyword, child class constructor can call to parent class constructor.


5. What is Abstract class & how to achieve Abstraction?


Abstract: This class used the abstract keyword. It provides, from 0 to 100 % abstraction. abstract and non abstract functions(or methods) can use into Abstract class.


How many to achieve the Abstraction: There are two ways to achieve abstraction in java:


Abstract class (0 to 100%)   

Interface (100%)



6. What is Association & Composition ?              (Imp Question)

Relation between 2 Classes – 2 Types 


I). InheritanceIs a relationship –To inherit the all properties of Parent class into Child class by using the extend keyword.
II). Association: Has a relationship – It show relationship between 2 or more then 2 objects.


     a) Aggregation– Week relationship

     b) Composition – Strong  relationship


There are 4 type of Association within Objects:


One to One

One to Many

Many to One, and

Many to Many


Exam: Bank and Employee Relationships , 


Aggregation: In aggregation both Objects are not relate for short time with each other, Like – Collage and Student – After student compete the collage and leave it . so it is a week relationship


Program Example:


         class Student {

int id;

String name;

String school_name;

//create constructor

System.out.println(“\nStudent name is “ + name);

System.out.println(“Student Id is “ + id);

System.out.println(“Student belongs to the “ + school_name + “School”);

}}

class school {

String schoolName;

int noOfStudents;

// create constructor

}

public class AggregationClass

public static void main(String[] args) {

Student n1 = new Student(1, “Shekher”, “Galgotia”);

Student n2 = new Student(2, “Trilok”, “IEC”);

Student n3 = new Student(3, “Aryan”, “ABC”);

}}


CompositionWhen both Objects are relate with each other for forever. like as– Collage and Department. so it is a Strong relationship.


Benefit of Relationship between classes:

 

I) Code Reusability: we can use same code many times, Like as – by extends one class to another and use their methods 

II) Cost cutting: product will not costly

III) Reduce redundancy:  remove unnecessary code



6: What is JDK & how it is work ?         (Most Imp)

JDK- Java Development kit

JDK: (Java Development kitJDK is the piece of software. It is used by developer to develop the software programs and applications. (JRE+ Java development tools – java, javac, javaDoc extra)


JRE:(Java Runtime Environment) it is used by client which is not develop the application, just run the application (JVM +Java Library)


JVM: (Java Virtual Machine) It is used to convert or change the .class file into Machine code or provide output of program.



7: What is JVM & how internally, it works(or Architecture) ?             (Most Imp Question)


JVM - Java Virtual Machine


JVM have 3 Parts :


a). Classloader:


Class loader is a subsystem of JVM used to load class data. Whenever we run a Java program, it is first loaded by the class loader. There are 3 classes of functions in Java.


1. Bootstrap ClassLoader: It loades the all core related jar files to run the perticular program or application. 


2. Extension ClassLoader:  Installs jar files to $JAVA_HOME/jre/lib/ext directory..


3. Application ClassLoader: It,s loads the .class files from classpath.


b). Memory:


1) Class(Method) Area:  it contains the class level variables and methods of class.


2) Heap: It contains java objects of a class.


3) Stack:  It contains the local variables of a class.


4) Program Counter Register: It is contains the address of current executed instruction of JVM.


5) Native Method : It contains all the native methods, which is used to communicate Java to other languages.


c). Execution Engine:


It contains:


1.A virtual processor


2). Interpreter: it convert .class files into Machine or output language.


3). Just-In-Time(JIT) compiler: It is another compiler, Which is use to inhance the speed of Interpreter. 


Java Native Interface:


Java Native Interface (JNI) is a framework which is used to communicate with another language like C, C++.net,Python extra.



8:What are the primitive and Non primitive data members in java?


Primitive: Which is already define by technology, that is known as primitive data members.There are 8 types primitive data member in java.

Eample:  Byte , short , integer, long , char , Boolean , float, double


Non primitive: –Which is manually created by developer.     Exam: Array , String


9: What are the Important Java Keywords ?             (Most Imp Question)
I) Static keywordWe have static to save the memory and we don’t need create object and also Static always invoke at class-Loading time so it will print things before main () . 

Static keyword used with variable, method and block. 


Note: It is share only one time memory. 


10: What is static variable?                                                                                      (Most Imp Question)

If a variable is static then it will share all Objects of that class. You just need one time write one time and It will share 


Exam: static collage-Name = “IEC engg & Technology, Noida” so this object(collage Name) will share with all students objects. 


11: What is static method?


A static method means you don’t need to create a Object to call the static method, it is directly call by class name.


Exam– b Main method of class is a example of static method so don’t need create a object to call this main method, JVM call itself.


public static void main(String[] args) {}


12: What is the static block?


Static block initialize the static data member within a class.


       class StaticBlock_Demo {

static { System.out.println(“This is static block”); }

public static void main(String args[]){

System.out.println(“”);

}}


13: Can we overload a static method? 

Yes. But there arguments should be different.

14: Can we override a static method?

No, because static directly invoke by class-name it don’t need any object creation .
Static method is Binding at compile time so it can’t be override . Overriding always be happening at run time. 

15: Why can’t we override static methods in Java?

Static methods bind at compile time. That why we cannot override static method.

15: Restrictions that are applied to the Java static methods?

These are mainly :

1). The static method  directly can’t invoke (or call ) the non-static methods.
2). this and super cannot be used wtih static context.


16: Why is the main method static

JVM can call the main method bec static method without to create any object and If JVM create object then invoke the main() , it will be consume more memory . So main method don’t need any object creation. 

17: Can we execute a program without main() method?

No, The static block was used before Java 7.It is not possible after java 7.

18: Can we make constructors static?

Static method always call by class name. Constructor used to construct the value for a object within a class so There is no sense to make consturctor as static. if you this then compiler will show the compiler error.


19: Can we declare the static variables and methods in an abstract class?

Yes. Because we don’t need object to access the static content.


20). This  Keyword This is a variable that refers to the current element(or object).

What time this call: When class level variable and local level variable are same type then compiler will confused to identify the local and class variable. So by using this keyword, complier identify the left-hand side is Class variable and right-hand side is a local variable.

Example:
         class Student {

int age;

String name;

Student(int age, String name) {

this.age = age;

this.name = name;

}

void display() {

System.out.println(age + ” “ + name);

}}

class ThisKeyword_Demo {

public static void main(String args[]) {

Student s1 = new Student(25, “ankit”);

Student s2 = new Student(30, “sumit”);

s1.display();

s2.display();

}}


21). Super Keyword: The use of super keyword is, to get the property of Parent class into Child class by forcefully.
Suppose if you get your parent property forcefully then you can get by super keyword in java.

22). Final Keyword: Final keyword use to restrict the user accessibility( means you can’t access that variable for perticular task).
It restrict the access by 3 types in Java: 
Use with Variable: Then the variable value will be constant (or not changeable).

Use with Method: You can’t override that method.

Use with Class:  you can’t extend that class.


23). Volatile keyword: If you make a variable volatile, it means it will save in main memory. Benefit is that if 2 or more thread are using same variable form cache memory may some thread modify the value of variable and that variable is accessing by multiple thread, so it will effect to other thread values.



Note: Variable was made as thread safe by using this keyword.Variable was made as thread safe by using this keyword.This keyword also used to make Variable as thread safe. 



24). Transient keyword: The Transient keyword is used with variables to prevent it from being serialized. It means this variable will create at your local level.
Example: transient, persist and detached state in hibernate Where in Transient level only object be created.


……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………







People also ask- What Is Core Java | … In Java | Core Java Topics | Core Java Syllabus | Core Java Interview Questions For 5 Years Experience | Core Java Interview Questions For Freshers Pdf | Core Java Interview Questions Answers| Java Interview Questions | Java Interview Questions For 10 Years Experience  core java | java interview questions | core java interview questions | core java topics | core java syllabus | core java tutorial | core java concepts | core java interview questions for 5 years experience | core java interview questions for 10 years experience | core java notes pdf | history of core java | what is java and core | core java and oops concepts | core java and spring | Java Interview Questions | 180 Core Java Interview Questions and Answers [2024] | Top Core Java Interview Questions and Answers [2024] | 200+ Core Java Interview Questions and Answers (2024) | 300 Core Java Interview Questions (2023) | Top Core Java Interview Questions and Answers (2024 | What is core Java basics? | How to prepare core Java interview questions? | Why core Java is used? | What is JDK in Java interview questions? | keywords of java programming language | why keywords are used in java | how many java keywords | jdk | jdk download | jdk 17 | jdk 17 download | jdk 11 | jdk 8 | jdk 21 | jdk vs jre | jdk 1.8 | jdk 11 download | how jdk works in java | how jdk works | how jdk install | jdk how to check version | how install jdk in windows 10 | how check jdk version in cmd | how install jdk in ubuntu | how to jdk version | how install jdk on mac | how to jdk in eclipse | jdk and jre | java 8 download | java 8 download mac | java 8 download windows | how java 8 solve diamond problem | how java 8 stream works internally | how java 8 | is java 8 still supported | is java 8 the latest version | is java 8 end of life | what java 8 features | is java 8 functional programming | java Streams api | what oops in java | what is oops in java interview questions | what is oops in java with example | what oops concepts in java | what are java generics | does java have generics | how java generics works internally | java how generics works | how do java generics work | how to create java generic class | java how to get generic type class    | how java reflection works | is java reflection slow | is java reflection bad | java reflection | java reflection example | how java reflection works | how java enum works | is java enum serializable | is java enum static | is java enum a class | what is enum in java | 

 | What is core Java basics? | Why core Java is used? | core java interview questions for freshers| java interview questions experienced | java keywords | What are the Java keywords? | What is the JVM Architecture?| What is the Java Architecture?  | java oops concepts ..