15 Java Common Questions and Answers for Fresher

Java programming language

Java is one of the most popular programming language in the world of technology and a general-purpose programming language which is class-based. Java’s syntax is similar to C++ and C.

According to the GitHub report 2019, Java is most popular programming language especially for client-server web applications. Java is used by 9 million developers and it is running on 7 billion devices worldwide.

Join the Core Java course in Kolkata.

In this article, we will see some common questions asked in Java interview.

1) Differentiate between Java and C++.

i) The first difference between Java and C++ is that Java is a platform independent whereas C++ is platform dependent.

ii) To create documentation for Java code, Java supports documentation comment (/**…*/) and documentation comment in C++ is not supported.

iii) Multiple inheritance is not supported in Java but in C++ multiple inheritance is supported.

iv) There is no concept of pointers in Java whereas pointers in C++ is fully supported.

v) Java is mostly used for application programming such as enterprise and mobile applications, window and web based. C++ is mostly used for system programming.

2) Mention features of Java.

Some of the important Java features are as follows:

i) Simple: The syntax of Java is easy and easy to learn.

ii) Portable: Java facilitates to carry the Java bytecode to any platform which makes Java portable.

iii) Object-oriented: In Java, everything is an object which means that software are organized as a combination of different types of object which includes behavior and data also. Therefore, it is an object-oriented programming language.

iv) Secured: With Java, virus-free systems is developed and there are much secured because there is no explicit pointer and the programs of Java run inside a virtual machine sandbox. Some other securities provided by Java is Classloader, Security Manager and Bytecode verifier.

v) Platform Independent: Java is ‘write once and run anywhere’ language which makes this language a platform independent.

3) What are basic concepts of OOPs?

In Java, basic concept of OOPs are as follows:

i) Object

ii) Class

iii) Abstraction

iv) Inheritance

v) Encapsulation

vi) Polymorphism

4) In Java, what are the various access specifiers?

The keywords that are used to describe the access scope of the method, variable or class in known as access specifiers. There are four access specifiers which are as follows:

i) Public: It is defined as classes, variables or methods and any class or method can be accessed.

ii) Protected: It can be accessed within the class, by the sub-class of this class or by the class of the same package.

iii) Private: Private is defined as private class, variables or methods which can be accessed within the class only.

iv) Default: By default, all the classes, variables and methods are of default scope and it is accessible within the package only.

5) Differentiate between Java methods and Java constructors.

The differences between methods and constructor are as follows:

a) To expose the behavior of an object, method is used whereas to initialize the state of an object, constructor is used.

b) Java method is invoked explicitly whereas constructor is invoked implicitly.

c) The method name may or may not be similar as class name but in constructor, the constructor name must be similar to the class name.

d) There must be a return type in method and constructor should not have a return type.

e) By the compiler, method is not provided in any case. But in constructor, a default constructor is provided by the compiler if it doesn’t have in a class.

6) Differentiate between float and double variables.

In Java, float variable takes 4 bytes in memory and it is single precision floating point decimal number. Double variables takes 8 bytes in memory and it is double precision decimal number.

7) What is the static method?

In Java, static method can access and modify the value of a static variable and this method belongs to the class rather than the object. To call the static methods, there is no requirement to create the object.

Connect to the advanced Java training institute in Kolkata to become a Java expert.

8) Tell us about JVM, JRE and JDK.

JVM means Java Virtual Machine and it follows three notations which are Specification, Runtime Instance and Implementation. JVM is an abstract machine and it is a specification which provides a run-time environment in which bytecode of Java can be carried out.

JRE means Java Runtime Environment and it’s a JVM implementation which physically exists. It refers to a runtime environment in which bytecode of Java can be carried out.

JDK means Java Development Kit and contains JRE+ development tools. JDK is the tool which necessary to compile, document and package Java programs.

9) Is Java 100% object-oriented?

Not at all, Java is not fully object-oriented because eight primitive data types is used which are not objects such as Boolean, byte, int, long, short, float, double and char.

10) Explain the JVM (Java Virtual Machine) architecture.

Java Virtual Machine or JVM consists key components which are as follows:

a) Classloader: The subsystem of JVM which load class files is the classloader and it is loaded by the classloader whenever a Java program is run.

b) Class Area: Class level data of each class file such as metadata, static variables and constant run pool are held by class area.

c) Heap: Heap is the runtime data that is used for objects allocation.

d) Registers: It contains the address of JVM instruction which is currently being carried out. Each thread has its separate register.

e) Native Method stacks: The instruction of native code depends on the native library is held by Native method stacks and instead of Java, it is written in another language.

f) Execution Engine: It is a sort of software which is used to test software, hardware or complete systems and any information about the tested product is never carried by the test execution engine. It contains a virtual processor.

11) In Java, can goto be used to go to a particular line?

The feature of going to a particular labeled line is not supported by Java and there is no goto keyword.

12) Can a dead thread be started again?

No, a thread which is in dead state cannot be started again and there is no solution to restart a dead thread.

13) Tell us the output of Round(3.7) and Ceil(3.7).

Round(3.7) returns 4 and Ceil(3.7) returns 4.

14) In Java, can a class be inherited from more than one class?

No, a class cannot be inherited from more than one class because multiple inheritance is not supported. A class can be derived from one class only.

15) In order to run any Java programs, what are the two environment variables that must be set?

To run any Java programs the two environment variable which much be set are as follows:

a) Path variable

b) CLASSPATH variable.


We have seen these were some common asked in a Java interview. All the questions mentioned above will help the candidate to prepare for the interview. There are many institutes which provides advanced Java course in Kolkata but the best Java training institute in Kolkata prepares their students for the interview also.