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 4 of 4)
- Why is using switch expressions with enums considered safer in Java 17?Multiple choiceEasy
- How does a switch expression enhance type safety compared to traditional switch statements?Multiple choiceMedium
- Given a 'Coordinate' value object, how can you ensure its equals method is correctly implemented?Multiple choiceHard
- What feature of switch expressions helps prevent bugs related to missing break statements?Multiple choiceMedium
- Which of the following best describes how enums enhance code readability?Multiple choiceMedium
- Why does the 'compact constructor' in a Java Record matter in practice?Multiple choiceMedium
- Which code correctly yield a value from a block in a switch expression?Multiple choiceMedium
- Which of the following is a valid definition of a record in Java?Multiple choiceMedium
- Why should validation logic be implemented inside a value object's constructor?Multiple choiceMedium
- Which is a characteristic of a Java record?Multiple choiceEasy
- In Java, which method is NOT automatically generated for a record?Multiple choiceEasy
- How does using a BigDecimal in a value object benefit financial calculations?Multiple choiceMedium
- Consider a class designed to handle monetary values. Why might a developer choose a static factory method over a constructor for creating instances of…Multiple choiceHard
- In what scenario would using a record be inappropriate?Multiple choiceMedium
- What does a static factory method return?Multiple choiceEasy
- When defining a 'ProductCode' value object, why might you choose to use a record?Multiple choiceHard
- How do you safely yield a result from a switch expression in Java 17?Multiple choiceMedium
- How would you explain a key advantage of using enums over strings for representing a set of predefined constants in an interview?Multiple choiceMedium
- Why do teams use switch expressions in Java over traditional switch statements in production code?Multiple choiceEasy
- Consider the following switch expression. What will be the output if 'category' is 'grocery'? string discount = switch (category) { case 'electronics' ->…Multiple choiceMedium
- Given the following Java text block for a SQL query, what will be the result of the indentation?Multiple choiceMedium
- When might a regular class be preferred over a record in Java?Multiple choiceHard
- What would be a reason to choose a traditional class over a Java Record?Multiple choiceMedium
- In what way do Java Records improve code readability?Multiple choiceMedium
- Which of the following is true about the arrow syntax in switch expressions?Multiple choiceEasy
- Which of the following is NOT a feature of Java records?Multiple choiceEasy
- When using a switch expression, which keyword is used to handle the default case?Multiple choiceEasy
- In what way do records enhance code readability?Multiple choiceMedium
- When embedding a JSON object in a text block, how do you handle key-value pairs?Multiple choiceMedium
- What main advantage do text blocks provide when embedding JSON or SQL in Java code?Multiple choiceMedium
- In what way can static factory methods improve validation when creating instances of classes?Multiple choiceMedium
- In which scenario is using a record not appropriate?Multiple choiceHard
- Given the following code snippet, identify the primary issue with the 'Email' value object:?Multiple choiceHard
- When should you avoid using Java Records?Multiple choiceMedium
- Why is it beneficial to use value objects for representing monetary amounts rather than using raw doubles or ints?Multiple choiceMedium