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

Java Interview Questions

The document contains a list of 50 Java interview questions covering topics like OOP concepts, inheritance, packages, exceptions, multithreading, JDBC, lambda expressions, and more.

Uploaded by

G S SAINIKHIL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Java Interview Questions

The document contains a list of 50 Java interview questions covering topics like OOP concepts, inheritance, packages, exceptions, multithreading, JDBC, lambda expressions, and more.

Uploaded by

G S SAINIKHIL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Java Interview

Questions
Made by: Want More?

Join Telegram
DEVELOPERS
Tap here
<SOCIETY/> or Search on Telegram

1. What is inheritance?
Inheritance is a mechanism where one class acquires the
properties (fields) and behaviors (methods) of another
class. It provides code reusability and method overriding.

2. What are the main features of Java?


Object-Oriented, Platform-Independent, Secure, Robust,
Multithreaded, Architecture Neutral, Portable, High
Performance, Distributed, Dynamic.

3. What is a constructor in Java?


A constructor is a block of code used to initialize an object.
It is called when an instance of a class is created.
Constructors have the same name as the class and do not
have a return type.

4. What is a Java package and which package is imported by


default?

DEVELOPERS
A package is a namespace that organizes a set of related
classes and interfaces. The java.lang package is imported
by default.

5. What is the difference between == and .equals() in Java?

<SOCIETY/>
== checks for reference equality, whereas .equals() checks
for value equality.
6. What is a static method?
A static method belongs to the class rather than an
instance of the class. It can be called without creating an
object of the class.

7. Explain the concept of garbage collection in Java.


Garbage collection is the process by which Java programs
perform automatic memory management by reclaiming
memory occupied by objects that are no longer in use.

8. What is the use of the final keyword in Java?


final can be used with variables to make them constants,
with methods to prevent overriding, and with classes to
prevent inheritance.

9. What is multithreading and how is it achieved in Java?


Multithreading is the capability to run multiple threads
concurrently. In Java, it is achieved by extending the
Thread class or implementing the Runnable interface.

10. What are access modifiers in Java?


Access modifiers define the scope of a class, method, or
variable. They are public, protected, default (package-
private), and private.

DEVELOPERS
11. What is the difference between StringBuilder and
StringBuffer?
Both are used for creating mutable strings. StringBuilder
is not synchronized and is faster, whereas StringBuffer is

<SOCIETY/>
synchronized and thread-safe.

12. What is the purpose of the this keyword in Java?


this is used to refer to the current instance of a class.

13. What is the difference between ArrayList and LinkedList?


ArrayList is based on a dynamic array and allows fast
random access but slow insertion/deletion, while
LinkedList is based on a doubly-linked list, allowing fast
insertion/deletion but slow random access.
14. Explain the concept of exception handling in Java.
Exception handling in Java is a mechanism to
handle runtime errors, allowing the normal flow of
the application to be maintained. It uses try, catch,
finally, throw, and throws keywords.

15.What are the different types of exceptions in Java?


Checked exceptions (compile-time) and unchecked
exceptions (runtime). Examples: IOException (checked),
NullPointerException (unchecked)

16. What is a Java interface?


An interface in Java is a reference type, similar to a
class, that can contain only constants, method
signatures, default methods, static methods, and
nested types. Interfaces cannot have instance fields.

17. What is a transient keyword?


transient is used to indicate that a field should not
be serialized.

18. What is the difference between == operator and instance


of operator?

DEVELOPERS
== checks if two references point to the same
object. instanceof checks if an object is an instance
of a specific class or subclass.

19. What is a volatile keyword?

<SOCIETY/>
volatile is used to indicate that a variable's value will be
modified by different threads

20. Explain the concept of synchronized keyword in Java.


synchronized is used to control access to a method
or block by multiple threads to prevent thread
interference and memory consistency errors.
21. What is the use of super keyword in Java?
super is used to refer to the immediate parent class
object. It can be used to call parent class methods
and constructors.

22. What is polymorphism in Java?


Polymorphism is the ability of a method to do different
things based on the object it is acting upon. It is achieved
through method overriding (runtime polymorphism) and
method overloading (compile-time polymorphism).

23. What is encapsulation?


Encapsulation is the wrapping of data (variables)
and code (methods) together as a single unit, often
with the data being hidden from outside access
through access modifiers.

