Annotations
Since Java 1.5 there are some useful annotations we can use in our daily tasks.
Annotations provide data about a program that is not part of the program itself.
Annotations are in
1. java.lang (@Deprecated,@Override and @SuppressWarnings. )
2. java.lang.annotations.
Deprecated
A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists.
Compilers warn when a deprecated program element is used. Ex:
new Thread().resume();
new Thread().stop();
new Thread().suspend();
Override
The @Override annotation informs the compiler that the element is meant to override an element declared in a super class.
Ex:
class one{
void show(){}
}
class two extends one{
@Override
void show(){}}
SuppressWarnings The @SuppressWarnings annotation tells the compiler to suppress the warning messages it normally show during compilation time.
EX : import java.util.Date;
public class Main {
@SuppressWarnings(value={"deprecation"})
public static void main(String[] args) {
Date date = new Date(2008, 9, 30);
System.out.println("date = " + date);
} }
In the example above if we don't use @SuppressWarnings annotation the compiler will report that the constructor of the Date class calledabove has been deprecated.
Annotations provide data about a program that is not part of the program itself.
Annotations are in
1. java.lang (@Deprecated,@Override and @SuppressWarnings. )
2. java.lang.annotations.
Deprecated
A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists.
Compilers warn when a deprecated program element is used. Ex:
new Thread().resume();
new Thread().stop();
new Thread().suspend();
Override
The @Override annotation informs the compiler that the element is meant to override an element declared in a super class.
Ex:
class one{
void show(){}
}
class two extends one{
@Override
void show(){}}
SuppressWarnings The @SuppressWarnings annotation tells the compiler to suppress the warning messages it normally show during compilation time.
EX : import java.util.Date;
public class Main {
@SuppressWarnings(value={"deprecation"})
public static void main(String[] args) {
Date date = new Date(2008, 9, 30);
System.out.println("date = " + date);
} }
In the example above if we don't use @SuppressWarnings annotation the compiler will report that the constructor of the Date class calledabove has been deprecated.