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 1 of 4)

  1. What could be a downside of overusing Java records in domain models?Multiple choiceHard
  2. Given an enum with a method, how can each constant have a different implementation of that method?Multiple choiceHard
  3. What keyword is used to define a Java Record?Multiple choiceEasy
  4. Which pattern is effectively implemented when using enums to represent singletons?Multiple choiceHard
  5. How can you iterate over all constants of an enum in Java?Multiple choiceMedium
  6. When designing a domain model, why should you be cautious about using records for classes with business logic?Multiple choiceHard
  7. How can the use of enums improve the clarity of domain models in Java?Multiple choiceMedium
  8. When is a Java Record usually the better choice than a traditional class?Multiple choiceEasy
  9. How might the misuse of BigDecimal constructors impact a domain model dealing with financial data?Multiple choiceHard
  10. How can you use an enum to implement a strategy pattern for different payment methods in an e-commerce application?Multiple choiceHard
  11. What keyword is used to define an enum in Java?Multiple choiceEasy
  12. Why is it not recommended to use the ordinal() method for persistent storage?Multiple choiceMedium
  13. Why might you choose to use a primitive type over a wrapper class in a performance-sensitive part of your domain model?Multiple choiceMedium
  14. In the context of domain-driven design, why is it beneficial to use value objects?Multiple choiceMedium
  15. Why do teams use final fields in Java domain models in production code?Multiple choiceEasy
  16. How would you explain a key benefit of using enums over strings for representing a fixed set of values in a Java interview?Multiple choiceEasy
  17. How does a Java Record handle method overriding for equals()?Multiple choiceEasy
  18. In the context of enums, what advantage does adding methods to an enum provide?Multiple choiceMedium
  19. How would you explain a potential pitfall of using enums for domain modeling in a Java interview?Multiple choiceMedium
  20. In the context of designing an e-commerce application, which of the following is a key advantage of using an enum to represent order statuses over a string?Multiple choiceMedium
  21. How can Java Records help in reducing memory footprint for objects?Multiple choiceHard
  22. Why do teams use Java records for domain modeling in production code?Multiple choiceEasy
  23. Which method can be overridden in a Java enum to provide custom behavior for each constant?Multiple choiceMedium
  24. How does an enum improve maintainability in Java applications?Multiple choiceMedium
  25. Which of the following is a potential misuse of Java records in domain modeling?Multiple choiceMedium
  26. Why might you choose to use a Java enum to represent the status of an order in an e-commerce application?Multiple choiceEasy
  27. Consider a Java Record defined as 'record Product(String name, double price) {}'. What happens if you attempt to add a non-static field to this record?Multiple choiceHard
  28. What does the ordinal() method of an enum return?Multiple choiceEasy
  29. How can you add additional information to an enum constant in Java?Multiple choiceMedium
  30. Which Java keyword would you use to create a Java Record?Multiple choiceEasy
  31. Which of the following is true about Java enums?Multiple choiceEasy
  32. Why is an enum usually a better model than a raw String for OrderStatus?Multiple choiceEasy
  33. Why do teams use Java Records over traditional Java classes in production code?Multiple choiceEasy
  34. Why can adding many methods to an enum become a problem in production code?Multiple choiceHard
  35. Which feature of the Java BigDecimal class makes it suitable for handling monetary values?Multiple choiceMedium
  36. In what scenario might using a wrapper type instead of a primitive be beneficial in Java?Multiple choiceMedium
  37. Why would you choose to use an enum for a set of states in an e-commerce order system?Multiple choiceMedium
  38. Why is it generally a bad idea to use floating-point numbers for precise financial calculations in Java?Multiple choiceMedium
  39. When designing a domain model, why might you choose to use a Java record over a traditional class?Multiple choiceHard
  40. How can using wrapper classes instead of primitive types improve a domain model?Multiple choiceEasy
  41. Why do teams use a Java record for a simple data carrier class in production code?Multiple choiceMedium
  42. Which Java feature helps eliminate the need for explicit getter and setter methods in domain models?Multiple choiceEasy
  43. Consider the following code snippet. What will be the output if the PriceRecord is instantiated with new PriceRecord(new BigDecimal("20.00"), Currency.USD)?Multiple choiceHard
  44. How does using value objects improve code readability in Java?Multiple choiceEasy
  45. Which of the following is NOT true about the canonical constructor in Java Records?Multiple choiceHard
  46. Which of the following is not a feature of Java text blocks?Multiple choiceMedium
  47. Given a Java text block, how does the compiler handle incidental whitespace?Multiple choiceHard
  48. How do you write a multiline string in Java using text blocks?Multiple choiceMedium
  49. In which scenario is a static factory method preferred over a constructor?Multiple choiceHard
  50. In Java 17, how would you refactor a switch statement to a switch expression for better readability and safety in a customer type check?Multiple choiceHard