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

Top 70 Java Que

The document contains a comprehensive list of the top 70 Java questions covering fundamental concepts such as Java, JVM, JDK, and JRE, as well as advanced topics like design patterns and RESTful web services. It provides concise definitions and explanations for key Java features, data types, object-oriented principles, exception handling, multithreading, and Java frameworks. This resource serves as a valuable reference for individuals preparing for Java-related interviews or seeking to enhance their understanding of the language.

Uploaded by

29ravirajput
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Top 70 Java Que

The document contains a comprehensive list of the top 70 Java questions covering fundamental concepts such as Java, JVM, JDK, and JRE, as well as advanced topics like design patterns and RESTful web services. It provides concise definitions and explanations for key Java features, data types, object-oriented principles, exception handling, multithreading, and Java frameworks. This resource serves as a valuable reference for individuals preparing for Java-related interviews or seeking to enhance their understanding of the language.

Uploaded by

29ravirajput
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Top 70 Java Questions

IT Resources/ mainbhideveloper: Click Here


English Communication/ mainbhiangrez: Click Here
YouTube Channel / Siddharth Vaidya: Click Here

1. What is Java?
- Java is a high-level, class-based, object-oriented programming language designed to have
as few
implementation dependencies as possible. It's platform-independent and follows the
principle of
"Write Once, Run Anywhere."

2. What are the main features of Java?


- Object-Oriented, Platform-Independent, Secure, Multithreaded, Portable, Robust, Dynamic.

3. What is a JVM?
- JVM (Java Virtual Machine) is the engine that provides a runtime environment to execute
Java
bytecode. It makes Java platform-independent by providing a layer of abstraction.

4. What is JDK?
- JDK (Java Development Kit) is a software development environment used for developing
Java
applications and applets. It includes JRE, an interpreter/loader, a compiler (javac), an
archiver (jar),
and documentation tools.

5. What is JRE?
- JRE (Java Runtime Environment) is the part of the JDK that contains everything needed to
run Java
applications, including the JVM, core libraries, and supporting files.
Top 70 Java Questions
6. What is the difference between JDK, JRE, and JVM?
- JDK is a development environment; JRE is the runtime environment, and JVM is the
machine that
runs the bytecode.

7. What are primitive data types in Java?


- byte, short, int, long, float, double, char, boolean.

8. What is a class?
- A class is a blueprint for creating objects. It contains fields (attributes) and methods
(functions).

9. What is an object?
- An object is an instance of a class. It contains both state (attributes) and behavior
(methods).

10. What is inheritance?


- Inheritance is a mechanism where one class acquires the properties and behaviors of
another
class.

11. What is encapsulation?


- Encapsulation is the wrapping of data (variables) and methods into a single unit or class,
restricting direct access to some of the object’s components.
Top 70 Java Questions
12. What is polymorphism?
- Polymorphism allows objects to be treated as instances of their parent class. It allows one
interface to be used for a general class of actions.

13. What is method overloading?


- Method overloading is when a class has more than one method with the same name but
different parameters.

14. What is method overriding?


- Method overriding occurs when a subclass provides a specific implementation for a
method that
is already defined in its parent class.

15. What is an interface?


- An interface is a reference type in Java that can contain only constants, method signatures,
default methods, and nested types.

16. What is an abstract class?


- An abstract class is a class that cannot be instantiated, and it can have abstract methods
(methods without a body) and concrete methods (methods with a body).

17. What is the difference between abstract class and interface?


- Abstract classes can have constructors, state, and non-abstract methods, while interfaces
can
only contain abstract methods (before Java 8).
Top 70 Java Questions
18. What is a constructor?
- A constructor is a block of code that initializes a newly created object.

19. What is the default constructor?


- If no constructor is defined in a class, the Java compiler creates a default constructor.

20. What is a static keyword?


- Static is used for memory management, and it can be applied to variables, methods,
blocks, and
nested classes.

21. What is a final keyword?


- The `final` keyword can be used with classes, methods, and variables to restrict their
modification.

22. What is the ‘this’ keyword in Java?


- The `this` keyword refers to the current object in a method or constructor.

23. What is the difference between StringBuffer and String?


- String is immutable, while StringBuffer is mutable.

24. What is a package?


- A package in Java is a namespace that organizes a set of related classes and interfaces.

25. What is garbage collection in Java?


- Garbage collection is the process of automatically freeing memory by deleting objects that
are no longer referenced.
Top 70 Java Questions
Intermediate Java Questions

26. What are checked and unchecked exceptions?


- Checked exceptions are those that are checked at compile-time, while unchecked
exceptions are
checked at runtime.

27. What is a try-catch block?


- A try-catch block is used for exception handling in Java. The code that might throw an
exception is
placed inside the try block, and the exception is handled in the catch block.

28. What is a finally block?


- A finally block contains code that will be executed after the try-catch block, regardless of
whether
an exception occurs.

29. What is a throw and throws keyword?


- `throw` is used to explicitly throw an exception, and `throws` is used in method
declarations to
indicate that a method can throw an exception.

30. What is multithreading in Java?


- Multithreading is the concurrent execution of two or more threads to maximize the
utilization of
the CPU.

