Top 50 Core Java Interview Questions & Answers 2023

Java is one of the most popular programming languages and this is used in so many applications and software as well. So the IT companies are always looking for credible people to hire. Although Core Java is in demand right now the competition isn’t any less. You should know that you will be competing against so many people to get that job and that’s where you have to prepare yourself and be better than others.
Since every candidate has to go through the interview, you should make sure that you are better than anyone else. The only way to do so is to prepare yourself for the interview. How do you do that? Easy just look up some of the questions that might be asked in the Core Java interview and prepare them.
However, finding such questions isn’t going to be easy. You can never know which question they might ask especially if you are fresher. Well, we are here to help you out and we would do so by introducing you to some of the most commonly asked core java interview questions. Go ahead and take a look at the following list of core java interview questions that might be asked to you in the interview.
Core Java Interview Questions

Core java interview questions

Q1.What is Java?
Java is the high-level, object-oriented, robust, secure programming language, platform-independent, high performance, Multithreaded, and portable programming language. It was developed by James Gosling in June 1991. It can also be known as the platform as it provides its own JRE and API.
Q2.What do you understand by Java virtual machine?
Java Virtual Machine is a virtual machine that enables the computer to run the Java program. JVM acts like a run-time engine which calls the main method present in the Java code. JVM is the specification which must be implemented in the computer system. The Java code is compiled by JVM to be a Bytecode which is machine independent and close to the native code.
Q3.What is the difference between JDK, JRE, and JVM?
JVM is an acronym for Java Virtual Machine; it is an abstract machine which provides the runtime environment in which Java bytecode can be executed. It is a specification which specifies the working of Java Virtual Machine. Its implementation has been provided by Oracle and other companies. Its implementation is known as JRE.
JVMs are available for many hardware and software platforms (so JVM is platform dependent). It is a runtime instance which is created when we run the Java class. There are three notions of the JVM: specification, implementation, and instance.
JRE stands for Java Runtime Environment. It is the implementation of JVM. The Java Runtime Environment is a set of software tools which are used for developing Java applications. It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of libraries + other files that JVM uses at runtime.
JDK is an acronym for Java Development Kit. It is a software development environment which is used to develop Java applications and applets. It physically exists. It contains JRE + development tools. JDK is an implementation of any one of the below given Java Platforms released by Oracle Corporation:
Standard Edition Java Platform
Enterprise Edition Java Platform
Micro Edition Java Platform
Q4.What is JIT compiler?
Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the bytecode that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.
Q5.What are the main differences between the Java platform and other platforms?
There are the following differences between the Java platform and other platforms.
Java is the software-based platform whereas other platforms may be the hardware platforms or software-based platforms.
Java is executed on the top of other hardware platforms whereas other platforms can only have the hardware components.
Q6.What gives Java its ‘write once and run anywhere’ nature?
The bytecode. Java compiler converts the Java programs into the class file (Byte Code) which is the intermediate language between source code and machine code. This bytecode is not platform specific and can be executed on any computer.
Q7.What is classloader?
Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.
Bootstrap ClassLoader: This is the first classloader which is the superclass of Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java net package classes, java.util package classes, package classes, java.sql package classes, etc.
Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loads the jar files located inside $JAVA_HOME/jre/lib/ext  directory.
System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the class files from the classpath. By default, the classpath is set to the current directory. You can change the classpath using “-cp” or “-classpath” switch. It is also known as Application classloader.
Q8.What is the platform?
A platform is the hardware or software environment in which a piece of software is executed. There are two types of platforms, software-based and hardware-based. Java provides the software-based platform.
Q9.Is delete, next, main, exit or null keyword in java?
Q10.If I don’t provide any arguments on the command line, then what will the value stored in the String array passed into the main() method, empty or NULL?
It is empty, but not null.
Q11.What if I write static public void instead of public static void?
The program compiles and runs correctly because the order of specifiers doesn’t matter in Java.
Q12.What is the default value of the local variables?
The local variables are not initialized to any default value, neither primitives nor object references.
Q13.What are the various access specifiers in Java?
In Java, access specifiers are the keywords which are used to define the access scope of the method, class, or a variable. In Java, there are four access specifiers given below.
Public The classes, methods, or variables which are defined as public, can be accessed by any class or method.
Protected Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
Default Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
Private The private class, methods, or variables defined as private can be accessed within the class only.
Q14.What is the purpose of static methods and variables?
The methods or variables defined as static are shared among all the objects of the class. The static is the part of the class and not of the object. The static variables are stored in the class area, and we do not need to create the object to access such variables. Therefore, static is used in the case, where we need to define variables or methods which are common to all the objects of the class.
For example, In the class simulating the collection of the students in a college, the name of the college is the common attribute to all the students. Therefore, the college name will be defined as static.
Q15.What is object-oriented paradigm?
It is a programming paradigm based on objects having data and methods defined in the class to which it belongs. Object-oriented paradigm aims to incorporate the advantages of modularity and reusability. Objects are the instances of classes which interacts with one another to design applications and programs. There are the following features of the object-oriented paradigm.
Follows the bottom-up approach in program design.
Focus on data with methods to operate upon the object’s data
Includes the concept like Encapsulation and abstraction which hides the complexities from the user and show only functionality.
Implements the real-time approach like inheritance, abstraction, etc.
The examples of the object-oriented paradigm are C++, Simula, Smalltalk, Python, C#, etc.
Q16.What is an object?
The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables as the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new  keyword.
Q17.What is the difference between an object-oriented programming language and object-based programming language?
There are the following basic differences between the object-oriented language and object-based language.
Object-oriented languages follow all the concepts of OOPs whereas, the object-based language doesn’t follow all the concepts of OOPs like inheritance and polymorphism.
Object-oriented languages do not have the inbuilt objects whereas Object-based languages have the inbuilt objects, for example, JavaScript has window object.
Examples of object-oriented programming are Java, C#, Smalltalk, etc. whereas the examples of object-based languages are JavaScript, VBScript, etc.
Q18.What will be the initial value of an object reference which is defined as an instance variable?
All object references are initialized to null in Java.
Q19.What is the constructor?
The constructor can be defined as the special type of method that is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for the object. Every time, an object is created using the new keyword, the default constructor of the class is called. The name of the constructor must be similar to the class name. The constructor must not have an explicit return type.
Q20.Does constructor return any value?
Ans: yes, The constructor implicitly returns the current instance of the class (You can’t use an explicit return type with the constructor).

