0% found this document useful (0 votes)
8 views5 pages

Most Important Java Questions With Answers

Uploaded by

Vijay Kumar
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)
8 views5 pages

Most Important Java Questions With Answers

Uploaded by

Vijay Kumar
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/ 5

MOST IMPORTANT JAVA Q&A

INSTRUCTOR: SHALINI RAVI

1. What is Java?
Java is a high-level, object-oriented programming language that is platform-
independent due to the Java Virtual Machine (JVM).
2. What is the JVM?
JVM runs Java bytecode and enables Java to be platform-independent.
3. What is the JRE?
Java Runtime Environment contains the JVM and libraries needed to run Java
applications.
4. What is the JDK?
Java Development Kit includes JRE plus development tools like a compiler and
debugger.
5. What is bytecode?
Bytecode is intermediate code generated by the compiler and executed by the
JVM.
6. Why is Java platform-independent?
Because Java bytecode can run on any device that has a JVM.
7. What are the main features of Java?
Simple, object-oriented, platform-independent, secure, robust, multithreaded, and
high performance.
8. What is the difference between JDK, JRE, and JVM?
JDK = JRE + development tools. JRE = JVM + libraries. JVM runs the bytecode.

1
9. What is a class in Java?
A class is a blueprint for creating objects; it defines fields and methods.
10. What is an object in Java?
An object is an instance of a class created using the new keyword.
11. What is a constructor in Java?
A constructor is used to initialize objects and has the same name as the class.
12. What is method overloading?
Defining multiple methods with the same name but different parameters.
13. What is method overriding?
Providing a specific implementation of a method already defined in the superclass.
14. What is inheritance?
Inheritance allows one class to acquire the properties and behaviors of another
class.
15. What is polymorphism?
The ability of a method or object to take many forms, through overloading or
overriding.
16. What is abstraction?
Abstraction hides complex implementation details and shows only necessary
features.
17. What is encapsulation?
Encapsulation binds data and code together and restricts access using access
modifiers.
18. What are access modifiers in Java?
They define access levels: public, private, protected, and default (no
modifier).
19. What is the difference between == and equals()?
== compares object references; .equals() compares object content.
20. What is a static variable?
A variable shared among all instances of a class.

2
21. What is the final keyword?
It is used to declare constants, prevent method overriding, or prevent inheritance.
22. What is the difference between an abstract class and an interface?
Abstract class can have method bodies; interface (before Java 8) only has method
signatures.
23. What is a package?
A package is a namespace used to group related classes and interfaces.
24. What is the default value of a boolean variable?
False.
25. Can the main() method be overloaded?
Yes, but only the one with String[] args is used by JVM to start the
program.
26. What is a String in Java?
A sequence of characters, implemented as an immutable object.
27. Difference between String, StringBuffer, and StringBuilder?
String is immutable. StringBuffer is mutable and thread-safe. StringBuilder is
mutable and faster but not thread-safe.
28. What are wrapper classes?
Classes that convert primitive types into objects, like int to Integer.
29. What is autoboxing and unboxing?
Automatic conversion between primitive types and their wrapper classes.
30. Difference between Array and ArrayList?
Array is fixed in size. ArrayList is dynamic and part of the Collections framework.
31. What is the Collection Framework?
A set of classes and interfaces for storing and manipulating groups of data.
32. Difference between List, Set, and Map?
List allows duplicates. Set doesn’t allow duplicates. Map stores key-value pairs.

3
33. Difference between HashMap and Hashtable?
HashMap is not synchronized and allows null. Hashtable is synchronized and
doesn't allow null keys.
34. What is an Iterator?
An interface to traverse elements in a collection.
35. Difference between Iterator and ListIterator?
ListIterator can traverse forward and backward. Iterator is forward-only.
36. What is exception handling?
A mechanism to handle runtime errors using try, catch, finally, throw, and throws.
37. Difference between checked and unchecked exceptions?
Checked exceptions are checked at compile-time. Unchecked exceptions occur at
runtime.
38. Difference between throw and throws?
throw is used to explicitly throw an exception. throws is used in method
signature to declare exceptions.
39. What is multithreading?
A feature that allows multiple threads to execute simultaneously.
40. How to create a thread in Java?
By extending the Thread class or implementing the Runnable interface.
41. What is synchronization?
A technique to control access to shared resources in multithreaded programs.
42. What is a deadlock?
A condition where two or more threads are blocked forever, each waiting for the
other.
43. What is a lambda expression?
A concise way to represent an anonymous function using -> (Java 8+).
44. What is a functional interface?
An interface with only one abstract method. Example: Runnable.

4
45. What is the Stream API?
An API introduced in Java 8 for processing collections using functional
programming.
46. What is the Optional class?
A container object used to avoid null pointer exceptions.
47. What is garbage collection?
Automatic memory management in Java where unreachable objects are deleted.
48. What is finalize()?
A method called by the garbage collector before destroying the object.
49. What is the transient keyword?
It prevents a variable from being serialized.
50. What is the volatile keyword?
It ensures that the value of a variable is always read from the main memory, useful
in multithreading.

You might also like