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 2 of 4)
- Why does overriding hashCode in a value object change runtime behavior?Multiple choiceMedium
- How does using Java text blocks simplify embedding JSON structures in code?Multiple choiceEasy
- How does the Java compiler handle whitespace at the end of each line in a text block?Multiple choiceHard
- How would you explain a potential disadvantage of using BigDecimal for high-frequency number crunching in an interview?Multiple choiceHard
- Which characteristic best describes a Java record?Multiple choiceEasy
- How would you explain a common feature of Java records that makes them suitable for value objects in an interview?Multiple choiceEasy
- Which version of Java introduced text blocks?Multiple choiceEasy
- How do you include a double quote within a Java text block?Multiple choiceEasy
- How would you explain a potential advantage of using static factory methods over constructors in terms of instance caching in an interview?Multiple choiceEasy
- What happens if you use inconsistent indentation in a Java text block?Multiple choiceHard
- Which is a potential downside of using static factory methods extensively?Multiple choiceMedium
- Which Java type is commonly used in value objects to represent currency values and ensure precision?Multiple choiceEasy
- Why should BigDecimal be preferred over double for currency calculations in Java?Multiple choiceHard
- Which of the following statements is true about static factory methods?Multiple choiceMedium
- What does a static factory method in Java mainly do?Multiple choiceEasy
- How do records in Java help in achieving immutability?Multiple choiceMedium
- Which switch expression feature helps ensure cleaner code in Java?Multiple choiceMedium
- If a value object needs to implement Comparable, what is a best practice to ensure the comparison logic remains consistent?Multiple choiceHard
- How would you explain a key characteristic of a Java record in an interview?Multiple choiceEasy
- Which feature is automatically provided by Java records?Multiple choiceEasy
- Why might you choose a wrapper class like Integer over a primitive int?Multiple choiceMedium
- What will happen if a switch expression does not cover all possible enum values and lacks a default case?Multiple choiceHard
- Consider a 'Price' value object with a BigDecimal field. Why is this a better choice than using a double for the price?Multiple choiceMedium
- Which visibility of a field in a Java record is the default in Java?Multiple choiceEasy
- When should you usually prefer a traditional class over a Record?Multiple choiceMedium
- Which design choice best communicates intent for a lightweight data carrier without behavior in Java?Multiple choiceMedium
- In Java 17, what is a major benefit of using switch expressions with enums?Multiple choiceEasy
- Which of the following is a valid way to define a text block in Java?Multiple choiceEasy
- How can static factory methods enhance validation during object creation?Multiple choiceHard
- Which of the following scenarios is most appropriate for using a Java record?Multiple choiceMedium
- When is a Java record usually a better fit than a traditional class?Multiple choiceMedium
- Given a record 'Product' used in an e-commerce application, what is a potential drawback of directly exposing its components?Multiple choiceHard
- When using switch expressions with enums in Java 17, what happens if you omit a case and there is no default?Multiple choiceMedium
- Static factory methods can return:?Multiple choiceEasy
- What limitation of Java records might require consideration when modeling domain logic?Multiple choiceHard
- How can you ensure thread safety when using a value object in a multi-threaded environment?Multiple choiceMedium
- How can you customize the toString() method in a Java Record?Multiple choiceHard
- Why might a developer choose a static factory method over a constructor when creating a BigDecimal instance?Multiple choiceMedium
- How would you explain a key benefit of using switch expressions in Java 17 for handling order states in an e-commerce system in an interview?Multiple choiceEasy
- In a value object representing a 'DateRange', how might you enforce that the start date precedes the end date?Multiple choiceHard
- Which statement best describes why static factory methods can lead to clearer creation intent in Java?Multiple choiceMedium
- Why might you choose to implement a 'PhoneNumber' as a value object?Multiple choiceMedium
- Which of the following is a potential pitfall when using text blocks for SQL queries?Multiple choiceHard
- Why can using a Java record for representing a mutable user profile in an application become a problem in production code?Multiple choiceMedium
- In a modern Java application, how can switch expressions improve the checkout process logic?Multiple choiceHard
- When implementing a complex financial calculation, why might you choose BigDecimal over double?Multiple choiceHard
- How can you add behavior to a Java record?Multiple choiceMedium
- Which is an advantage of using static factory methods in a large e-commerce application?Multiple choiceMedium
- Why should a value object be immutable?Multiple choiceEasy
- Why do teams use small dedicated types, such as 'ZipCode', in a domain model in production code?Multiple choiceMedium