- Annotations help us in determining basic errors before hand before compilation.
- For example if we misspell an overridden method then in that case we can check it before compilation only if it has @override annotation above it.
- In Spring framework many issues can be predicted in advanced i.e. before application compiler.
- Before annotations we used to do all configurations in Spring framework in the xml configuration file.
- for example @bean/@component annotation directly class can be used as a bean.
- We can create a custom annotation using @interface MyAnnotation {}
- Important meta annotation properties are
- @Target
- This annotation meta tells where we can apply the particular annotation on method on class or constructor, et cetera
- It has following properties
- ElementType.Constructor
- ElementType.Method
- ElementType.Parameter
- ElementType.Field
- @Retention
- This annotation meta Tells how the particular annotation will be stored in Java.
- It has following values
- RetentionPolicy.Source
- Annotations will be discarded by compiler itself and not even recorded in class file.
- RetentionPolicy.Class
- Annotation will be recorded in class file, but ignored by JVM during runtime.
- RetentionPolicy.Runtime
- Annotation will be recorded in class file and also available during runtime.
- Return type Of the custom annotation is Restricted to
- Primitive type(type,boolean,double)
- String
- Enum
- Class<?>
- Annotation
- Array of above types.
- Introduction
- Installation
- Junit
- Arrays
- Classes
- Data Types
- Expressions
- Interfaces
- JDBC
- Loops
- OOPS
- Serializable
- Strings
- Constructors
- Package
- Java Servlets
- Deployment
- Logging
- JSP
- ANT
- Web Services and Sockets
- Struts
- JPA
- Object Injection
- Annotations
- Reflection API
- Static Blocks
- Java Native Interface (JNI)
- Multithreading
- Tomcat Server
- Java Web Toolkit(JWT)
- Archive Files
- EJB(Enterprise Java Beans)
- JConsole
- Memory Profiling
- Hashing
- Exceptions
- Java Map Interface
- Java 8
- Garbage Collection
- Java 11
- Collections
Annotations
Subscribe to:
Posts (Atom)
-
What is the way to import only static members of a class? We can import using “import static packagename.classname.*” We can import using “i...
-
Q What is the difference between Array List and Linked List? Array List and Linked List both extend the List interface which extends Coll...
-
How do you detect a deadlock in a running Java program? We can use Jconsole to check for Deadlock which comes with JDK. There are also other...
No comments:
Post a Comment