Java Annotations interview questions
Annotation Processors, Custom Annotations, Retention Policies
73 questions with answers and explanations · 73 flashcards
Questions (page 1 of 2)
- Why do teams use Annotation Processors in Java in production code?Multiple choiceEasy
- Which reflection method would you use to check if a specific runtime annotation is present on a class?Multiple choiceMedium
- Given the following custom annotation, what is the default retention policy if none is specified?Multiple choiceHard
- Why does the setAccessible(true) method in Java reflection matter in practice?Multiple choiceEasy
- How does breaking encapsulation using setAccessible(true) impact a Java application?Multiple choiceHard
- Why do teams use Java annotations in production code?Multiple choiceEasy
- How would you explain a key limitation of compile-time annotation processing in a Java interview?Multiple choiceHard
- Which Java Reflection method is used to access annotations at runtime?Multiple choiceMedium
- How would you explain the use of @Override annotation in a Java interview?Multiple choiceEasy
- Which of the following is true about RetentionPolicy.CLASS?Multiple choiceHard
- Which architecture is healthiest for a tiny web framework built with annotations?Multiple choiceHard
- How can you dynamically execute a method in Java using reflection?Multiple choiceMedium
- Why might MethodHandles be preferred over reflection for method invocation in performance-critical Java applications?Multiple choiceHard
- Which Java annotation is used to specify that an annotation type should be automatically inherited?Multiple choiceEasy
- Which Java API allows you to manipulate method parameters dynamically at runtime?Multiple choiceHard
- Which retention policy must be specified to use annotations with reflection?Multiple choiceEasy
- When defining a custom annotation, what does the @Target annotation specify?Multiple choiceMedium
- Which Java API provides the ability to inspect method details at runtime?Multiple choiceEasy
- How does the setAccessible(true) method affect a private field?Multiple choiceMedium
- Consider a custom annotation with RetentionPolicy.RUNTIME placed on a method. Why might method.invoke() be used alongside this annotation?Multiple choiceHard
- Which retention policy if none is specified for a custom annotation is the default in Java?Multiple choiceEasy
- Which of the following is true about the @Retention annotation?Multiple choiceMedium
- Which RetentionPolicy must you choose to ensure annotations are accessible during both development and runtime?Multiple choiceEasy
- How does the JVM treat annotations with RetentionPolicy.SOURCE?Multiple choiceMedium
- How can you check if a method in Java is annotated with a specific annotation at runtime?Multiple choiceMedium
- What does the Abstract Syntax Tree (AST) in the context of Java annotation processing mainly do?Multiple choiceMedium
- Which Java annotation indicates that a custom annotation should be retained at runtime?Multiple choiceMedium
- Why do teams use RetentionPolicy.RUNTIME in annotations in production code?Multiple choiceEasy
- Which tool is commonly used for generating code at compile-time in Java?Multiple choiceMedium
- What does RetentionPolicy.RUNTIME allow you to do with annotations?Multiple choiceEasy
- Which API would you use to check if a class is annotated with a specific annotation at runtime?Multiple choiceMedium
- When using custom annotations in Java, which retention policy must be specified to ensure annotations are available at runtime?Multiple choiceMedium
- What does the @Target annotation specify?Multiple choiceEasy
- When is compile-time code generation usually a better choice than runtime reflection?Multiple choiceMedium
- Why do teams use annotations for URL mapping in a mini-framework in production code?Multiple choiceHard
- What does a custom annotation's @Inherited annotation indicate?Multiple choiceMedium
- Which retention policy is required if a mini-framework reads annotations during startup?Multiple choiceEasy
- Which Java API allows you to dynamically invoke methods on objects?Multiple choiceMedium
- How can annotation processing be leveraged to enhance a mini-framework in Java?Multiple choiceHard
- What could be a potential drawback of using RetentionPolicy.RUNTIME extensively in an application?Multiple choiceHard
- In Java, what is the primary role of the Abstract Syntax Tree (AST) during compilation?Multiple choiceMedium
- How do you declare a custom annotation that should be retained at runtime?Multiple choiceMedium
- In the context of a mini-framework, why is reflection useful when working with annotations?Multiple choiceMedium
- Which API would you use to dynamically load a class in Java?Multiple choiceMedium
- How does the JVM handle annotations with RetentionPolicy.SOURCE?Multiple choiceMedium
- When using an Annotation Processor, what phase of compilation does it primarily operate in?Multiple choiceHard
- In the context of a mini Spring Boot framework, why is it crucial that annotations on REST controllers have RetentionPolicy.RUNTIME?Multiple choiceMedium
- Why does the Annotation Processor in Java matter in this design?Multiple choiceMedium
- In the context of annotation processing, what is the significance of the @SupportedSourceVersion annotation?Multiple choiceHard
- How does an annotation processor interact with the Abstract Syntax Tree (AST) during Java compilation?Multiple choiceMedium