Skip to content
Sharp

Java Annotations interview questions

Annotation Processors, Custom Annotations, Retention Policies

73 questions with answers and explanations · 73 flashcards

Questions (page 1 of 2)

  1. Why do teams use Annotation Processors in Java in production code?Multiple choiceEasy
  2. Which reflection method would you use to check if a specific runtime annotation is present on a class?Multiple choiceMedium
  3. Given the following custom annotation, what is the default retention policy if none is specified?Multiple choiceHard
  4. Why does the setAccessible(true) method in Java reflection matter in practice?Multiple choiceEasy
  5. How does breaking encapsulation using setAccessible(true) impact a Java application?Multiple choiceHard
  6. Why do teams use Java annotations in production code?Multiple choiceEasy
  7. How would you explain a key limitation of compile-time annotation processing in a Java interview?Multiple choiceHard
  8. Which Java Reflection method is used to access annotations at runtime?Multiple choiceMedium
  9. How would you explain the use of @Override annotation in a Java interview?Multiple choiceEasy
  10. Which of the following is true about RetentionPolicy.CLASS?Multiple choiceHard
  11. Which architecture is healthiest for a tiny web framework built with annotations?Multiple choiceHard
  12. How can you dynamically execute a method in Java using reflection?Multiple choiceMedium
  13. Why might MethodHandles be preferred over reflection for method invocation in performance-critical Java applications?Multiple choiceHard
  14. Which Java annotation is used to specify that an annotation type should be automatically inherited?Multiple choiceEasy
  15. Which Java API allows you to manipulate method parameters dynamically at runtime?Multiple choiceHard
  16. Which retention policy must be specified to use annotations with reflection?Multiple choiceEasy
  17. When defining a custom annotation, what does the @Target annotation specify?Multiple choiceMedium
  18. Which Java API provides the ability to inspect method details at runtime?Multiple choiceEasy
  19. How does the setAccessible(true) method affect a private field?Multiple choiceMedium
  20. Consider a custom annotation with RetentionPolicy.RUNTIME placed on a method. Why might method.invoke() be used alongside this annotation?Multiple choiceHard
  21. Which retention policy if none is specified for a custom annotation is the default in Java?Multiple choiceEasy
  22. Which of the following is true about the @Retention annotation?Multiple choiceMedium
  23. Which RetentionPolicy must you choose to ensure annotations are accessible during both development and runtime?Multiple choiceEasy
  24. How does the JVM treat annotations with RetentionPolicy.SOURCE?Multiple choiceMedium
  25. How can you check if a method in Java is annotated with a specific annotation at runtime?Multiple choiceMedium
  26. What does the Abstract Syntax Tree (AST) in the context of Java annotation processing mainly do?Multiple choiceMedium
  27. Which Java annotation indicates that a custom annotation should be retained at runtime?Multiple choiceMedium
  28. Why do teams use RetentionPolicy.RUNTIME in annotations in production code?Multiple choiceEasy
  29. Which tool is commonly used for generating code at compile-time in Java?Multiple choiceMedium
  30. What does RetentionPolicy.RUNTIME allow you to do with annotations?Multiple choiceEasy
  31. Which API would you use to check if a class is annotated with a specific annotation at runtime?Multiple choiceMedium
  32. When using custom annotations in Java, which retention policy must be specified to ensure annotations are available at runtime?Multiple choiceMedium
  33. What does the @Target annotation specify?Multiple choiceEasy
  34. When is compile-time code generation usually a better choice than runtime reflection?Multiple choiceMedium
  35. Why do teams use annotations for URL mapping in a mini-framework in production code?Multiple choiceHard
  36. What does a custom annotation's @Inherited annotation indicate?Multiple choiceMedium
  37. Which retention policy is required if a mini-framework reads annotations during startup?Multiple choiceEasy
  38. Which Java API allows you to dynamically invoke methods on objects?Multiple choiceMedium
  39. How can annotation processing be leveraged to enhance a mini-framework in Java?Multiple choiceHard
  40. What could be a potential drawback of using RetentionPolicy.RUNTIME extensively in an application?Multiple choiceHard
  41. In Java, what is the primary role of the Abstract Syntax Tree (AST) during compilation?Multiple choiceMedium
  42. How do you declare a custom annotation that should be retained at runtime?Multiple choiceMedium
  43. In the context of a mini-framework, why is reflection useful when working with annotations?Multiple choiceMedium
  44. Which API would you use to dynamically load a class in Java?Multiple choiceMedium
  45. How does the JVM handle annotations with RetentionPolicy.SOURCE?Multiple choiceMedium
  46. When using an Annotation Processor, what phase of compilation does it primarily operate in?Multiple choiceHard
  47. In the context of a mini Spring Boot framework, why is it crucial that annotations on REST controllers have RetentionPolicy.RUNTIME?Multiple choiceMedium
  48. Why does the Annotation Processor in Java matter in this design?Multiple choiceMedium
  49. In the context of annotation processing, what is the significance of the @SupportedSourceVersion annotation?Multiple choiceHard
  50. How does an annotation processor interact with the Abstract Syntax Tree (AST) during Java compilation?Multiple choiceMedium