Core Java Interview Questions and Answers

By | November 10, 2021
Core Java Interview Questions

Java Core is an edition of Java also known as Java SE (Standard Edition). The core java is basic Java and in interviews, most of the Core java Interview questions for a java developer come from here. Here in this article we have mentioned the frequent questions ever asked in the Java Interview. With the increment in the flow of interview questions, difficulty raise too.

Core Java Interview Questions and Answers

Now here we have listed a lot of interview questions that can be asked in the interview by the interviewer


1. What is Java?

Answer: Java is a general-purpose high-level, object-oriented programming language that works on the principle “write once and run anywhere”. It was developed by James Gosling in 1991 at Sun Microsystems later bought by Oracle Corporation. 

Read more about Java Programming Languages here.

2. What is Core Java?

Answer: When Oracle bought Java, they give their own definition to it and release a Java Standard Edition which is commonly known as Java. The core Java deals with the basic type and Object of Java Programming. 

3. What is the latest version of Java?

Answer: Java SE 17 is the latest version of Java that comes with Long Term Support (LTS).

The next Java versions tentative release dates are

Java Versions Release Date
Java SE 18 March 2022
Java SE 19 September 2022
Java SE 20 March 2023
Java SE 21 (LTS) September 2023


4. What is JVM?

Answer: JVM is an acronym for Java Virtual Machine. JVM is one of the parts of the Java Runtime Environment (JRE). It is the one which calls the Main method of Java Code.

5. How does a bytecode run in JAVA?

Answer: Bytecode is a compiled format of a java program. Classloader loads the bytecode into a java runtime environment where the JIT compiler converts bytecode into machine-dependent code.

6. What is Thread in Java?

Answer: The flow of execution is referred to as a thread. The main which is used in every java program is also a thread. This main thread is created by JVM. The user can create their own thread by extending the thread class.

7. Why do we declare Main as Static?

Answer: Main is the entry point of the program hence it is declared as static. For calling the static method we never need an object of a class.

8. What is Super Keyword in JAVA and Where to use it?

Answer: If superclass and subclass both have the same method as well as the variable name, to identify superclass variables & methods in the subclass, a super keyword is used. It is always written in the subclass only when the method name is the same. It is used to class superclass constructors explicitly.

9. When a subclass has only parameterized constructor and a superclass does not have a matching constructor, What will happen?

Answer: A default constructor of the superclass will get invoked when a subclass has only parameterized constructor and the superclass does not have any matching constructor.

If the superclass has parameterized constructor and the subclass wants to use that constructor then we must write the “super” keyword to pass parameters in the superclass constructor.

The super keyword must be written in the very first line in the constructor of the subclass.

10. Explain Public Static Void Main (String args[]).


Access modifier is also known as Access specifiers. Access modifiers in Java have clarified the classes which can access a given class and its fields, constructors, and methods.

  • Public: A type of access modifier. It is used to specify who can access this method. This means that this method can be accessed by any class.
  • Static: It is a keyword in java that identifies it can be accessed without creating the instance of a Class.
  • Void: Void is a return type of method that will not return any value.
  • Main: It is referred to as a method that is searched by JVM as a starting point for an application with a particular signature only.
  • String args[]: It is a parameter that is passed to the main method.

11. What are Constructors in Java?

Answer: In Java, Constructors are the block of codes that are similar to a method. A constructor is called when an instance of an object is created. The name of the constructor is kept the same as the name of the class. There is no return type of a constructor, not even void. If we don’t create an explicit constructor in our class, the java compiler supplies it by default.

12. What do you understand by a Wrapper class?

Answer: A wrapper class is a class that converts java primitives into reference-type objects. They “wrap” the primitive data type into an object of that class, therefore they are referred to as wrapper class.

13. Explain the local variable and instance variable?

Answer: Local variables are defined inside methods and constructors. Instance variables are those variables that are present within a class but outside any method.

14. Why JAVA is a statically typed language?

