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)
- What could be a downside of overusing Java records in domain models?Multiple choiceHard
- Given an enum with a method, how can each constant have a different implementation of that method?Multiple choiceHard
- What keyword is used to define a Java Record?Multiple choiceEasy
- Which pattern is effectively implemented when using enums to represent singletons?Multiple choiceHard
- How can you iterate over all constants of an enum in Java?Multiple choiceMedium
- When designing a domain model, why should you be cautious about using records for classes with business logic?Multiple choiceHard
- How can the use of enums improve the clarity of domain models in Java?Multiple choiceMedium
- When is a Java Record usually the better choice than a traditional class?Multiple choiceEasy
- How might the misuse of BigDecimal constructors impact a domain model dealing with financial data?Multiple choiceHard
- How can you use an enum to implement a strategy pattern for different payment methods in an e-commerce application?Multiple choiceHard
- What keyword is used to define an enum in Java?Multiple choiceEasy
- Why is it not recommended to use the ordinal() method for persistent storage?Multiple choiceMedium
- Why might you choose to use a primitive type over a wrapper class in a performance-sensitive part of your domain model?Multiple choiceMedium
- In the context of domain-driven design, why is it beneficial to use value objects?Multiple choiceMedium
- Why do teams use final fields in Java domain models in production code?Multiple choiceEasy
- 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
- How does a Java Record handle method overriding for equals()?Multiple choiceEasy
- In the context of enums, what advantage does adding methods to an enum provide?Multiple choiceMedium
- How would you explain a potential pitfall of using enums for domain modeling in a Java interview?Multiple choiceMedium
- 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
- How can Java Records help in reducing memory footprint for objects?Multiple choiceHard
- Why do teams use Java records for domain modeling in production code?Multiple choiceEasy
- Which method can be overridden in a Java enum to provide custom behavior for each constant?Multiple choiceMedium
- How does an enum improve maintainability in Java applications?Multiple choiceMedium
- Which of the following is a potential misuse of Java records in domain modeling?Multiple choiceMedium
- Why might you choose to use a Java enum to represent the status of an order in an e-commerce application?Multiple choiceEasy
- 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
- What does the ordinal() method of an enum return?Multiple choiceEasy
- How can you add additional information to an enum constant in Java?Multiple choiceMedium
- Which Java keyword would you use to create a Java Record?Multiple choiceEasy
- Which of the following is true about Java enums?Multiple choiceEasy
- Why is an enum usually a better model than a raw String for OrderStatus?Multiple choiceEasy
- Why do teams use Java Records over traditional Java classes in production code?Multiple choiceEasy
- Why can adding many methods to an enum become a problem in production code?Multiple choiceHard
- Which feature of the Java BigDecimal class makes it suitable for handling monetary values?Multiple choiceMedium
- In what scenario might using a wrapper type instead of a primitive be beneficial in Java?Multiple choiceMedium
- Why would you choose to use an enum for a set of states in an e-commerce order system?Multiple choiceMedium
- Why is it generally a bad idea to use floating-point numbers for precise financial calculations in Java?Multiple choiceMedium
- When designing a domain model, why might you choose to use a Java record over a traditional class?Multiple choiceHard
- How can using wrapper classes instead of primitive types improve a domain model?Multiple choiceEasy
- Why do teams use a Java record for a simple data carrier class in production code?Multiple choiceMedium
- Which Java feature helps eliminate the need for explicit getter and setter methods in domain models?Multiple choiceEasy
- 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
- How does using value objects improve code readability in Java?Multiple choiceEasy
- Which of the following is NOT true about the canonical constructor in Java Records?Multiple choiceHard
- Which of the following is not a feature of Java text blocks?Multiple choiceMedium
- Given a Java text block, how does the compiler handle incidental whitespace?Multiple choiceHard
- How do you write a multiline string in Java using text blocks?Multiple choiceMedium
- In which scenario is a static factory method preferred over a constructor?Multiple choiceHard
- 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