24. What are wrapper classes in Java?


Wrapper classes are used to convert primitive data types
into objects. Examples include Integer, Double, Boolean.

25. What is a nested class?


A nested class is a class that is defined within
another class. Types include static nested class,
inner class, local class, and anonymous class.

DEVELOPERS
26. What is the difference between wait() and sleep()
methods in Java?
wait() is used for thread communication and releases the
lock on the object, while sleep() is used to pause the

<SOCIETY/>
thread for a specified period without releasing the lock.

27. What is an enumeration (enum) in Java?


enum is a special Java type used to define
collections of constants.

28. What is the purpose of finalize() method?


finalize() is a method called by the garbage collector
on an object when garbage collection determines that
there are no more references to the object.
29. What is a marker interface?
A marker interface is an interface with no methods
or fields, used to indicate a specific behavior.
Examples include Serializable, Cloneable.

30. What is the difference between abstract class and


concrete class?
An abstract class cannot be instantiated and can have
abstract methods. A concrete class is a regular class that
can be instantiated and has complete implementation.

31. What are the main principles of OOP?


Encapsulation, Inheritance, Polymorphism, Abstraction.

32. What is the purpose of toString() method in Java?


toString() provides a string representation of an object.
It is often overridden to provide meaningful output.

33. What is JDBC?


Java Database Connectivity (JDBC) is an API for
connecting and executing queries in the database.

34. What is a lambda expression?


A lambda expression is a short block of code which takes
in parameters and returns a value. Lambda expressions
are similar to methods but do not need a name and can be

DEVELOPERS
implemented right in the body of a method.

35.What is the default value of an instance variable?


The default values for instance variables are 0 for numeric
types, false for boolean, \u0000 for char, and null for

<SOCIETY/>
reference types.

36. What is a functional interface?


A functional interface is an interface with only one
abstract method. Examples include Runnable,
Callable, Comparator.

37. What is the purpose of instanceof keyword?


instanceof is used to test whether the object is an
instance of the specified type (class or subclass).
38. What is a singleton class?
A singleton class is a class that can have only one
object (instance of the class) at a time.

39.What is reflection in Java?


Reflection is a feature that allows inspection and
modification of the program structure at runtime.

40.What is the difference between process and thread?


A process is an independent executing program with
its own memory space, while a thread is a subset of
a process, sharing the process's resources but
running independently.

41. What is a servlet in Java?


A servlet is a Java class that runs on a server and
handles HTTP requests and responses.

42. What is a spring framework?


Spring is a comprehensive framework for enterprise
Java development, providing infrastructure support
for developing robust Java applications.

43. What is Hibernate in Java?


Hibernate is an ORM (Object-Relational Mapping) tool

DEVELOPERS
for Java, providing a framework for mapping an object-
oriented domain model to a relational database.

44. What is the hashCode() method?

<SOCIETY/>
hashCode() returns an integer value, generated by a
hashing algorithm. It is used for hashing in data
structures like HashMap.

45. What is the equals() method?


equals() is used to compare the content of two objects.

46. What is the use of transient keyword in Java?


The transient keyword is used to indicate that a field
should not be serialized.
47. What is the difference between throw and throws in Java?

throw: Used to explicitly throw an exception from a method


or any block of code.

throws: Used in method signature to declare that a method


can throw one or more exceptions.

48. What is the purpose of try-with-resources in Java?


try-with-resources is a try statement that declares
one or more resources, ensuring that each resource
is closed at the end of the statement. It is used for
automatic resource management (ARM).

49.What is Java Stream API and why is it used?

Java Stream API is used to process sequences of


elements such as collections in a functional style. It
is part of the java.util.stream package and provides
operations like filter, map, and reduce.

50. What is a daemon thread in Java?


A daemon thread is a background thread that does

DEVELOPERS
not prevent the JVM from exiting when the program
finishes but still runs. Daemon threads are used for
background supporting tasks.

<SOCIETY/>
More E-Books Coming soon!
Join our Community to Stay Updated

Follow us on Instagram
@Developers_Society
Tap here to follow

Join Join
WhatsApp Group Telegram Channel
FOR DAILY UPDATES EXCLUSIVE CONTENT

TAP ON THE ICONS TO JOIN!

You might also like