Answer: Java is referred to as a statically typed language as the type of the variable is known at the compile time.

15. What is Java Runtime Environment(JRE)?

Answer: JRE is the abbreviation of the Java Runtime Environment. It is an environment in which bytecode runs. In other words, JRE is a software package that has everything that needs to run a Java Program.

16. What is Package in JAVA?

Answer: Packages in Java is a group of similar kind of classes, subclasses, interfaces. There are two categories of packages: Built-in and user-defined packages. The built-in packages are java, lang, awt, Java X, swing, net, io, util, SQL etc.

The keyword “package” is used to create a package in Java.


package mypack;  
public class Simple
public static void main(String args[])
System.out.println("Welcome to package");  

17. What is the Java language programming platform?

Answer: Java is a programming language and a platform too. A Java platform is an environment for the Java programming language on which its application runs.

18. What are the components of JVM?

Answer: The three main components of Java are JVM, JDK, JRE.

  • JVM is known as Java Virtual Machine. It is required to run a Java application.
  • JDK is known as the Java Development Kit. It is a software development environment that is used for developing Java applications and applets.
  • JRE or Java Runtime Environment is a set of software that is used to create Java applications. JRE is that which combines JVM and JDK Together.

19. Name all Java Programming language platforms.


  • Java Platform Standard Edition
  • Java Platform, Enterprise Edition
  • Java Platform, Micro Edition
  • JavaFX

20. What are the components that a Java Platform consists of?

Answer: All Java platforms have two components Java Virtual Machine (VM) and Application Programming Interface (API). 

21. What is Java Virtual Machine?

Answer: It is a program that is designed for specific hardware and software platforms so it could run the application based on Java Technology. 

22. What is an API?

Answer: API stands for Application Programming Interface which is a software component collection, that a Java developer uses to develop other software components and applications. 

23. What is Java EE?

Answer: Java EE where EE stands for Java Enterprise Edition which is also known as Advance Java, this Java platform is made upon Java Standard Edition platform. This platform is mainly used to create enterprise-level applications because this provides an API and runtime environment for developing and running large-scale applications. 

24. What is Java ME?

Answer: Java ME or Micro Edition, this platform of Java is used to create micro native applications for small devices like Mobile Phones. This platform uses Java Standard Edition API and libraries to develop applications. 

25. What is JavaFX?

Answer: This Java platform is used to build and develop Internet-based applications that use lightweight API. 

26. Give some features of Core Java.


  • It is simple basically it follows a similar syntax based on the C++ language
  • It is an Object-oriented programming platform, which follows all the concepts of OOP’s.
  • It is platform-independent.
  • It provides security as compared to other programming languages
  • It has a strong Memory management
  • The provides high-quality application development
  • It supports multithreaded which means it can handle many tasks at once.

Read more Features of Java

27. Name all the OOPS concepts present in Java.


  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Association
  • Aggregation
  • Composition

28. Is Java a pure object-oriented programming language?

Answer: No, Java is not a pure object-oriented programming language because it has primitive data types which are not objects, and to be a pure object-oriented programming language everything should be an object in the programming language. 

29. Is the Java Virtual machine platform independent?

Answer: No, it is not that’s why we have different JVM for different platforms. 

30. What is abstraction?

Answer: Abstraction is a process of hiding the main source from the user and only showing the functionality it is the common practice of each object-oriented programming language. 

31. What is the difference between JVM and JRE?

Answer: Java Runtime Environment (JRE) is a collection of JVM and java binaries, basically, JRE is the implementation of Java Virtual Machine.

32. What is a Classloader?

Answer: A Java Classloader is an inbuilt program in JDK that is used to load the byte code program into memory when a program accesses any class. 

33. Name all the different types of Classloader in Java.


  • Bootstrap Classloader
  • Extension Classloader
  • System Classloader

34. What is a class in Java?

Answer: Everything we code in Java we code it inside a class block, here the class is a blueprint of an object and a collection of different attributes and methods. 

