Welcome!

Java Authors: Maureen O'Gara, Liz McMillan, Walter H. Pinson, III, Yakov Werde, Tony Bishop

Related Topics: Java

Java: Article

Three Gems from JavaOne

Three Gems from JavaOne

You may have heard the news that Sun has opened the doors for its employees to start blogging, including the most famous employee, the COO. Blogging obviously isn't new, and many companies have already gran-ted individual users the opportunity to go ahead. However, the open floodgate - simply to fill in your details on a Web page, press a button, and start posting - is proving an interesting challenge.

One item that has created some debate is what happens to the useful information after it gets posted and how can we prevent it from being lost forever. It's only human to discard most of a day's events, what we read and what we heard. How do we remember what is important and then how can we apply that to something like a sea of RSS-distributed content?

With that thought in place, and with the JavaOne conference now becoming a distant memory for me, I wanted to spend a little time this month walking through some of the Tiger features announced at JavaOne that didn't have a dedicated session. Features that perhaps are long forgotten or were missed in the first place.

APT
The first feature is a new tool in the Java Developer Kit called the Annotation Processing Tool (APT). APT is used to manipulate annotation tags defined by JSR 175. One way to think about annotations is to compare them to some of the original metadata-like tags in J2SE such as the @deprecated Javadoc tag. When put inside a Java comment, the Javadoc tool and Javac tools understood the @deprecated tag and had rules for what to do with one when they came across it. In the deprecation example the Javac tool would generate a compiler warning and the Javadoc tool would generate some special HTML text.

The new annotation API uses the @interface keyword to define a new annotation and allows you to specify properties to represent that annotation. In the case of the @deprecated example, one property could be the release number that the deprecation first appeared in. Then every time you used the @deprecated annotation you could supply the release as one of the properties, for example, @deprecated ( 1.4 ) mymethod().

How does this reduce boilerplate code and make developers' lives easier? This is where the APT tool comes in. The tool and its associated API can parse Java source files looking for Java annotations. By registering annotation processors with the tool, an annotation processor, which is simply a class that has a process method, can generate custom rules for each annotation. The annotation processor could be a very simple Javadoc-like tool that generates text output displaying the properties of the annotation it is parsing. The more advanced annotation processor could generate new code and the API could provide access to a Filer class that can help generate that boilerplate code in a new class, which is then passed to the Javac compiler.

For most users the developer tools are already gearing up for annotation and processing support so that the only task left for the user is to add the annotation and let the tool take care of the rest.

Diagnostics
We have a great monitoring article in the JDJ pipeline that will explain how you can now get low-memory alerts using JMX or SNMP technology and delve into the monitoring and management frameworks. However, there are also several small tools in the reference implementation that can be used to help track down simple issues.

One such tool is called jps. jps -l will list all the J2SE 5.0 reference JVMs running on that machine, which is especially useful on older Linux releases. The JVM ID or pro-cess ID that is returned from jps can then be used by other diagnostic or debug tools. Another new tool is jstack, which can generate a stack trace on a running JVM. If you supply the jstack -m option, Java and native code will be listed in your stack trace. Look for other tools like jmap and jinfo to provide further diagnostic information.

You can even generate a stack trace from your own program with-out having to throw and catch an exception. This is achieved with the new stack trace API; the easiest way to use it is to call Thread.getAllStackTraces() and then simply read the output.

Java Plugin
The final feature I want to shine a spotlight on is one of the small improvements to the Java Plugin. When you load an applet, the default color for the background is dull gray. In 1.4.2 a tiny coffee cup icon was placed in the corner of that gray background. In 5.0 the first step in launching an applet is to display the coffee cup logo on a white background with a rotating clock-wise swirl. It also displays a progress bar tracking the classes that are being loaded. It not only looks better but gives download feedback to end users.

If you have heard of these three features before, I hope this was a useful reminder. If you're new to them, look out for future coverage in JDJ. On that note, a big thank you to everyone who has submitted J2SE 5.0 article proposals. As a JDJ reader I'm really looking forward to seeing the finished articles come through.

More Stories By Calvin Austin

A section editor of JDJ since June 2004, Calvin Austin is an engineer at SpikeSource.com. He previously led the J2SE 5.0 release at Sun Microsystems and also led Sun's Java on Linux port.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Hans Loedolff 09/09/04 10:44:18 AM EDT

Misleading intro! I thought you were going to tel me "How to remember what is important and then how can we apply that to something like a sea of RSS-distributed content?"