Annotation:-----------
Meta data overcome to problem of xml,, basically we want something meta informatio whhich can be with .java ,.class and even runtime
then annotation came in picture. basically what desiger think the best approach for javadeveloper ,is annotation why should learn .xml for it's usage
,so annotation came in picture.
1-marker annotation @overide,@weblistener without any value
2single value annotation @("unchecked")----<=> value=unchecked
3-multi value annotation @webservlet(name="",urlpattern="")
classification of annotation
1-standard annotation
2-custom annotation
1-standard:-----------1:-general purpose:@overide,@suppresseswarning,@depricated (upto java 7)but in java 8@functioninterface all these annotation are part of
(java.lang. package)
2:-meta-annotation:-@depricated,@inheritedx,@target,@retention,(java.lang.annotation)
For every annotation common default super class java.lang.Annotation
@overide--to overcome the problem of child class overide method should match with super class method else compile time error(spelling mistek etc
)
@suppresseswarning-adding element to collection without it's type compile genetate warning message:Test.java used unchecked or unsafe opertion.
by @suppresseswarning we can hide these messages
@functioninterface, it will allow only one method of abstract in interface
-------------------
@inheritable-will allow annotation to inherited to subclass
@target-to which element we want to apply this annotation
@target(ElementType.type(class level),ElementType.Field(variable),ElementType.method)
@Rentention, up to which stage you want to apply it. source code, class, runtime
@retention(retentionPolicy.runtime),, it will allow to .java,.class. and runtime
2:custom:- define by the developer as per the application:--
stpes requiredP--
@interface Course
{
String cid() default"101" note:- variable name must be like method see cid()
}
applt it to ant class like student
if you want to access it then
Annotation an=class.forname.getAnnotation(course.class);
course cs=course(an)
ex:--
https://www.youtube.com/watch?v=WiefMpqCd1o
http://javapapers.com/core-java/java-annotations/
Meta data overcome to problem of xml,, basically we want something meta informatio whhich can be with .java ,.class and even runtime
then annotation came in picture. basically what desiger think the best approach for javadeveloper ,is annotation why should learn .xml for it's usage
,so annotation came in picture.
1-marker annotation @overide,@weblistener without any value
2single value annotation @("unchecked")----<=> value=unchecked
3-multi value annotation @webservlet(name="",urlpattern="")
classification of annotation
1-standard annotation
2-custom annotation
1-standard:-----------1:-general purpose:@overide,@suppresseswarning,@depricated (upto java 7)but in java 8@functioninterface all these annotation are part of
(java.lang. package)
2:-meta-annotation:-@depricated,@inheritedx,@target,@retention,(java.lang.annotation)
For every annotation common default super class java.lang.Annotation
@overide--to overcome the problem of child class overide method should match with super class method else compile time error(spelling mistek etc
)
@suppresseswarning-adding element to collection without it's type compile genetate warning message:Test.java used unchecked or unsafe opertion.
by @suppresseswarning we can hide these messages
@functioninterface, it will allow only one method of abstract in interface
-------------------
@inheritable-will allow annotation to inherited to subclass
@target-to which element we want to apply this annotation
@target(ElementType.type(class level),ElementType.Field(variable),ElementType.method)
@Rentention, up to which stage you want to apply it. source code, class, runtime
@retention(retentionPolicy.runtime),, it will allow to .java,.class. and runtime
2:custom:- define by the developer as per the application:--
stpes requiredP--
@interface Course
{
String cid() default"101" note:- variable name must be like method see cid()
}
applt it to ant class like student
if you want to access it then
Annotation an=class.forname.getAnnotation(course.class);
course cs=course(an)
ex:--
https://www.youtube.com/watch?v=WiefMpqCd1o
http://javapapers.com/core-java/java-annotations/
No comments:
Post a Comment