0% found this document useful (0 votes)
6 views15 pages

Java Questionar

The document provides a comprehensive list of 150 Java interview questions categorized into sections such as Java Basics, Control Flow, OOP, Exception Handling, Collections Framework, Multithreading, and Advanced Java. Each section contains a variety of questions that cover fundamental concepts, coding practices, and advanced features of Java. It also includes practical scenarios for real-world applications, making it a useful resource for both beginners and experienced developers preparing for technical interviews.

Uploaded by

Goraangi Ratra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views15 pages

Java Questionar

The document provides a comprehensive list of 150 Java interview questions categorized into sections such as Java Basics, Control Flow, OOP, Exception Handling, Collections Framework, Multithreading, and Advanced Java. Each section contains a variety of questions that cover fundamental concepts, coding practices, and advanced features of Java. It also includes practical scenarios for real-world applications, making it a useful resource for both beginners and experienced developers preparing for technical interviews.

Uploaded by

Goraangi Ratra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

JAVA QUESTIONAR

Here's a structured **set of 150 Java questions** progressing from **basic to advanced**, covering core concepts,
OOP, collections, multithreading, exceptions, I/O, and more:

---

### **Section 1: Java Basics (20 Questions)**

1. What is Java? List its key features.

2. What is the difference between JDK, JRE, and JVM?

3. Explain the `public static void main(String[] args)` method.

4. What are Java keywords? List 5 examples.

5. What are data types in Java? List primitive and non-primitive types.

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

7. What is type casting? Explain implicit and explicit casting.

8. What are Java operators? List arithmetic, relational, and logical operators.

9. What is the ternary operator? Give an example.

10. What are comments in Java? List single-line and multi-line syntax.

11. What is `var` in Java (Java 10+)?

12. What is the difference between `++i` and `i++`?

13. How do you take user input in Java?

14. What is `String[] args` in `main()`?

15. What is the difference between `System.out.print()` and `System.out.println()`?

16. What is an escape sequence? Give examples.

17. What is the difference between `float` and `double`?

18. What is the `final` keyword?

19. What is `Scanner` class used for?

20. How do you compile and run a Java program?

---

### **Section 2: Control Flow (15 Questions)**

21. What is an `if-else` statement? Give an example.


22. What is a `switch` statement? How is it different from `if-else`?

23. What is a nested `if`?

24. What is the `default` case in `switch`?

25. What are loops in Java? List `for`, `while`, and `do-while`.

26. What is an infinite loop? How do you create one?

27. What is the difference between `break` and `continue`?

28. What is a labeled loop?

29. Write a program to print numbers 1 to 10 using `for`.

30. Write a program to find the factorial of a number.

31. Write a program to check if a number is prime.

32. Write a program to print Fibonacci series.

33. What is recursion? Give an example.

34. What is the difference between iteration and recursion?

35. How do you reverse a number?

---

### **Section 3: OOPs Concepts (25 Questions)**

36. What is OOP? List its principles (Abstraction, Encapsulation, Inheritance, Polymorphism).

37. What is a class and object? Give an example.

38. What is a constructor? How is it different from a method?

39. What is method overloading?

40. What is method overriding?

41. What is the difference between overloading and overriding?

42. What is `this` keyword?

43. What is `super` keyword?

44. What is the difference between `this` and `super`?

45. What is inheritance? Give an example.

46. What is polymorphism? Explain runtime and compile-time polymorphism.

47. What is abstraction? How is it achieved in Java?

48. What is encapsulation? How is it implemented?

49. What is an interface? How is it different from an abstract class?


50. What is an abstract class? Can it have constructors?

51. What is a `static` method? Can it be overridden?

52. What is a `final` class?

53. What is a `final` method?

54. What is a package? How do you create one?

55. What is the difference between `private`, `protected`, `default`, and `public` access modifiers?

56. What is composition? How is it different from inheritance?

57. What is aggregation?

58. What is association?

59. What is dependency injection?

60. What is the `instanceof` operator?

---

### **Section 4: Exception Handling (15 Questions)**

61. What is an exception?

62. What is the difference between `Error` and `Exception`?

63. What are checked and unchecked exceptions?

64. What is `try-catch-finally`?

65. What is `throw` and `throws`?

66. What is the difference between `throw` and `throws`?

67. What is `try-with-resources`?

68. What is a custom exception? How do you create one?

69. What is `NullPointerException`?

70. What is `ArrayIndexOutOfBoundsException`?

