120+ Core Java Interview Questions and Answers

Core Java Interview Questions and AnswersJava is the most popular computing language for developing web, enterprise, desktop, and Android applications. It follows object-oriented programming (OOP) principles, entailing polymorphism, classes, inheritance, objects, and others. Java also offers open-source libraries such as Apache and Maven. If you want to master this ever-in-demand programming language, it’s essential first to learn Core Java, as Core Java forms the base of Java. It is the reason why most tech recruiters ask Core Java interview questions to test the basic knowledge of Java Developers.
If you are also an aspiring Java developer, you must learn the top Core Java interview questions to clear the interview. To help job applicants prepare for the Java interview, we have prepared a list of the most common Core Java interview questions 2023 that recruiters will likely ask you.

Our extensive list of Core Java interview questions and answers can help you brush up your knowledge of Core Java fundamentals and pave your way through a rewarding career in Java.

Answer:

Java is a programming language and computing platform first released by Sun Microsystems in 1995. It has multiple features, such as platform-independent, multithreaded, portable, & high-performance.

Answer:

JVM or Java Virtual Machine provides a runtime environment to execute Java code or applications. It converts bytecode into machine language. JVM implementation is known as JRE or Java Runtime Environment.

Answer:

  1. JVM: JVM stands for Java Virtual Machine that enables computer systems to run programs. The runtime environment of JVM helps in the execution of Java bytecode. It is platform-dependent; thus, for each hardware & software, we have different JVM configurations. JVM is abstract & doesn’t exist physically.
  2. JRE: JRE stands for Java Runtime Environment. It contains all sets of Libraries that JVM uses at runtime. JRE is imperative to run any Java code. It is platform-dependent & exists physically.
  3. JDK: JDK stands for Java Development Kit that includes development tools like Javadoc, Compiler, & Debugger along with Java Runtime Environment. It is a complete kit for developing any type of Java application. You can run code & execute Java codes & launch your application with JDK.

Answer:

Following are the five different types of memory areas allocated by JVM:

  1. Class (Method) Area: The class method area is the memory block that stores the class code, variable code, method code, and the constructor of a Java program.
  2. Heap: The Heap area is the memory block where objects are created or objects are stored. It is used to allocate memory to objects at run time.
  3. Stack: It is used to store data and partial results which will be needed while returning value for method and performing dynamic linking.
  4. Program Counter Register: It is a register that contains the address of the JVM instruction being executed currently.
  5. Native Method Stack: This memory is allocated for each thread when it’s created And it can be of a fixed or dynamic nature.

Answer:

JIT compiler stands for Just-In-Time compiler. It is a crucial part of the Java Runtime Environment as it is used to improve performance. JIT compiles the code when needed, but not before runtime. Therefore, it reduces the amount of time required for compilation.

Answer:

Platform in Java is a collection of programs that facilitates programmers to efficiently build and run Java applications. It consists of a compiler, an execution engine, & a set of libraries.

Answer:

Below are the key differences between the Java platform & other platforms:

  1. Java is the software-based platform whereas other platforms may be the hardware platforms or software-based platforms.
  2. Java is executed on the top of other hardware platforms whereas other platforms can only have the hardware components.

Answer:

In Java, the programs are compiled & converted to a class file or bytecode, which is interpreted by Java Virtual Machine. Thus, the generated bytecode file can run anywhere or on any JVM.

Answer:

Java ClassLoader is used to load bytecode or class file. When JVM runs a Java program, it is loaded first by the ClassLoader. The ClassLoader class uses a delegation model for searching for resources & classes.

Answer:

It won’t make any difference if you write static public void instead of the public static void as the order of specifiers doesn’t matter & are interchangeable in Java. Moreover, your Java program will run & compile successfully.

Answer:

The local variables have no default values in Java, meaning that they must be declared & assigned an initial value before the first use; else, the compiler will throw an error.

Answer:

Access specifiers are the keywords in Java used to define the variable, class, or method’s access scope. There are four access specifiers in Java, which are as follows:

  1. Public- It attains the highest level of accessibility. Any class, method, or field defined as Public is accessible from any Java program class.
  2. Protected-Fields & methods declared as protected are accessible by the subclasses in other packages or any class within the protected members’ class package.
  3. Private- It obtains the lowest level of accessibility. Any class, field, or method defined as Private is accessible within the same class only.
  4. Default– When no access modifier is specified, all the methods, classes, & fields are of default scope.

Answer:

  1. A Static method in Java belongs to a class & not to an object or instance. It can only access the static data & cannot access non-static data.
  2. A static variable is initialized only one time during the start of the execution. Java variables belong to a class & are initialized first, before the initialization of any instance variables.

Answer:

Following are the advantages of using Java Packages:

  1. Java package is used to categorize the classes and interfaces so that they can be easily maintained.
  2. Java package provides access protection.
  3. Java package removes naming collision.

Answer:

OOP or object-oriented programming is a paradigm that helps to design a program using objects or classes. It streamlines the process of software development.

Answer:

Following are basic differences between object-oriented languages & object-based languages:

  1. An object-oriented language follows all OOP concepts, whereas an object-based language doesn’t follow every OOP concept, such as polymorphism & inheritance.
  2. Object-oriented languages do not have an inbuilt object, whereas Object-based languages do have inbuilt objects like JavaScript has a window object.
  3. Some popular examples of object-oriented programming are C#, Java, & Smalltalk, while the examples of Object-based languages are VBScript, JavaScript, etc.

Answer:

A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created.

Answer:

Default: It is a constructor with no arguments. Default or nullary constructor is generated whenever you don’t declare any constructor in a class; thus, the compiler creates a default one automatically.

Parameterized: A constructor with a specific number of arguments & parameters is known as parameterized constructors.

Answer:

A static method is a method that belongs to a class rather than an instance of a class. This means you can call a static method without creating an object of the class. Static methods are sometimes called class methods.

Answer:

Mainly, two major restrictions are applied to static methods, which are as follows:

  1. The static method cannot directly call the non-static method or utilize a non-static data member.
  2. Also, it cannot use “this and super” keywords in a static context as they are non-static.