Skip to content
Sharp

Java Annotations interview questions

Annotation Processors, Custom Annotations, Retention Policies

73 questions with answers and explanations · 73 flashcards

Questions (page 2 of 2)

  1. How would you explain a key purpose of using MethodHandles in a Java interview?Multiple choiceHard
  2. Which annotation in Java specifies that the annotated element should be documented by Javadoc and similar tools?Multiple choiceEasy
  3. What role does the Method.invoke() function play in Java reflection?Multiple choiceMedium
  4. How would you explain a potential risk of generating code at compile-time using annotation processors in an interview?Multiple choiceHard
  5. What method would you use to dynamically call a method annotated with a custom annotation at runtime?Multiple choiceMedium
  6. Which method is used to load a class dynamically at runtime in Java?Multiple choiceEasy
  7. How does Lombok help reduce boilerplate code in Java?Multiple choiceMedium
  8. In the context of annotation processing, why might you use RetentionPolicy.SOURCE?Multiple choiceHard
  9. In a mini-framework using reflection, what is a key advantage of using annotations over configuration files?Multiple choiceHard
  10. Which annotation property must be specified to make an annotation available at runtime?Multiple choiceMedium
  11. Why is it important for annotations used in a Spring Boot REST controller to have RetentionPolicy.RUNTIME?Multiple choiceMedium
  12. Why do teams use a @Retention annotation in custom annotations in production code?Multiple choiceEasy
  13. Why might you use MethodHandles instead of reflection for method invocation in Java?Multiple choiceHard
  14. Which of the following is NOT a valid target for an annotation?Multiple choiceEasy
  15. Why can using reflection in Java applications become a problem in production code?Multiple choiceHard
  16. If an annotation has RetentionPolicy.CLASS, what happens to it during runtime?Multiple choiceEasy
  17. Which retention policy for annotations if none is specified is the default in Java?Multiple choiceEasy
  18. Why does setAccessible(true) on a private field when using reflection change runtime behavior?Multiple choiceHard
  19. Which of the following retention policies does not allow annotations to be accessed during runtime?Multiple choiceEasy
  20. Why might a Java framework require annotations with RetentionPolicy.RUNTIME when implementing a feature such as dependency injection?Multiple choiceHard
  21. Which of the following accurately describes the @Inherited annotation?Multiple choiceHard
  22. Which Java reflection method can be used to inspect the annotations present on a method during runtime?Multiple choiceMedium
  23. How does Lombok help in reducing boilerplate code for Java classes?Multiple choiceMedium