Advanced core java interview questions

Advanced core java questions
Q21.Is constructor inherited?
No, The constructor is not inherited.
Q22.Can you make a constructor final?
No, the constructor can’t be final.
Q23.What are the advantages of Packages in Java?
There are various advantages of defining packages in Java.
Packages avoid the name clashes.
The Package provides easier access control.
We can also have the hidden classes that are not visible outside and used by the package.
It is easier to locate the related classes.
Q24.Can we make constructors static?
As we know that the static context (method, block, or variable) belongs to the class, not the object. Since Constructors are invoked only when the object is created, there is no sense to make the constructors static. However, if you try to do so, the compiler will show the compiler error.
Q25.Can we make the abstract methods static in Java?
In Java, if we make the abstract methods static, It will become the part of the class, and we can directly call it which is unnecessary. Calling an undefined method is completely useless therefore it is not allowed.
Q26.Why is the main method static?
Because the object is not required to call the static method. If we make the main method non-static, JVM will have to create its object first and then call main() method which will lead to the extra memory allocation.
Q27.Can we override the static methods?
No, we can’t override static methods.
Q28.Can we declare a constructor as final?
The constructor can never be declared as final because it is never inherited. Constructors are not ordinary methods; therefore, there is no sense to declare constructors as final. However, if you try to do so, The compiler will throw an error.
Q29.Can we declare an interface as final?
No, we cannot declare an interface as final because the interface must be implemented by some class to provide its definition. Therefore, there is no sense to make an interface final. However, if you try to do so, the compiler will show an error.
Q30.Can there be an abstract method without an abstract class?
No, if there is an abstract method in a class, that class must be abstract.

Core java interview questions for freshers

