Recording available for JavaOne CON2013 session – Code Generation in the Java Compiler: Annotation Processors Do the Hard Work

Directly from the pen of the happy panda, the recording for my JavaOne 2014 session on ‘Code Generation in the Java Compiler: Annotation Processors Do the Hard Work’ is finally available for replay at Parsleys site.

The direct link to the session recording is: https://www.parleys.com/talk/code-generation-java-compiler-annotation-processors-do-hard-work

Slides and code examples from JavaOne CON2013 session – Code Generation in the Java Compiler: Annotation Processors Do the Hard Work

The slides for my conference session CON2013 in JavaOne 2014 can be found online here: http://www.slideshare.net/deors/javaone-2014-con2013-code-generation-in-the-java-compiler-annotation-processors-do-the-hard-work

The coding examples can be found on GitHub: https://github.com/deors/deors.demos.annotations

con2013

Speaking at JavaOne 2014 San Francisco!

This year I have been honored to be selected to speak at JavaOne 2014. Awesome news! I’m excited for this opportunity to speak at possibly the larger Java developer conference in the world.

The session that was selected is CON2013: Code Generation in the Java Compiler: Annotation Processors Do the Hard Work. This session is largely based on my work around Annotation Processors as a driver for code generation.

It is really a pleasure to see that what was an experimental work three years ago, matures and get the attention of the JavaOne commitee.

So, if you happen to be at JavaOne, don’t miss the opportunity and come to the session! See you there!

Code Generation using Annotation Processors in the Java language – part 3: Generating Source Code

This post is the third and final part in my series about Code Generation using Annotation Processors in the Java language. In part 1 (read it here) we introduced what Annotations are in the Java language and some of their common uses. In part 2 (read it here) we introduced Annotation Processors, how to build them and how to run them.

Now, in part 3, we are going to show how an Annotation Processor can be used to generate source code.

Continue reading “Code Generation using Annotation Processors in the Java language – part 3: Generating Source Code”

Code Generation using Annotation Processors in the Java language – part 2: Annotation Processors

This post is the second part in my series about Code Generation using Annotation Processors in the Java language. In part 1 (read it here) we introduced what Annotations are in the Java language and some of their common uses.

Now in part 2 we are going to introduce Annotation Processors, how to build them and how to run them.

Code Generation using Annotation Processors in the Java language – part 2: Annotation Processors

Annotations are great, sure. You can set any kind of metadata or configuration with them, with a well defined syntax and different types to use.

From what we have seen until now, annotations have advantages compared with Javadocs but not enough to justify their inclusion into the language. Therefore, is it possible to interact with annotations and get the most from them? Sure it is:

  • At runtime, annotations with runtime retention policy are accessible through reflection. The methods getAnnotation() and getAnnotations() in Class class will do the magic (1).
  • At compile time, Annotation Processors, a specialized type of classes, will handle the different annotations found in code being compiled.

Continue reading “Code Generation using Annotation Processors in the Java language – part 2: Annotation Processors”

Code Generation using Annotation Processors in the Java language – part 1: Annotation Types

With this post I would like to start a series about Code Generation using Annotation Processors in the Java language, how powerful they are, and at the end show how to make use of them to generate source code on compile time.

During the series we will:

  • Introduce what are Annotations in the Java language.
  • Understand the common uses of Annotations and their scopes.
  • Understand what are Annotation Processors and their defined role.
  • Learn how to build Annotation Processors.
  • Learn how to run Annotation Processors from command line, Eclipse and Maven.
  • Learn how to use Annotation Processors to generate source code.
  • Learn how to use Annotation Processors to generate source code using an external template engine as Apache Velocity.

Code Generation using Annotation Processors in the Java language – part 1: Annotation Types

Annotations were first introduced in the Java language with the third edition of the Java Language Specification (1) and first implemented in Java 5.

Using annotations, we are able to add metadata information to our source code – build or deployment information, configuration properties, compilation behavior or quality checks.

Unlike Javadocs, annotations are strong typed, having that any annotation in use has a corresponding Annotation Type defined in the classpath. Besides that, annotations can be defined to be available at run-time – not possible with Javadocs.

Continue reading “Code Generation using Annotation Processors in the Java language – part 1: Annotation Types”