35. What is an Object?

Answer: An object in Java is a combination of data and procedures and it has states and behaviors.

36. What is a constructor?

Answer: A constructor is a method in the class that shares the same name as the class, and it gets invoked automatically at the moment the object of that class gets created. Basically, the constructor of a class is used to initialize values to the variables. 

37. Name all the types of the constructor we used in JAVA?

Answer: Java constructors are of two types:

  • Default constructor
  • Parameterized constructor

38. What is an Object?

Answer: When we create an instance of the class is known as its object. Basically, at the moment we create the instance or object of a class that class comes into existence, and with the help of that object or instance, we could access the class attributes and methods. 

39. What is inheritance?

Answer: Inheritance is one of the important OOPs concepts used to increase code reusability in a programming language. With the help of inheritance, we can use the properties of one class in another class.

40. Is String a datatype in JAVA?

Answer: The string is not a primitive data type, while it’s an object of string. lang.string class that gets created when a string is created in Java. We can use all the built-in methods of a string class on the string object.

41. What is the difference between Array and ArrayList?


Array ArrayList
An array is a fixed-length data structure.


String[] name = new String[2]

It’s a variable length collection class.


ArrayList name = new ArrayList

We need to specify the index to put an object in an array.


name[1] = “cat”

No indexing is required.



Not type parameterized as ArrayList. It is type parameterized.

42. Explain Public and Private access specifiers.

Answer: An access specifier in java is used to restrict the scope of a class, constructor, variable, method, or data member.

  • Public Specifiers: They are specified using the public keyword. The public members are visible in the same package as well as the outside package that is for other packages.
  • Private Specifiers: They are specified using the private keyword. Private members can be seen in the same class. They are not for the other classes in the same package as well as classes outside of packages.

43. What is the Java superclass for all classes?

Answer: java.lang.object is the root class for all Java classes. 

44. Explain Method Overloading and Overriding.

Answer: Method Overloading:

Method overloading is one of the important features of Java which allows a class to have more than one method with the same name and their argument list is different. Method overloading keeps the method name the same. It depends on a number of parameters and their data types.


class Adder
Static int add(int a, int b)
return a+b;
Static double add( double a, double b)
return a+b;
public static void main(String args[])

Method Overriding:

Method overriding is defined as the definition of the superclass is used by a subclass using the same method signature.


class Car
void run()
System.out.println(“car is running”);
Class Audi extends Car
void run()
System.out.prinltn(“Audi is running safely with 100km”);
public static void main( String args[])
Car b=new Audi();;

45. What is an interface in Java?

Answer: Java in-built does not support multiple inheritances so in order to overcome this problem we use the interface concept in java. 

46. Name all the types of memory that are allocated by Java Virtual Machine.


  • Class (Method) Area
  • Heap
  • Stack
  • Program counter Register
  • Native Method Stack

47. What is the JIT compiler?

Answer: JIT Just-in-Time compiler is a part of the JRE Java Runtime Environment, and it optimizes the performance of Java-based applications at run time. 

48. Why Java is said to be Platform Independent?

Answer: Java is called platform independent because its bytecode can run on any system irrespective of the underlying operating system. But the necessary condition is the presence of JVM.

49. What makes Java code write once and run anywhere?

Answer: Though Java source code could not run anywhere when the code gets compiled it gets converted into byte code (class file), which is a middle code format between source code and machine code, and this byte code is platform-independent. 

50. What is an abstract class in Java?

Answer: In Java, we can create an Abstract class using the ‘abstract’ keyword before the class name. And an abstract class should have at least one abstract method. 

51. What is Heap Memory?

Answer: Heap memory is a space that is used by java runtime to allocate memory to Objects and JRE classes. Whenever an object is created, it’s always created in the Heap space.

52. What is an abstract method?

Answer: An abstract method is a special method in the abstract class which have the only implantation and does not contain any body declaration. 

53. Does Java have virtual functions?

