Home » Annotations » Page 3

Tag Archives: Annotations

How To Process Java Annotations

One of the cool new features of Java 8 is the support for lambda expressions. Lambda expressions lean heavily on the FunctionalInterface annotation. In this post, we’ll look at annotations and how to process them so you can implement your own cool features. Annotations Annotations were added in Java 5. The Java language comes with some predefined annotations, but you ...

Read More »

Java Annotations Tutorial – The ULTIMATE Guide (PDF Download)

EDITORIAL NOTE: In this post, we feature a comprehensive Java Annotations Tutorial. Annotations in Java are a major feature and every Java developer should know how to utilize them. We have provided an abundance of tutorials here at Java Code Geeks, like Creating Your Own Java Annotations, Java Annotations Tutorial with Custom Annotation and Java Annotations: Explored & Explained. We ...

Read More »

Processing Java Annotations Using Reflection

In my previous article covering Java Annotations, I outlined a recent use case and provided you with some examples of custom annotations and how they might be used. In this article, I’m going to take that a step further and give you a few examples of custom annotations and how you would process these custom annotations using the Java Reflection API. ...

Read More »

Creating Your Own Java Annotations

If you’ve been programming in Java and using any one of the popular frameworks like Spring and Hibernate, you should be very familiar with using annotations. When working with an existing framework, its annotations typically suffice. But, have you ever found a need to create your own annotations? Not too long ago, I found a reason to create my own annotations for a ...

Read More »

Use Java annotation deprecated the right way

There is hardly anything more infuriating that seeing a method @Deprecated without a proper documentation. I feel lost. Should I still use the method? Probably that is not the intention of the developer, that is why he/she added the deprecation annotation. Should I use something else? So…. What are the rules using @Deprecated? Rule #1: do Javadoc how not to ...

Read More »

Java Annotations Tutorial with Custom Annotation

Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java annotations, how to write custom annotation, annotations usage and how to parse annotations using reflection. Annotations are introduced in Java 1.5 and now it’s heavily used in Java frameworks like Hibernate, Jersey, Spring. Annotation ...

Read More »

Java Annotations – Retention

Consider a Java annotation: public @interface AnAnnotaton { } A class with this annotation applied on it: @AnAnnotaton class AnAnnotatedClass{ } And a test which checks if this annotation is present on a class: import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import java.lang.annotation.Annotation; import org.junit.Test; public class AnAnnotationTest { @Test public void testAnAnnotation() throws Exception { AnAnnotatedClass anAnnotatedClass = new AnAnnotatedClass(); ...

Read More »

Java Annotations: Explored & Explained

One of the many wonderful features of Java 5 SE is the introduction of the Annotations construct. Annotations are tags that we can insert into our program source code for some tool to process it and make sense out of it. Annotations processing tools generally use Reflection API (of Java 5 SE) to process the code at source level on ...

Read More »

Make your Spring Security @Secured annotations more DRY

spring-interview-questions-answers

Recently a user on the Grails User mailing list wanted to know how to reduce repetition when defining @Secured annotations. The rules for specifying attributes in Java annotations are pretty restrictive, so I couldn’t see a direct way to do what he was asking. Using Groovy doesn’t really help here since for the most part annotations in a Groovy class ...

Read More »