50 Java Interview Questions
For Freshers
+91 80099 00785 [email protected] www.grotechminds.com
1.What is Java?
Java is a high-level, object-oriented programming language
developed by Sun Microsystems in 1995. It’s designed to have
minimal implementation dependencies, making it platform-
independent.
2. What is the JDK?
The JDK (Java Development Kit) is a software development
environment used for developing Java applications. It includes
the Java Runtime Environment (JRE), a compiler, and other
development tools.
3. What is the JRE?
The JRE (Java Runtime Environment) is the runtime portion of
Java software, which is all you need to run Java applications but
not to develop them
4. What is the JVM?
The JVM (Java Virtual Machine) is a platform-independent
execution environment that converts Java bytecode into machine
language and executes it.
5. What is bytecode?
Bytecode is the intermediate code generated after the Java
compiler compiles the source code. It is platform-independent
and can be executed by the JVM.
+91 80099 00785 [email protected] www.grotechminds.com
6. What is the difference between JDK, JRE, and JVM?
JDK: For development (contains JRE + tools for development).
JRE: For running Java applications (contains JVM + libraries).
JVM: For executing bytecode (runs Java programs).
7. Is Java platform-independent? Why?
Yes, Java is platform-independent because of its bytecode that
can run on any system that has a JVM, regardless of the
underlying architecture.
8. What is the main feature of the Java language?
The primary feature of Java is platform independence, achieved
through the use of the JVM.
9. What is object-oriented programming (OOP)?
OOP is a programming paradigm that relies on the concept of
classes and objects. Key principles of OOP include encapsulation,
inheritance, polymorphism, and abstraction.
10. What is a class in Java?
A class in Java is a blueprint from which objects are created. It
can contain fields (attributes) and methods (functions) to define
the behavior and state of objects.
11. What is an object in Java?
An object is an instance of a class. It is a real-world entity that
holds state and behavior defined by its class
+91 80099 00785 [email protected] www.grotechminds.com
12. What is encapsulation?
Encapsulation is the wrapping of data (fields) and code (methods)
into a single unit, known as a class, and restricting direct access
to some components.
13. What is inheritance?
Inheritance is a mechanism where one class acquires the
properties (fields and methods) of another class. It helps in code
reusability.
14. What is polymorphism?
Polymorphism is the ability of a method to perform different
functions based on the object that it is acting upon. It allows one
interface to be used for a general class of actions.
15. What is abstraction?
Abstraction is the concept of hiding the internal implementation
of a feature and only exposing the functionality to the user.
16. What is the difference between an interface and an abstract
class?
Interface: Can only have abstract methods and final fields
(Java 8+ allows default and static methods).
Abstract class: Can have both abstract and concrete methods
and can hold state.
+91 80099 00785 [email protected] www.grotechminds.com
17. What is a constructor in Java?
A constructor is a special method used to initialize objects. It is
invoked when an object of a class is created.
18. What is the default constructor?
A default constructor is a constructor provided by Java if no
other constructors are defined in the class. It has no parameters.
19. What is method overloading?
Method overloading is when a class has more than one method
with the same name but different parameter lists (either in
number or type).
20. What is method overriding?
Method overriding occurs when a subclass provides a specific
implementation of a method that is already defined in its
superclass.
21. What is the ‘super’ keyword in Java?
The super keyword refers to the immediate parent class object. It
is used to access parent class methods or constructors.
22. What is a package in Java?
A package is a namespace that organizes classes and interfaces. It
helps to avoid name conflicts and to control access.
23. What is the use of the ‘final’ keyword?
The final keyword can be used with classes, methods, and
variables to indicate that they cannot be modified or extended.
+91 80099 00785 [email protected] www.grotechminds.com
24. What is the static keyword?
The static keyword in Java is used for memory management. It
can be applied to variables, methods, blocks, and nested classes.
Static members belong to the class rather than instances.
25.What is the difference between static and instance
variables?
Static variables are shared among all instances of a class.
Instance variables are unique to each instance of a class.
26. What is the ‘this’ keyword in Java?
The This keyword is used to refer to the current instance of the
class.
27. What is exception handling?
Exception handling in Java is a mechanism to handle runtime
errors, allowing normal flow of the application even after an
error occurs.
28. What is the difference between checked and unchecked
exceptions?
Checked exceptions are checked at compile-time.
Unchecked exceptions are checked at runtime (subclasses of
RuntimeException).
29. What is the try-catch block?
The try block contains code that might throw an exception, while
the catch block handles the exception if it occurs.
+91 80099 00785 [email protected] www.grotechminds.com
30. What is the finally block in Java?
The finally block contains code that is always executed,
regardless of whether an exception is thrown or caught.
31.What is the throw keyword in Java?
The throw keyword is used to explicitly throw an exception.
32. What is the throws keyword?
The throws keyword is used in method signatures to declare that
a method may throw exceptions.
33. What are collections in Java?
The Java Collections Framework provides a set of interfaces and
classes to store and manipulate data in groups
34. What is the difference between an Array and an ArrayList?
Arrays are of fixed size, while ArrayLists are resizable.
Arrays can hold primitive types, whereas ArrayLists hold
objects.
35. What is a HashMap?
A HashMap is a part of the Collections Framework that stores
key-value pairs and provides constant-time performance for
basic operations like getting and putting data.
36. What is the difference between HashMap and Hashtable?
HashMap is non-synchronized and allows null keys/values.
Hashtable is synchronized and doesn’t allow null keys/values.
+91 80099 00785 [email protected] www.grotechminds.com
37. What is the difference between List and Set?
List: An ordered collection that can contain duplicate
elements.
Set: An unordered collection that cannot contain duplicate
elements.
38. What is multithreading?
Multithreading is a Java feature that allows the concurrent
execution of two or more parts of a program for maximum
utilization of CPU.
39. What is the difference between a thread and a process?
A thread is a smaller unit of a process, and multiple threads
can exist within a single process.
A process is an independent program in execution.
40. What is synchronization in Java?
Synchronization is the capability to control the access of multiple
threads to shared resources. It is used to prevent thread
interference and data consistency issues.
41. What is a daemon thread?
A daemon thread is a background thread that runs in the
background to perform tasks such as garbage collection.
42. What is garbage collection in Java?
Garbage collection is the process by which Java programs
automatically manage memory by reclaiming objects that are no
longer in use.
+91 80099 00785 [email protected] www.grotechminds.com
43. What is the difference between ‘==’ and ‘.equals()’ in Java?
== compares references.
.equals() compares values or content.
44. What is the String Pool?
The String Pool is a memory area where Java stores String
literals. Strings with the same content share the same reference
in the pool.
45. What is the difference between String, StringBuilder, and
StringBuffer?
String: Immutable.
StringBuilder: Mutable and not synchronized.
StringBuffer: Mutable and synchronized.
46. What is the purpose of the main() method in Java?
The main() method is the entry point of any Java program. The
JVM invokes this method to start the execution of an application.
47. What are annotations in Java?
Annotations provide metadata about the program to the compiler
and runtime. Examples include @Override, @Deprecated, and
@FunctionalInterface.
48. What is a wrapper class in Java?
A wrapper class provides a way to use primitive data types (int,
char, etc.) as objects. Examples include Integer, Character, and
Boolean.
+91 80099 00785 [email protected] www.grotechminds.com
49. What is the difference between final, finally, and finalize?
final: Used to declare constants, methods that cannot be
overridden, or classes that cannot be inherited.
finally: Used in exception handling to execute code after a
try-catch block.
finalize: A method that the garbage collector calls before an
object is destroyed.
50. What are the access modifiers in Java?
The access modifiers in Java are public, private, protected, and
the default (package-private). They control the visibility and
accessibility of classes, methods, and variables.
+91 80099 00785 [email protected] www.grotechminds.com
FOLLOW FOR MORE
+91 80099 00785 [email protected] www.grotechminds.com