Answer: Yes, apparently all the Java methods are virtual by default.

54. Does Java provide default values for the local variables?

Answer: No, the coder has to initialize the value explicitly. 

55. What are the static methods and variables?

Answer: To make any variable and method static we use the static keyword and when we make any variable static the value of that variable remains the same for all the methods of the class, it is like that we have fixed that variable value. We commonly use static methods and variables for those classes in which we want, all its objects to share the common variable and method. 

56. What is the difference between an object-oriented programming language and an object-based programming language?

Answer: The Object-oriented programming language support the OOPs concept like Inheritance, polymorphism, etc, whereas the object-based programming language does not have OOP’s concept

In Object-Oriented programming, language objects are not pre-defined but in Object-based programming language objects are pre-defined

Java, C++, and python are examples of Object-oriented programming languages whereas JavaScript and VBScript are Object-Based programming languages.

57. Why the main method is static?

Answer: We do not need an object to call a static method. Though we could make the main() method non-static, here JVM has to create an object to call the main() method that leads to extra memory allocation. 

58. What does this keyword do in Java?

Answer: The keyword this is used to refer to the current of the object of the class can also refer to the current properties of the class such as instances, methods, variables, and constructors. The use of this keyword comes very handily when we create trees algorithm and programs, it is used to separate the parent class from the child class.    

59. Can this keyword refer to the static method?

Answer: Yes, it can but it does not make any difference because the static value remains the same for all the objects. 

60. What are pointers and does Java has pointers?

Answer: A pointer is a user-defined variable that is used to point the memory address of another variable and Java does not pointers.

61. What is a garbage collector?

Answer: In Java, the interpreter takes care of the memory allocation and deallocation of objects at heap memory. When an object is of no use the interpreter deallocates the object with the help of a garbage collector.

62. What are the exceptions?

Answer: An exception is an unwanted error that occurs during the execution of a program. Exception normally occurs during the runtime, and to counter these exceptions we use exception handling.

63. What is Serialization?

Answer: When a file is get converted into a byte stream is known as serialization, the serialization is done for security purposes.

64. Where does the volatile variable store?

Answer: In the main memory

65. What is a final variable in Java?

Answer: Final variables are those variables that once get assigned couldn’t be updated by the user. If there is a final variable that is not assigned yet so the user can only assign it with the help of the class constructor.

66. What do you mean by the final class?

Answer: Once we declare a class final it could not be inherited by any other class.

67. What is dynamic polymorphism?

Answer: A dynamic polymorphism or runtime polymorphism is a process to call the overridden methods at the runtime instead of compile time.

68. What is the difference between static binding and dynamic binding?

Answer: In static binding, the object binds with the method at compile time but in dynamic binding, the object binds with methods at runtime.

69. When is ParseInt() Method used?

Answer: Sometimes in Java, we need to convert a number represented as a string into an integer type. ParseInt() method is used to execute such types of tasks to convert String into Integer.

70. What is the purpose of a Volatile Variable?

Answer: The value of the Volatile variable is are always read from the main memory and not from the thread’s cache memory. This is used mainly during synchronization. It is applicable only for variables.

71. What do you understand by Exception Handling?

Answer: Exception Handling is a mechanism to handle runtime errors. It is done to maintain the normal flow of the application.  

72. Explain enumeration.

Answer: It is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in a collection.

73. What is Applet? Which class does Applet extend?

Answer: An applet is a Java program that runs in the browser. It can be a fully functional Java application as it has the entire Java API. The class which is used for Applet extends is Java. applet.Applet.class.

74. Differentiate between Throw and Throws.


Throw Throws
As per the word itself, the Throw keyword is used to explicitly throw an exception. It is used to declare an exception.
A checked exception cannot be propagated using throw only. A checked exception cannot be propagated using throws.
It is followed by an instance. It is followed by a class.
This is not allowed to throw multiple exceptions. You can declare multiple exceptions using the throws keyword.

