0% found this document useful (0 votes)
4 views

java ques

The document provides a comprehensive list of Java interview questions and answers, covering fundamental concepts such as Java's features, differences between JDK, JRE, and JVM, and key programming principles like inheritance, polymorphism, and exception handling. It also explains various data structures, access modifiers, and the use of Lambda expressions. Overall, it serves as a useful resource for preparing for Java-related interviews.

Uploaded by

syahirah.work61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

java ques

The document provides a comprehensive list of Java interview questions and answers, covering fundamental concepts such as Java's features, differences between JDK, JRE, and JVM, and key programming principles like inheritance, polymorphism, and exception handling. It also explains various data structures, access modifiers, and the use of Lambda expressions. Overall, it serves as a useful resource for preparing for Java-related interviews.

Uploaded by

syahirah.work61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

JAVA INTERVIEW

QUESTIONS AND
ANSWERS

What is Java
Java is a high-level object-
oriented programming language
that is platform-independent
and can be used to create
software applications that can
run on any system with the Java
Virtual Machine (JVM)

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What are the features


of Java
Java is an object-oriented
language with features such as
platform independence
automatic memory
management multithreading
exception handling and robust
security.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between JDK JRE and
JVM
JDK stands for Java
Development Kit JRE stands for
Java Runtime Environment and
JVM stands for Java Virtual
Machine. JDK is used for
developing Java applications JRE
is used for running Java
applications and JVM is used for
executing Java bytecode.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between abstract class
and interface
An abstract class can have both
abstract and non-abstract
methods while an interface can
only have abstract methods. An
abstract class can have instance
variables while an interface can
only have constant variables.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a constructor
in Java
A constructor is a special
method in Java that is used to
initialize the object of a class. It
has the same name as the class
and does not have a return type.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between method
overloading and
method overriding
Method overloading is when a
class has multiple methods with
the same name but different
parameters while method
overriding is when a subclass
provides a specific
implementation of a method
that is already defined in its
superclass.
AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the final


keyword in Java
The final keyword is used to
declare a constant variable a
method that cannot be
overridden or a class that cannot
be extended.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between static and
non-static methods
Static methods can be called
without creating an instance of
the class while non-static
methods can only be called on
an object of the class.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a package in
Java
A package is a collection of
related classes and interfaces
that provide a namespace for
the classes and interfaces.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a thread in
Java
A thread is a lightweight process
that can execute independently
of the main program flow.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the
synchronized keyword
in Java
The synchronized keyword is
used to provide thread safety by
ensuring that only one thread
can access a block of code at a
time.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between ArrayList and
LinkedList
ArrayList is implemented as an
array while LinkedList is
implemented as a doubly-linked
list. ArrayList provides faster
access to elements while
LinkedList provides faster
insertion and deletion.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between HashMap and
Hashtable
HashMap is not synchronized
and allows null values while
Hashtable is synchronized and
does not allow null values.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between the equals()
method and the ==
operator
The equals() method is used to
compare the values of two
objects while the == operator is
used to compare the memory
addresses of two objects.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a garbage
collector in Java
A garbage collector is a feature
in Java that automatically frees
up memory by removing objects
that are no longer needed by the
program.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between public private
and protected access
modifiers
Public access modifier allows
access to a method or variable
from anywhere private access
modifier restricts access to only
within the class and protected
access modifier allows access
within the class and its
subclasses.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between the
StringBuilder and
StringBuffer classes
The StringBuilder class is not
synchronized while the
StringBuffer class is
synchronized.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a try-catch
block in Java
A try-catch block is used for
exception handling in Java. The
try block contains the code that
might throw an exception and
the catch block handles the
exception.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is polymorphism
in Java
Polymorphism is the ability of an
object to take on many forms. In
Java this is achieved through
method overloading and method
overriding.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is inheritance
inJava
Inheritance is a mechanism in
Java where a subclass inherits
the properties and methods of its
superclass. This allows for code
reuse and the creation of more
specialized classes.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is an abstract
method in Java
An abstract method is a method
that does not have an
implementation. It is defined in
an abstract class or interface
and must be implemented by
any subclass or class that
implements the interface.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a static block


in Java
A static block is a block of code
that is executed when a class is
loaded into memory. It is used for
initialization and cannot be
called directly.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between checked and
unchecked exceptions
in Java
Checked exceptions are checked
at compile time and must be
handled by the programmer
while unchecked exceptions are
not checked at compile time and
do not need to be handled.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between a stack and a
queue in Java
A stack is a last-in first-out (LIFO)
data structure while a queue is a
first-in first-out (FIFO) data
structure.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is the difference


between a constructor
and a method in Java
A constructor is a special
method that is used to create an
object of a class while a method
is a block of code that performs
a specific task.

AMIGOSCODE.COM
JAVA INTERVIEW
QUESTIONS AND
ANSWERS

What is a Lambda
expression in Java
A Lambda expression is a new
feature in Java that allows for the
creation of anonymous
functions. It simplifies the syntax
of functional programming in
Java.

AMIGOSCODE.COM

You might also like