Skip to main content

Posts

Showing posts from May, 2016

Annotations

What’s the use of Annotations? 1) Instructions to the compiler : There are three built-in annotations available in Java ( @Deprecated ,  @Override  &  @SuppressWarnings ) that can be used for giving certain instructions to the compiler. For example the @override annotation is used for instructing compiler that the annotated method is overriding the method. More about these built-in annotations with example is discussed in the next sections of this article. 2) Compile-time instructors : Annotations can provide compile-time instructions to the compiler that can be further used by sofware build tools for generating code, XML files etc. 3) Runtime instructions : We can define annotations to be available at runtime which we can access using  java reflection  and can be used to give instructions to the program at runtime. We will discuss this with the help of an example, later in this same post. Annotations basics An annotation always starts with th...