75. Explain Garbage Collection in JAVA.

Answer: Java uses garbage collection to free memory. It is done by removing those objects which are not referenced in the program anymore.

76. Explain the Multi-threaded Program.

Answer: A multi-threaded program is a combination of 2-3 parts that can run concurrently. These parts are referred to in the thread. Every thread has its own separate paths.

public class MultipleThreads implements Runnable
public static void main (String[] args)
Runnable r = new runnable ();
Thread t=new thread ();
t.start ();//User thread starts here
Addition add=new addition ();
public void run()
} //User thread ends here

77. Differentiate between Swing and AWT components.


AWT Swing
It is a heavy-weighted component. It contains light-weighted components.
The pluggable look and feel are not supported in AWT. It supports a pluggable look and feel.
AWT programs are not portable. Swing programs are portable.
It is not based on MVC. It follows MVC.
It is an old framework for creating GUIs. It is a new framework for creating GUIs.

78. What is Downcasting?

Answer: When a subclass refers to an object of a parent class then it is known as downcasting.


class Animal { }  
class Dog3 extends Animal
static void method(Animal a)
if(a instanceof Dog3)
Dog3 d=(Dog3)a; //downcasting  
System.out.println("ok downcasting performed");  
public static void main (String [] args) 
Animal a=new Dog3();  

79. What is an Interface?

Answer: An interface is a collection of static constants and abstract methods. The interface is implemented by class thereby inheriting the abstract methods of the interface. Here abstract methods mean only method signature, nobody.

80. Why multiple inheritances are not supported in Java?

Answer: Java does not support multiple inheritances through the class to avoid errors. For multiple inheritances, the interface can be used.  

81. What is Object Cloning?

Answer: Object cloning is a way through which an exact copy of an object can be created. The clone() method of an object class is used to clone an object.

82. Can Private Methods be Overridden?

Answer: A private method can’t be overridden. If you’ll create a similar method with the same return type and same method arguments in child class then it will abstract the superclass method; this is known as method hiding. In the same way, you cannot override a private method in a subclass because it’s not accessible there. What you can do is that you can create another private method with the same name in the child class.

83. What are the use cases? Explain.

Answer: Use cases to describe a situation that a program might encounter and what behavior the program should exhibit in that circumstance. It is a part of the analysis of the program.

84. What is a priority queue?

Answer: Linked list and queue are related to each other as the class has been enhanced to implement the queue interface and Queues can be handled using a linked list. The purpose of a queue is “Priority-in, Priority-out”.

85. What are Ternary Operators? Explain with Example.

Answer: The Java ternary operator functions as a simplified Java if statement. The ternary operator consists of a condition that evaluates to either true or false and one value that is returned if the condition is true and another value is returned when the condition is false.

86. How do you differentiate inner and nested classes?

Answer: When a class is defined within the scope of another class, then it becomes an inner class. If the access modifier of the inner class is static, then it becomes a nested class.

87. What is the difference between Stack and Queue?


Stack Queue
In the stack, objects are inserted and removed from the same end. Objects are inserted and removed from the different ends in the queue.
There is only one pointer used in Stack. It points to the top of the stack. In the queue, two different pointers are used for the front and rear ends.
Stack follows LIFO (Last in First Out) Queue follows FIFO (First In )
Stack operations are called push and pop. Queue operations are called en queue and dequeue.

88. Describe different states of Thread.

Answer: The different states of thread are:

  • New
  • Runnable
  • Running
  • Blocked
  • Terminated

89. Which type of Exceptions is caught at Compile-time?

Answer: If code within a method throws a checked exception, then the method must either handle the exception or the code must specify the exception using the “Throws” keyword. Therefore, these are the Checked exceptions that are checked at compile time.


In the above article, we have provided the top Core Java interview questions and the core Java is also known as basic Java. Most of the questions in the above article are based on the OOP’s concepts because that’s what Java is famous for.

People are also reading:

Leave a Reply

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