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