71. What is `ClassCastException`?

72. What is `StackOverflowError`?

73. What is `OutOfMemoryError`?

74. What is `NumberFormatException`?

75. What is `FileNotFoundException`?

---
### **Section 5: Collections Framework (25 Questions)**

76. What is the Java Collections Framework?

77. What is the difference between `List`, `Set`, and `Map`?

78. What is `ArrayList`? How is it different from `LinkedList`?

79. What is `HashSet`? How does it ensure uniqueness?

80. What is `HashMap`? How does it work internally?

81. What is the difference between `HashMap` and `HashTable`?

82. What is `TreeMap`? How is it different from `HashMap`?

83. What is `LinkedHashMap`?

84. What is `PriorityQueue`?

85. What is `Comparable` and `Comparator`?

86. How do you sort a `List`?

87. What is `Iterator` and `ListIterator`?

88. What is `ConcurrentHashMap`?

89. What is `fail-fast` and `fail-safe`?

90. What is `Vector`? How is it different from `ArrayList`?

91. What is `Stack`?

92. What is `Queue`?

93. What is `Deque`?

94. What is `Collections.synchronizedList()`?

95. What is `CopyOnWriteArrayList`?

96. What is `WeakHashMap`?

97. What is `IdentityHashMap`?

98. What is `EnumSet`?

99. What is `EnumMap`?

100. What is `Stream` API?

---

### **Section 6: Multithreading (20 Questions)**

101. What is multithreading?


102. What is the difference between `Thread` and `Runnable`?

103. How do you create a thread?

104. What is `Thread.sleep()`?

105. What is `Thread.join()`?

106. What is `synchronized` keyword?

107. What is `volatile` keyword?

108. What is `wait()`, `notify()`, and `notifyAll()`?

109. What is a deadlock? How do you avoid it?

110. What is a race condition?

111. What is `ThreadPoolExecutor`?

112. What is `Callable` and `Future`?

113. What is `ReentrantLock`?

114. What is `AtomicInteger`?

115. What is `CountDownLatch`?

116. What is `CyclicBarrier`?

117. What is `Semaphore`?

118. What is `ForkJoinPool`?

119. What is `CompletableFuture`?

120. What is `ThreadLocal`?

---

### **Section 7: Advanced Java (30 Questions)**

121. What is reflection in Java?

122. What is serialization and deserialization?

123. What is `transient` keyword?

124. What is `native` keyword?

125. What is JNI?

126. What is lambda expression?

127. What is functional interface?

128. What is `Optional`?

129. What is `Stream` API?


130. What is method reference?

131. What is `Predicate`, `Function`, and `Consumer`?

132. What is `var` (Java 10)?

133. What is `record` (Java 16)?

134. What is `sealed` class (Java 17)?

135. What is `switch` expression (Java 14)?

136. What is `instanceof` pattern matching (Java 16)?

137. What is `Text Blocks` (Java 15)?

138. What is `Modules` (Java 9)?

139. What is `JShell` (Java 9)?

140. What is `var` with lambda (Java 11)?

141. What is `ZGC` (Java 11)?

142. What is `Shenandoah GC` (Java 12)?

143. What is `Records` (Java 16)?

