Skip to content
Sharp

Modern Java interview questions

Cleaner Domain Modeling, Enums, Java Records, Modern Java Design Choices, Records, Static Factory Methods

185 questions with answers and explanations · 185 flashcards

Questions (page 3 of 4)

  1. What will be the result of the following switch expression? String product = "Laptop"; String warranty = switch (product) { case "Laptop" -> { yield "2 years…Multiple choiceHard
  2. How would you explain a text block in a Java interview?Multiple choiceEasy
  3. Why do teams use records in Java for domain modeling in production code?Multiple choiceEasy
  4. Which of the following best describes a value object in modern Java design?Multiple choiceEasy
  5. Given the following code, what will be printed if the 'status' is 'PENDING'? enum OrderStatus { PENDING, SHIPPED, DELIVERED } OrderStatus status =…Multiple choiceHard
  6. In what situation might a Java developer choose to use a class instead of a record?Multiple choiceMedium
  7. In which scenario is it most appropriate to use a record in Java for a value object?Multiple choiceHard
  8. How would you explain a key characteristic of value objects that distinguishes them from entities in an interview?Multiple choiceEasy
  9. Which statement about using text blocks for SQL queries is true?Multiple choiceMedium
  10. When should you prefer using BigDecimal over double in Java?Multiple choiceMedium
  11. Why is it useful to autoboxing in Java?Multiple choiceEasy
  12. Why would you choose to use dedicated types like 'Email' instead of raw Strings?Multiple choiceEasy
  13. Which characteristic of a value object ensures its immutability?Multiple choiceMedium
  14. Why do accessor methods in Java Records not use the 'get' prefix?Multiple choiceMedium
  15. Which of the following is a benefit of using a Java record over a traditional class?Multiple choiceEasy
  16. Which of the following best utilizes a Java enum for representing order statuses in an e-commerce application?Multiple choiceEasy
  17. Which keyword is used in a switch expression to handle control flow and return values without fall-through?Multiple choiceMedium
  18. Why might OrderId.from(raw) be clearer than an overloaded constructor?Multiple choiceHard
  19. Which of the following would prevent a record from being serialized?Multiple choiceHard
  20. How can static factory methods improve domain modeling in Java?Multiple choiceHard
  21. What advantage does using Integer over int provide in Java?Multiple choiceEasy
  22. In what situation might it be inappropriate to use an enum in Java?Multiple choiceHard
  23. How do records help in achieving cleaner domain code in Java?Multiple choiceMedium
  24. How would you explain a compact constructor in Java Records used for in an interview?Multiple choiceMedium
  25. Why do teams use records in Java in production code?Multiple choiceEasy
  26. How can you define a custom method within a Java record?Multiple choiceMedium
  27. How does the canonical constructor in a Java record differ from a traditional constructor?Multiple choiceHard
  28. How would you explain the design benefit of wrapping a raw string in a value object like EmailAddress in an interview?Multiple choiceMedium
  29. How would you explain a key advantage of using static factory methods over constructors in a Java interview?Multiple choiceEasy
  30. How would you explain a key benefit of using static factory methods when creating instances of immutable value objects in an interview?Multiple choiceEasy
  31. What is one advantage of using text blocks over traditional string concatenation for JSON data?Multiple choiceMedium
  32. Why might you prefer using a class over a record if a method needs to modify the state of its instance?Multiple choiceMedium
  33. Which statement about extending records in Java is correct?Multiple choiceHard
  34. Which implementation of the toString() method in a Java Record is the default in Java?Multiple choiceMedium
  35. How does using text blocks for JSON improve error detection compared to string concatenation?Multiple choiceMedium
  36. Why might you choose a traditional class over a record for a certain Java component?Multiple choiceHard
  37. Why do teams use a constructor within a value object to enforce invariants in production code?Multiple choiceMedium
  38. How do records in Java help in maintaining the immutability of objects?Multiple choiceMedium
  39. Which of the following statements is true about Java Records?Multiple choiceMedium
  40. Why might direct component exposure in records be problematic for API evolution?Multiple choiceHard
  41. Why does defining a 'Currency' value object in an e-commerce application help in practice?Multiple choiceEasy
  42. What distinguishes a record's constructor from a typical class constructor in Java?Multiple choiceMedium
  43. How can static factory methods enhance the readability of code when dealing with different ways to create objects?Multiple choiceMedium
  44. How would you explain a key advantage of using value objects in domain modeling in an interview?Multiple choiceEasy
  45. In an e-commerce application, why might static factory methods be used to create objects representing different types of products?Multiple choiceHard
  46. Consider the following switch expression. What will be the value of 'result'? String category = "electronics"; String result = switch (category) { case…Multiple choiceMedium
  47. Which of the following code snippets correctly uses a text block to format a SQL query?Multiple choiceHard
  48. Which type is the clearest sign that you should keep a full class instead of converting it to a record?Multiple choiceHard
  49. Which of the following is a disadvantage of using constructors compared to static factory methods?Multiple choiceMedium
  50. Why might static factory methods be preferred for instance control when creating singleton objects?Multiple choiceMedium