Friday Jul 20, 2012

Metaprogramming: Manipulating Data About Data

Metaprogramming is the secret behind the success of many Java frameworks such as Spring and Struts 2, and constitutes the backbone of many of the most fundamental APIs across the Java EE technology stack. More importantly, you can use metaprograming for improving your apps and app testing. In his session The Art of Metaprogramming in Java, presented at OSCON, Abdel Remani (@PolymaticCoder) explained the philosophy and theory behind metaprogramming, and then showed code examples illustrating the different mechanisms and techniques developers can use to take advantage of this underused feature of the Java programming language.

Remani started with an overview of metadata. Metadata is "data about data," for example, most people are familiar with HTML meta tags. Javadoc is also an example of metadata. The most common way to generate and display metadata in Java is using annotations. JSR 175 (A Metadata Facility for the Java Language) was introduced in Java SE 5.0, and it standardized how annotations are declared in Java code. JSR 250 introduced Common Annotations for the Java Platform. You can write your own java.lang.annotation package, just tell the Java compiler how the annotations are to be treated, including the element types to be annotated, retention policies, and default values.

Metaprogramming is writing programs that manipulate other programs or themselves based on metadata. One good use case is saving scanned metadata for use later during runtime, allowing for quicker startup of your application. Since there are no commonly defined best practices in the area of metadata, Remani calls this a "big boy's exercise." You can access metaprogramming at runtime via JSR 299, Pluggable Annotation Processing API. He recommends the following steps: 1) Define metadata, 2) Process metadata, 3) Construct a metamodel, and 4) Validate the metamodel.

Here are some of the libraries available to use for metadata processing:


Finally, Ramani introduced Project Averroes. His vision for the project is a metaprogramming framework that provides auto-discovery of annotations, annotation processing, metamodel construction and validation. "It is," he concluded, "a work in progress." Project Averroes is open source, and he welcomes comments and contributions. 


Making the Most of Java's Metadata: Custom Annotations

Thursday Apr 12, 2012

JavaServer Faces 2.0 for the Cloud

A new article now up on otn/java by Deepak Vohra titled “JSF 2.0 for the Cloud, Part One,” shows how JavaServer Faces 2.0 provides features ideally suited for the virtualized computing resources of the cloud. The article focuses on @ManagedBean annotation, implicit navigation, and resource handling. Vohra illustrates how the container-based model found in Java EE 7, which allows portable applications to target single machines as well as large clusters, is well suited to the cloud architecture.

From the article--

“Cloud services might not have been a factor when JavaServer Faces 2.0 (JSF 2.0) was developed, but JSF 2.0 provides features ideally suited for the cloud, for example:
•    The path-based resource handling in JSF 2.0 makes handling virtualized resources much easier and provides scalability with composite components.
•    REST-style GET requests and bookmarkable URLs in JSF 2.0 support the cloud architecture. Representational State Transfer (REST) software architecture is based on transferring the representation of resources identified by URIs. A RESTful resource or service is made available as a URI path. Resources can be accessed in various formats, such as XML, HTML, plain text, PDF, JPEG, and JSON, among others. REST offers the advantages of being simple, lightweight, and fast.
•    Ajax support in JSF 2.0 is integrable with Software as a Service (SaaS) by providing interactive browser-based Web applications.”
In Part Two of the series, Vohra will examine features such as Ajax support, view parameters, preemptive navigation, event handling, and bookmarkable URLs.

Have a look at the article here.


Insider News from the Java Team at Oracle!

javeone logo


« April 2014