Java interview questions ✅
Java interview questions ✅
Interview Questions
Q 1. What is Java?
Ans: Java is a high-level, object-oriented
programming language developed by Sun
Microsystems that enables the development of
platform-independent applications.
01
Q 4. What are the different components of the
Java platform?
Ans: It is a field (or collection of fields) in one table, that
refers to the PRIMARY KEY in another table
02
Q 6. Check if a number is Prime
Ans:
03
Q 8. Why java is platform independent?
Ans: Java's most unique feature is its platform
independence. Unlike other languages that
compile source code into platform-specific
executables, Java compiles code into .class files
containing bytecode. This bytecode is
interpreted by the Java Virtual Machine (JVM),
which is available on all major platforms. As a
result, Java code compiled on Windows can run
on Linux or any other platform with a JVM.
Java is platform
C++ is platform dependent.
independent
Does’nt support
Supports multithreading
multithreading
04
Q 10. What is bytecode in java ?
Ans: When a javac compiler compiler compiles a class
it generates .class file. This .class file contains set of
instructions called byte code. Byte code is a
machine independent language and contains set
of instructions which are to be executed only by
JVM. JVM can understand this byte codes.
05
Q 12. What is JIT compiler ?
Ans: Java JIT compiler or Just-In-Time compiler is one
of the key parts of Java Runtime Environment (JRE).
Its role is the compilation of bytecode to native
machine code when it's in runtime. As a result, the
overall performance of the Java apps is optimized.
06
Q 13. Difference between overriding and
overloading in java?
Ans: Overriding:
Overriding occurs when a subclass provides a
specific implementation of a method that is
already defined in its superclass. The method in
the subclass must have the same name, return
type, and parameters as the method in the
superclass. It is used to achieve runtime
polymorphism.
Overloading:
Overloading happens when multiple methods in
the same class have the same name but different
parameter lists (different type or number of
parameters). It is used to increase the readability
of the program and is resolved at compile time.
07
Q 14. What is multithreading in Java?
Ans: Multithreading is a process in which a Java
program is divided into multiple smaller parts
called threads. These threads run parallelly and
simultaneously, allowing tasks to be performed
concurrently. The main purpose of multithreading
in Java is to create lightweight threads that share
the same memory space, enabling better use of
the system's processing power and improving the
performance of applications.
08
Q 16. What is Java enum?
Ans: An enum (short for enumeration) in Java is a
special data type that represents a group of
named constant values. It was introduced in Java 5
to provide a type-safe way to define and use
constants. Enums are declared using the enum
keyword, and the constant values are separated by
commas.
09
Q 18. How Lambda expressions and functional
interface are interrelated?
Ans: We can call the functional interface a large platform
that comes with numerous expressions. The lambda
expressions are one such part of this interface. This
is the interrelation between the two.
Q 19. What are the roles of final, finally, and
finalize keywords in Java?
Ans:
10
Q 21. What is inheritance in Java?
Ans: Inheritance is a mechanism where a child class
inherits properties and methods from a parent
class using the extends keyword.
It promotes code reuse.
11
Q 23. What is encapsulation?
Ans: Encapsulation is the process of wrapping data
and code together into a single unit (class).
12
Q 26. Can Java support multiple inheritance?
Ans: Java does not support multiple inheritance with
classes to avoid ambiguity.
13
Q 28. Can we write any code after throw
statement?
Ans: After throw statement jvm stop execution and
subsequent statements are not executed. If we
try to write any statement after throw we do
get compile time error saying unreachable
code.
Q 29. Can we nested try statements in java?
Ans: Yes try statements can be nested. We can declare
try statements inside the block of another try
statement.
14
Q 32. What is an object?
Ans: An object in Java is a runtime instance of a class
that encapsulates state and behavior. It
represents a real-world entity and serves as the
fundamental building block of object-oriented
programming.
15
Q 35. what will happen when a constructor is
declared as protected?
Ans: When a constructor is protected, it can be
accessed only within the same package or by
subclasses (even if they are in different
packages).
It restricts object creation from other classes.
Q 36. What is the static method?
16
Q 37. Why is the main method static?
Ans: 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
17
Q 39. Which class is the superclass for all the
classes?
Ans: The object class is the superclass of all other
classes in Java.
18
Our students have gone on to work at renowned companies,
innovative startups, and leading unicorns.
Crack Project
Top Job
MNC’s Updates
Courses Blogs
E - Books
www.thelearnnova.com Follow us -