144. What is `Pattern Matching for `instanceof` (Java 16)?

145. What is `Foreign Function & Memory API` (Java 19)?

146. What is `Virtual Threads` (Java 21)?

147. What is `String Templates` (Java 21)?

148. What is `Unnamed Classes` (Java 21)?

149. What is `Structured Concurrency` (Java 21)?

150. What is `Scoped Values` (Java 21)?

---

### **How to Use These Questions?**

- **Beginners**: Focus on **Basics, OOPs, Exception Handling**.

- **Intermediate**: Master **Collections, Multithreading**.

- **Advanced**: Dive into **Java 8+ Features, Concurrency, JVM Internals**.

**Need detailed answers or coding examples?** Let me know! 🚀


Here's a structured **set of 150 Java interview questions** categorized from **basic to advanced**, perfect for
technical interviews:

---

### **1. Core Java Fundamentals (30 Questions)**

1. What is Java? Explain its key features.

2. Difference between JDK, JRE, and JVM.

3. Explain `public static void main(String[] args)`.

4. What are Java keywords? List 5.

5. Primitive vs. non-primitive data types.

6. Difference between `==` and `.equals()`.

7. What is autoboxing/unboxing?

8. Explain `final`, `finally`, and `finalize`.

9. What are Java annotations? Give examples.

10. What is `var` (Java 10+)?

---

### **2. OOPs Concepts (25 Questions)**

11. Four pillars of OOP with examples.

12. Difference between class and object.

13. Constructor vs. method.

14. Method overloading vs. overriding.

15. `this` vs. `super` keyword.

16. Abstract class vs. interface (Java 8+).

17. Can we override `static` methods?

18. What is polymorphism? Runtime vs. compile-time.

19. Composition vs. inheritance.

20. What is encapsulation? How is it achieved?

---
### **3. Exception Handling (15 Questions)**

21. Checked vs. unchecked exceptions.

22. `try-catch-finally` block flow.

23. `throw` vs. `throws`.

24. Custom exception creation.

25. Why is `NullPointerException` unchecked?

26. `try-with-resources` (Java 7+).

27. What is `StackOverflowError`?

---

### **4. Collections Framework (25 Questions)**

28. List vs. Set vs. Map.

29. `ArrayList` vs. `LinkedList`.

30. `HashSet` internal working.

31. `HashMap` working (hashing, collisions).

32. `HashMap` vs. `ConcurrentHashMap`.

33. `Comparable` vs. `Comparator`.

34. Fail-fast vs. fail-safe iterators.

35. `Stream` API operations (`map`, `filter`, `reduce`).

---

### **5. Multithreading & Concurrency (25 Questions)**

36. Thread vs. Runnable.

37. Thread lifecycle states.

38. `synchronized` keyword usage.

39. `volatile` keyword purpose.

40. Deadlock example and prevention.

41. `wait()`, `notify()`, `notifyAll()`.

42. `ExecutorService` vs. `ForkJoinPool`.

43. `CountDownLatch` vs. `CyclicBarrier`.


44. `CompletableFuture` (Java 8+).

---

### **6. Advanced Java (30 Questions)**

45. JVM memory areas (heap, stack, metaspace).

46. Garbage collection algorithms.

47. Reflection API uses.

48. Serialization/deserialization.

49. Lambda expressions (Java 8+).

50. Functional interfaces (`Predicate`, `Function`).

51. `Optional` class best practices.

52. Records (Java 16+).

53. Sealed classes (Java 17+).

54. Virtual Threads (Java 21).

---

### **7. Java 8+ Features (20 Questions)**

55. Default methods in interfaces.

56. `Stream` API vs. loops.

57. Method references (:: operator).

58. `Optional` to avoid NPEs.

59. New Date/Time API (`LocalDate`, `ZonedDateTime`).

60. `var` for local variables (Java 10).

---

### **Key Areas Covered:**

- **Beginner**: Basics, OOPs, exceptions.

- **Intermediate**: Collections, multithreading.

- **Advanced**: JVM, Java 8+ features, concurrency.


**Pro Tip:** For coding rounds, practice problems on:

- String manipulation (`Palindrome`, `Anagram`).

- Array/List sorting/searching.

- Tree/Graph traversals.

Would you like solutions to any specific questions? 🚀

Here’s a curated list of **30 real-world Java interview questions** that simulate practical scenarios, testing your ability
to solve everyday problems with code:

---

### **1. E-Commerce & Retail Systems**

1. **Shopping Cart System**

- Design a cart that calculates discounts (e.g., "Buy 2, Get 1 Free") and taxes.

- *Key Concepts: OOP (classes for `Product`, `Cart`), collections (`HashMap` for items), algorithms.*

2. **Inventory Stock Alert**

- Build a system that triggers alerts when product stock falls below a threshold.

- *Key Concepts: Exception handling, file I/O (log alerts), observer pattern.*

3. **Payment Gateway Integration**

- Simulate validating credit card numbers (Luhn algorithm) and processing payments.

- *Key Concepts: Regex, polymorphism (different payment methods: `CreditCard`, `PayPal`).*

---

### **2. Banking & Finance**

4. **ATM Simulation**

- Implement withdrawal/deposit with PIN validation and balance checks.

- *Key Concepts: Encapsulation (account balance), exception handling (`InsufficientFundsException`).*

5. **Interest Calculator**
- Compute compound interest for savings accounts with varying rates.

- *Key Concepts: BigDecimal (precision), loops/formulas.*

6. **Fraud Detection**

- Flag transactions above $10,000 or from unusual locations.

- *Key Concepts: Stream API (`filter`), custom exceptions.*

---

### **3. Social Media & Networking**

7. **Post Scheduler**

- Schedule posts to publish at specific times (e.g., `java.util.Timer`).

- *Key Concepts: Multithreading, `TimerTask`, `ScheduledExecutorService`.*

8. **Trending Hashtags**

- Track top 10 trending hashtags from a stream of posts.

- *Key Concepts: PriorityQueue, Map (count occurrences).*

9. **Friend Recommendation**

- Suggest friends-of-friends (graph traversal: BFS/DFS).

- *Key Concepts: Graph algorithms, adjacency lists.*

---

### **4. Logistics & Travel**

10. **Route Optimization**

- Find the shortest path between warehouses (Dijkstra’s algorithm).

- *Key Concepts: Graphs, `PriorityQueue`.*

11. **Flight Booking System**

- Handle seat reservations (economy/business) with thread safety.

- *Key Concepts: `ConcurrentHashMap`, synchronization.*


12. **Package Tracker**

- Update delivery status in real-time (observer pattern).

- *Key Concepts: Observer pattern, `java.util.Observable`.*

---

### **5. Healthcare Systems**

13. **Patient Appointment Scheduler**

- Avoid double-booking doctors using time slots.

- *Key Concepts: `TreeSet` (sorted slots), immutability.*

14. **Medicine Reminder**

- Send alerts at scheduled times (e.g., "Take Insulin at 8 AM").

- *Key Concepts: `Timer`, `LocalTime`.*

15. **BMI Calculator**

- Calculate BMI from weight/height inputs with validation.

- *Key Concepts: DTOs, input validation.*

---

### **6. IoT & Embedded Systems**

16. **Smart Thermostat**

- Adjust temperature based on sensor input (e.g., `if (temp > 30) cool()`).

- *Key Concepts: State pattern, enums.*

17. **Sensor Data Aggregator**

- Average temperature readings from multiple sensors.

- *Key Concepts: Stream API (`map`, `reduce`), `DoubleSummaryStatistics`.*

18. **Device Command Queue**


- Process commands in FIFO order while handling priority interrupts.

- *Key Concepts: `BlockingQueue`, thread pools.*

---

### **7. Entertainment & Gaming**

19. **Tic-Tac-Toe with AI**

- Implement a minimax algorithm for an unbeatable AI.

- *Key Concepts: 2D arrays, recursion.*

20. **Movie Recommendation Engine**

- Suggest movies based on genre/ratings (collaborative filtering).

- *Key Concepts: `Map` (user preferences), sorting.*

21. **Playlist Shuffler**

- Randomize songs without repeats (Fisher-Yates shuffle).

- *Key Concepts: Arrays, randomness.*

---

### **8. Enterprise Solutions**

22. **PDF Invoice Generator**

- Create PDFs with order details using `iText` or `Apache PDFBox`.

- *Key Concepts: External libraries, file I/O.*

23. **Email Campaign Manager**

- Send bulk emails with templates (JavaMail API).

- *Key Concepts: SMTP, `ExecutorService` for threading.*

24. **Log Analyzer**

- Parse server logs to find error rates (regex, `Files.lines()`).

- *Key Concepts: Stream API, `java.nio`.*


---

### **9. Performance & Scalability**

25. **Database Connection Pool**

- Reuse connections to reduce overhead (singleton pattern).

- *Key Concepts: `ObjectPool`, `synchronized` blocks.*

26. **Caching Mechanism**

- Implement LRU (Least Recently Used) cache.

- *Key Concepts: `LinkedHashMap`, eviction policies.*

27. **Parallel Data Processing**

- Sum numbers in a large file using `ForkJoinPool`.

- *Key Concepts: Fork/Join framework.*

---

### **10. Security & Compliance**

28. **Password Strength Checker**

- Validate passwords (min 8 chars, special symbols).

- *Key Concepts: Regex, `Pattern`/`Matcher`.*

29. **Audit Logger**

- Log user actions (e.g., "User X deleted file Y") to a file.

- *Key Concepts: `java.util.logging`, `Log4j`.*

30. **Data Encryption**

- Encrypt sensitive fields using AES.

- *Key Concepts: `javax.crypto`, `SecretKey`.*

---
### **Why These Questions?**

- **Real-World Relevance**: Mimics tasks at companies like Amazon, Google, or startups.

- **Skill Diversity**: Tests OOP, algorithms, concurrency, and APIs.

- **Interview Ready**: Commonly asked in senior/backend developer roles.

**Need solutions or code snippets?** Let me know which problem you’d like to explore! 🚀

You might also like