Q31.Can you use abstract and final both with a method?
No, because we need to override the abstract method to provide its implementation, whereas we can’t override the final method.
Q32.Is it possible to instantiate the abstract class?
No, the abstract class can never be instantiated even if it contains a constructor and all of its methods are implemented.
Q33.What is the interface?
The interface is a blueprint for a class that has static constants and abstract methods. It can be used to achieve full abstraction and multiple inheritance. It is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java. In other words, you can say that interfaces can have abstract methods and variables. Java Interface also represents the IS-A relationship. It cannot be instantiated just like the abstract class. However, we need to implement it to define its methods. Since Java 8, we can have the default, static, and private methods in an interface.
Q34.Can you declare an interface method static?
No, because methods of an interface are abstract by default, and we can not use static and abstract together.
Q35.Can the Interface be final?
No, because an interface needs to be implemented by the other class and if it is final, it can’t be implemented by any class.
Q36.Can we define private and protected modifiers for the members in interfaces?
No, they are implicitly public.
Q37.When can an object reference be cast to an interface reference?
An object reference can be cast to an interface reference when the object implements the referenced interface.
Q38.What is the difference between the final method and abstract method?
The main difference between the final method and abstract method is that the abstract method cannot be final as we need to override them in the subclass to give its definition.
Q39.How can we access some class in another class in Java?
There are two ways to access a class in another class.
By using the fully qualified name: To access a class in a different package, either we must use the fully qualified name of that class, or we must import the package containing that class.
By using the relative path, We can use the path of the class that is related to the package that contains our class. It can be the same or subpackage.
Q40.Do I need to import java.lang package any time? Why?
No. It is by default loaded internally by the JVM.

Core java interview questions and answers for experienced

Q41.Can I import same package/class twice? Will the JVM load the package twice at runtime?
One can import the same package or the same class multiple times. Neither compiler nor JVM complains about it. However, the JVM will internally load the class only once no matter how many times you import the same class.
Q42.What is the static import?
By static import, we can access the static members of a class directly, and there is no to qualify it with the class name.
Q43.What is the purpose of using javap?
The javap command disassembles a class file. The javap command displays information about the fields, constructors and methods present in a class file.
javap fully_class_name
Q44.Can you access the private method from outside the class?
Yes, by changing the runtime behavior of a class if the class is not secured.
Q45.Can an exception be rethrown?
Q46.Can subclass overriding method declare an exception if parent class method doesn’t throw an exception?
Yes but only unchecked exception not checked.
Q47.How the metacharacters are different from the ordinary characters?
Metacharacters have the special meaning to the regular expression engine. The metacharacters are ^, $, ., *, +, etc. The regular expression engine does not consider them as the regular characters. To enable the regular expression engine treating the metacharacters as ordinary characters, we need to escape the metacharacters with the backslash.
Q48.Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; Its length must be in between 8 to 20.
The regular expression for the above criteria will be: ^[a-zA-Z][a-zA-Z0-9]{8,19} where ^ represents the start of the regex, [a-zA-Z] represents that the first character must be an alphabet, [a-zA-Z0-9] represents the alphanumeric character, {8,19} represents that the length of the password must be in between 8 and 20.
Q49.What are the advantages of defining packages in Java?
By defining packages, we can avoid the name conflicts between the same class names defined in different packages. Packages also enable the developer to organize the similar classes more effectively. For example, one can clearly understand that the classes present in package are used to perform io related operations.
Q50.What is the purpose of the strictfp keyword?
Java strictfp keyword ensures that you will get the same result on every platform if you perform operations in the floating-point variable. The precision may differ from platform to platform that is why java programming language has provided the strictfp keyword so that you get the same result on every platform. So, now you have better control over the floating-point arithmetic.

Conclusion –

So these are some of the popular core java interview questions that you can find. We have happened to list down these questions with some assistance from some professionals and experts who wants to help the freshers and experienced job seekers.
Although we are not saying that these would be the only questions asked in a Core Java interview, these would certainly some common questions that you can expect. So it won’t harm you to prepare for these questions before your interview. So go ahead and prepare yourself for the interview. Best of luck to you for your upcoming interview.

Leave a Comment