100 Viva Questions with Answers (Based on Java Syllabus)
Unit I: Java Basics & OOP Concepts
1. Q1: What is JVM and how does it work?
Ans: JVM (Java Virtual Machine) executes Java bytecode and enables platform
independence. It converts bytecode to machine-specific code.
2. Q2: Explain the difference between JDK, JRE, and JVM.
Ans: JDK is Java Development Kit (tools + JRE), JRE is Java Runtime Environment (JVM +
libraries), and JVM runs bytecode.
3. Q3: What is a constructor in Java?
Ans: A constructor is a special method used to initialize objects. It has the same name as the
class and no return type.
4. Q4: What are access specifiers in Java?
Ans: Access specifiers control visibility: public, private, protected, and default.
5. Q5: What is the difference between ‘==’ and ‘.equals()’?
Ans: ‘==’ compares references, while ‘.equals()’ compares content.
6. Q6: What is inheritance in Java?
Ans: Inheritance allows a class to acquire properties and methods of another class using the
‘extends’ keyword.
7. Q7: Define polymorphism with example.
Ans: Polymorphism means many forms. It allows one interface to be used for different types
of actions. Example: method overriding.
8. Q8: What is encapsulation?
Ans: Encapsulation is the binding of data and code. It hides internal details using private
variables and provides public methods.
9. Q9: What is abstraction in Java?
Ans: Abstraction hides implementation details and shows only functionality. Achieved via
abstract classes and interfaces.
10. Q10: What is an interface?
Ans: An interface is a reference type in Java used to achieve abstraction and multiple
inheritance.
Unit II: Exception Handling, I/O, and Multithreading
11. Q1: What is an exception in Java?
Ans: An exception is an event that disrupts program execution. It is handled using try-catch
blocks.
12. Q2: Differentiate between checked and unchecked exceptions.
Ans: Checked exceptions are checked at compile time, while unchecked occur at runtime.
13. Q3: What is try-with-resources?
Ans: A try statement that declares resources to be closed automatically after use.
14. Q4: What are byte and character streams?
Ans: Byte streams handle binary data, character streams handle character data.
15. Q5: How to read and write files in Java?
Ans: Using FileReader/FileWriter for characters or FileInputStream/FileOutputStream for
bytes.
16. Q6: What is multithreading?
Ans: Multithreading is executing multiple threads concurrently to perform tasks
simultaneously.
17. Q7: Explain thread life cycle.
Ans: States: New → Runnable → Running → Waiting → Terminated.
18. Q8: What is thread synchronization?
Ans: It controls thread access to shared resources to avoid data inconsistency.
19. Q9: What is inter-thread communication?
Ans: Threads communicate via wait(), notify(), and notifyAll() methods.
20. Q10: What are thread priorities?
Ans: Thread priority decides the order of thread execution; range is 1 (min) to 10 (max).
Unit III: Java New Features
21. Q1: What is a functional interface?
Ans: An interface with a single abstract method. Example: Runnable.
22. Q2: What is a lambda expression?
Ans: A lambda expression is a short block of code that takes parameters and returns a value.
23. Q3: What is method reference?
Ans: Method reference is a shorthand syntax for calling methods using :: operator.
24. Q4: What is Stream API?
Ans: Stream API processes sequences of elements using functional-style operations like
map, filter, reduce.
25. Q5: Explain default and static methods in interfaces.
Ans: Default methods have a body; static methods belong to the interface class itself.
26. Q6: What is Base64 encoding?
Ans: It converts binary data to a text format. Useful for encoding binary streams.
27. Q7: Explain try-with-resources.
Ans: It ensures automatic resource management and closing.
28. Q8: What is Java Module System?
Ans: Introduced in Java 9, it organizes code into modules to improve scalability.
29. Q9: What are type annotations?
Ans: Type annotations are applied to any use of a type and improve code clarity.
30. Q10: What is a sealed class?
Ans: A sealed class restricts which classes can extend it.
Unit IV: Java Collections Framework
31. Q1: What is Java Collection Framework?
Ans: A set of classes and interfaces to store and manipulate data in collections.
32. Q2: Difference between List and Set.
Ans: List allows duplicates and maintains order; Set does not allow duplicates.
33. Q3: What is the difference between HashSet and TreeSet?
Ans: HashSet is unordered; TreeSet maintains sorted order.
34. Q4: What is Map in Java?
Ans: Map stores key-value pairs. Keys are unique; values can be duplicated.
35. Q5: What is the use of Iterator?
Ans: Iterator is used to traverse collections element by element.
36. Q6: Explain Comparable and Comparator interfaces.
Ans: Both are used for sorting. Comparable is natural ordering; Comparator is custom
sorting.
37. Q7: What is HashMap?
Ans: HashMap stores data as key-value pairs and allows one null key and multiple null
values.
38. Q8: What is LinkedHashMap?
Ans: It is a HashMap with predictable iteration order.
39. Q9: What is the use of Properties class?
Ans: Used to maintain configuration and property files.
40. Q10: What is the difference between Vector and ArrayList?
Ans: Vector is synchronized; ArrayList is not.
Unit V: Spring Framework & Spring Boot
41. Q1: What is Spring Framework?
Ans: A Java framework that simplifies enterprise Java development using dependency
injection and AOP.
42. Q2: What is dependency injection?
Ans: It is a design pattern that injects objects rather than creating them manually.
43. Q3: What is Spring Boot?
Ans: Spring Boot simplifies Spring application development by auto-configuration and
embedded servers.
44. Q4: Explain @RestController in Spring Boot.
Ans: @RestController combines @Controller and @ResponseBody. Used for REST APIs.
45. Q5: What is @Autowired?
Ans: It automatically injects dependent beans.
46. Q6: What are Spring Bean Scopes?
Ans: Singleton, Prototype, Request, Session, and Application define bean lifecycles.
47. Q7: What is the purpose of application.properties?
Ans: Used to configure Spring Boot application settings.
48. Q8: What is RequestMapping in Spring Boot?
Ans: It maps HTTP requests to handler methods.
49. Q9: Explain RESTful web services.
Ans: RESTful web services use HTTP methods (GET, POST, PUT, DELETE) for
communication.
50. Q10: What is the use of Logger in Spring Boot?
Ans: Logger records runtime information, errors, and debugging messages.