31. How can you create a thread in Java?


- By extending the `Thread` class or by implementing the `Runnable` interface.
Top 70 Java Questions
32. What is synchronization in Java?
- Synchronization in Java is used to control the access of multiple threads to any shared
resource.

33. What are Java collections?


- The Java Collections Framework provides a set of classes and interfaces to store and
manipulate
groups of objects.

34. What is the difference between List and Set?


- List allows duplicate elements, while Set does not allow duplicates.

35. What is a HashMap?


- HashMap is a collection class that stores data in key-value pairs and allows null values.

36. What is the difference between HashMap and Hashtable?


- HashMap is unsynchronized and allows null values, while Hashtable is synchronized and
does not
allow null values.

37. What is an Iterator?


- An Iterator is an interface that provides methods to iterate over elements in a collection.

38. What is the difference between Iterator and ListIterator?


- ListIterator can traverse the elements in both forward and backward directions, while
Iterator can
only traverse in one direction.
Top 70 Java Questions
39. What is the difference between ArrayList and LinkedList?
- ArrayList is based on dynamic arrays, while LinkedList is based on doubly-linked lists.

40. What is the difference between fail-fast and fail-safe iterators?


- Fail-fast iterators throw a `ConcurrentModificationException` if the collection is modified
while
iterating, while fail-safe iterators do not.

41. What is serialization?


- Serialization is the process of converting an object into a byte stream.

42. What is transient keyword?


- Transient is a keyword used in serialization. If a field is transient, it will not be serialized.

43. What are generics in Java?


- Generics provide a way to parameterize classes and methods with types.

44. What is a lambda expression?


- Lambda expressions provide a clear and concise way to represent a method interface using
an
expression.

45. What are streams in Java?


- Streams represent sequences of data and provide a functional approach to processing
collections of objects.

46. What is Optional in Java?


- Optional is a container object used to contain not-null objects and avoid
`NullPointerException`.
Top 70 Java Questions
47. What is functional programming in Java?
- Functional programming treats functions as first-class citizens and supports immutability
and
higher-order functions.

48. What is method reference in Java?


- Method reference is a shorthand notation of a lambda expression to call a method directly.

49. What is a CompletableFuture?


- CompletableFuture is used to perform asynchronous tasks in Java, providing the ability to
run
tasks in parallel and combine their results.

50. What is the difference between process and thread?


- A process is an independent unit of execution, while a thread is a smaller execution unit
that runs
within a process.

Advanced Java Questions

51. What is the Java Memory Model?


- The Java Memory Model defines how threads interact through memory and what
behaviors are
allowed in concurrent programs.

52. What is volatile keyword in Java?


- The volatile keyword guarantees visibility of changes to variables across threads.
Top 70 Java Questions
53. What is the difference between wait() and sleep()?
- `wait()` releases the lock on an object, while `sleep()` keeps the lock.

54. What is deadlock?


- Deadlock is a situation where two or more threads are blocked forever, waiting for each
other to
release resources.

55. What are design patterns?


- Design patterns are typical solutions to common problems in software design.

56. What is Singleton design pattern?


- The Singleton pattern ensures that only one instance of a class is created.

57. What is Factory design pattern?


- The Factory pattern provides an interface for creating objects but lets subclasses alter the
type of
objects that will be created.

58. What is Dependency Injection?


- Dependency Injection is a design pattern used to implement inversion of control, allowing
dependencies to be injected into a class, instead of being instantiated by the class itself.

59. What is RESTful Web Services?


- RESTful web services use HTTP methods like GET, POST, PUT, DELETE to perform CRUD
operations
on resources.

60. What is Spring Framework?


Top 70 Java Questions
- Spring is a comprehensive framework for building enterprise applications in Java. It
supports
dependency injection and simplifies various aspects of Java development.

61. What is Hibernate?


- Hibernate is an ORM (Object Relational Mapping) tool for mapping Java classes to database
tables.

62. What is the difference between JDBC and Hibernate?


- JDBC is a low-level database API, while Hibernate is a high-level ORM framework that
automates
data mapping between relational databases and Java objects.

63. What are microservices?


- Microservices are an architectural style that structures an application as a collection of
small,
autonomous services modeled around a business domain.

64. What is the purpose of annotations in Java?


- Annotations are metadata that provide data about a program but are not part of the
program
itself.

65. What is the difference between equals() and hashCode()?


- The `equals()` method checks for logical equality between objects, while `hashCode()`
returns an
integer that represents the object’s memory address.

66. What are default methods in interfaces?


- Default methods in interfaces allow the interface to provide a default implementation for a
method.
Top 70 Java Questions
67. What is the diamond problem in Java?
- The diamond problem occurs when a class inherits from multiple classes that have
methods with
the same signature. Java solves this problem with interfaces and default methods.

68. What is the difference between == and equals()?


- `==` checks for reference equality, while `equals()` checks for value equality.

69. What is the Executor framework?


- The Executor framework provides a higher-level replacement for working with threads
directly,
offering mechanisms for managing a pool of threads.

70. What is a ConcurrentHashMap?


- ConcurrentHashMap is a thread-safe variant of HashMap, which allows concurrent access
without locking the entire map.

You might also like