Skip to content
QuizMaker logoQuizMaker
Activity
Java Programming: From Zero to Enterprise
4. Advanced Java & Frameworks
1. Getting Started with Java & the JVM
2. Data Types & Variables
3. Control Flow: Ifs & Loops
4. String Manipulation in Depth
5. Methods (Functions) Architecture
6. Arrays & The Enhanced For Loop
7. User Input via Scanner
8. Mathematical Operations & The Math Class
9. Operators in Depth
10. Block Scope & Variable Lifecycles
11. Introduction to Object-Oriented Programming
12. Classes & Instances Deep Dive
13. Constructors
14. Encapsulation & The 'this' Keyword
15. Inheritance: Extending Functionality
16. Polymorphism & Method Overriding
17. Abstraction & Abstract Classes
18. Interfaces: The Ultimate Contract
19. Packages & Access Modifiers
20. Enums (Enumerations)
21. Exceptions: Handling Runtime Errors
22. The 'throw' and 'throws' keywords
23. Dates, Times, and Formatting
24. Enumerable Data Structures
25. LinkedLists: The Alternative
26. HashMaps: Key-Value Architecture
27. HashSets: The Art of Uniqueness
28. Iterator: Safe Collection Traversal
29. Wrapper Classes & Autoboxing
30. Basic File I/O
31. Generics: Type-Safe Templates
32. Lambda Expressions & Functional Interfaces
33. The Stream API: Functional Data Pipelines
34. Optional: Beating the NullPointerException
35. Multithreading & Concurrency Basics
36. JDBC: Connecting to SQL Databases
37. Annotations & Reflection
38. The JVM Garbage Collector
39. Introduction to Spring Boot
40. Unit Testing with JUnit
41. Java Collections for DSA
CONTENTS

37. Annotations & Reflection

Metadata tagging and inspecting your own code while it's running.

Feb 22, 20264 views0 likes0 fires
18px

[!NOTE] We touched upon Annotations briefly with @Override. But Annotations govern modern Java frameworks entirely. If you want to use Spring or Hibernate, you must understand exactly how decorators inject massive amounts of hidden logic!

What is an Annotation?

An annotation (the @ symbol followed by a name) is Metadata. It does not perform any physical logic by itself. It is simply a tag stitched onto a class or method.

@Deprecated // Warning! Do not use this method anymore!
public void oldLegacyLogin() { ... }

How Frameworks Use Annotations (Reflection)

If an annotation is just a descriptive label, how does the famous Spring Framework use @RestController to magically launch a Tomcat web server and start mapping HTTP requests?

It uses Reflection.

Java Reflection is an incredibly dangerous, ultra-powerful API that allows the Java JVM to look in the mirror. It lets code inspect itself while it is actively running.

  1. The Spring Framework starts up.
  2. It uses Reflection to aggressively scan every single Class in your entire /src directory.
  3. It asks: "Does this Class have the @RestController tag glued to it?"
  4. If Yes, Spring dynamically hijacks the class, generates a massive proxy server block in memory, injects JSON parsing logic, and opens ports to the internet!
// Without you writing ANY server code, Spring detects this tag and boots a server for it via Reflection!
@RestController
public class AuthenticationAPI {

    // Spring scans for this tag, and routes HTTP GET requests straight into your method!
    @GetMapping("/login")
    public String attemptLogin() {
        return "You have reached the API!";
    }
}

[!CAUTION] Applying Reflection directly yourself (like invoking methods via string names) is extremely slow and breaks compile-time safety. Unless you are literally building the next Spring Boot framework yourself, avoid utilizing the java.lang.reflect package in business logic!

Share this article

Share on TwitterShare on LinkedInShare on FacebookShare on WhatsAppShare on Email

Test your knowledge

Take a quick quiz based on this chapter.

mediumJava
Quiz: Annotations
2 questions5 min

Continue Learning

38. The JVM Garbage Collector

Advanced
12 min

39. Introduction to Spring Boot

Advanced
12 min

40. Unit Testing with JUnit

Advanced
14 min
Lesson 7 of 11 in 4. Advanced Java & Frameworks
Previous in 4. Advanced Java & Frameworks
36. JDBC: Connecting to SQL Databases
Next in 4. Advanced Java & Frameworks
38. The JVM Garbage Collector
← Back to Java Programming: From Zero to Enterprise
Back to Java Programming: From Zero to EnterpriseAll Categories