Java Interview Questions for Beginners

Java Interview Questions for Beginners, Questions on Java Environment, Java Language Fundamentals, and Java Object Oriented Programming.

Java FAQ
Java Interview Questions and Answers for Beginners.
1. What is Java Virtual Machine (JVM)?

JVM (Java Virtual Machine) is an abstract computing machine or virtual machine. It is a platform-independent execution environment that converts Java bytecode into machine language and executes it.

Java was developed with the concept of WORA (Write Once Run Anywhere), which runs on a VM. The compiler compiles the Java file into a Java .class file, then that .class file is input into the JVM, which loads and executes the class file.

2. What are JDK and JRE?

JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development environment that is used to develop Java applications and applets. It physically exists. It contains JRE + development tools.

JRE stands for “Java Runtime Environment” and may also be written as “Java RTE.” The Java Runtime Environment provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.

3. What are the different types of memory areas allocated by JVM?

Whenever we execute a Java program, a separate memory area is reserved for storing various parts of our application code which we roughly call JVM memory.

Some of the memory areas allocated by JVM are:

i. ClassLoader
It is a component of JVM used to load class files.

ii. Class (Method) Area
It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods.

iii. Heap
Heap is created a runtime and it contains the runtime data area in which objects are allocated.

iv. Stack
Stack stores local variables and partial results at runtime. It also helps in method invocation and return value. Each thread creates a private JVM stack at the time of thread creation.

v. Program Counter Register
This memory area contains the address of the Java virtual machine instruction that is currently being executed.

vi. Native Method Stack
This area is reserved for all the native methods used in the application.

4. What is JIT compiler?

Just-in-time compilation is a method for improving the performance of interpreted programs. During execution the program may be compiled into native code to improve its performance. It is also known as dynamic compilation.

5. How Java platform is different from other platforms?

Java is the software-based platform (The entire Java development and execution environment) 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.

6. Why people say that Java is ‘write once and run anywhere’ language?

Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. This is all possible because of JVM.

7. How does ClassLoader work in Java?

The Java ClassLoader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. The Java run time system does not need to know about files and file systems because of classloaders.

8.What is ‘main’ method in Java?

In Java, the main method is the entry point Whenever you execute a program in Java JVM searches for the main method and starts executing from it.

To compile a program, you doesn’t really need a main method in your program. But, while execution JVM searches for the main method.

The main method must be public, static, with return type void, and a String array as argument.

public static int main(String[] args){

9. Why Java is not pure Object Oriented Programming Language?

Java is not fully object oriented because it supports primitive data types like int, byte, long, etc., which are not objects.

10. Why Java is platform-independent?

Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system.

11. What are the main principles of Object Oriented Programming?

Fundamental principles of OOP:

i. Encapsulation

We will learn to hide unnecessary details in our classes and provide a clear and simple interface for working with them.

ii. Inheritance

We will explain how class hierarchies improve code readability and enable the reuse of functionality.

iii. Abstraction

We will learn how to work through abstractions: to deal with objects considering their important characteristics and ignore all other details.

iv. Polymorphism

We will explain how to work in the same manner with different objects, which define a specific implementation of some abstract behavior.

12. What is the difference between Object Oriented Programming language and Object Based Programming language?

Object Based languages are different from Object Oriented Languages:

Object Based Languages:

> Object based languages support the usage of object and encapsulation.

> They do not support inheritance or, polymorphism or, both.

> Object based languages do not support built-in objects.

> Javascript, VB are examples of object bases languages.

Object Oriented Languages

> Object Oriented Languages supports all the features of Oops including inheritance and polymorphism.

> They support built-in objects.

> C#, Java, VB. Net are examples of object oriented languages.

13. Why do we need Constructor in Java?

The purpose of Constructor is to initialize the object of a class while the purpose of a method is to perform a task by executing java code.

Constructors cannot be abstract, final, static, and synchronized while methods can be.

Constructors do not have return types while methods do.

14. Can we inherit a Constructor?

Constructor is the special member function of the class but they can’t be inherited.

You can access parent`s class constructor in child class via super keyword.

15. What is the purpose of ‘this’ keyword in java?

Purpose of Java ‘this’ keyword.

‘this’ can be used to refer current class instance variable.
‘this’ can be used to invoke current class method (implicitly)
‘this’ can be used to invoke current class constructor.
‘this’ can be passed as an argument in the method call.

16. Explain the concept of Inheritance?
17. Why Java does not support multiple Inheritance?
18. In OOPS, what is meant by composition?
19. Why there are no pointers in Java?
20. What is the purpose of ‘super’ keyword in java?
21. Is it possible to use this() and super() both in the same constructor?
22. What is the meaning of object cloning in Java?
23. In Java, why do we use static variable?
24. What is the purpose of static method in Java?
25. Why do we mark main method as static in Java?
26. Is it possible to execute a program without defining a main() method?
27. What is the difference between static method and instance method in Java?
28. What is the other name of Method Overloading?
29. How will you implement method overloading in Java?
30. Is it allowed to overload main() method in Java?

Java Quick Tutorial

Follow me on social media: