MSK Institute • Shikohabad
Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Connecting serverPlease wait...
💻 Practical Labs🚀 Free Demo📜 Verified Certificates
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Annotations are metadata tags affixed to classes, methods, fields, and parameters. While annotations do not directly change compiled bytecode execution semantics, they can be discovered and processed at runtime using Reflection.
This is the exact mechanism behind @Autowired, @Test, @Entity, and @Transactional.
When defining a custom annotation using @interface, Java requires meta-annotations:
@Retention: Defines how long the annotation is retained:RetentionPolicy.SOURCE: Discarded by the compiler (e.g. @Override).RetentionPolicy.CLASS: Stored in .class file but ignored by JVM at runtime.RetentionPolicy.RUNTIME: Retained in JVM memory and readable via Reflection!@Target: Restricts where the annotation can be attached:ElementType.TYPE: Classes, interfaces, enums, records.ElementType.METHOD: Methods.ElementType.FIELD: Fields.ElementType.PARAMETER: Method parameters.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 1 questions. Each question has one correct answer.