File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Metadata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Metadata" Watch "Metadata" New topic


rama murthy
Ranch Hand

Joined: Jan 13, 2006
Posts: 82

With the advent of annotations in Java 5 -which are a generic mechanism of adding metadata to a class-, marker interfaces have become obsolete, and no new ones should be defined.

When I was learning marker interface I came across this quote from javaranch FAQ. I want to know what metadata is?
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
metadata is data about data.
In this case some indicator of what a class is to replace a marker interface.

IMO that's very dirty indeed, and a marker interface a cleaner way to work.
But then I consider the type of something to be code rather than data and mixing code with data (which the use of annotations more often than not is) to be evil incarnate.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Metadata is information that describes the properties of something (a class, member variable, method, etc.).

In Java, there have been several ad-hoc ways of specifying metadata in the past. Marker interfaces are one example, the "transient" keyword is another.

Normally, when a class implements an interface, it tells you something about the data type of instances of the class - it's the normal "is a" relationship that you have with inheritance. For example, if your class implements Runnable, then your object is a Runnable.

With marker interfaces, the inheritance mechanism is abused to specify metadata. For example, if your class implements the marker interface Serializable, it doesn't mean that your object is a Serializable. (The whole sentence "this object is a Serializable" sounds kind of strange.) Instead, it means that the object has a property; it is Serializable.

In Java 5, annotations were added as a generic way of specifying metadata - now we can use annotations instead of the existing ad-hoc ways to specify properties.

In J2EE, metadata about EJBs is stored separately from the source code, in an XML deployment descriptor. This has some advantages; you're not mixing up source code and deployment configuration information. In the new EJB 3.0 standard, XML deployment descriptors have been replaced (or amended by, because you can still use XML deployment descriptors if you want) by annotations. The disadvantage of this is that you're mixing up code and configuration information, the advantage is that you don't have to hack in XML and that you have everything in one place (the source code file).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
A book I quote often, Horstmann C, Cornell G, Core Java 2: Vol II-Advanced Features 7/e, Upper Saddle River, NJ: Prentice-Hall (Sun Microsystems Press) (2004), has this paragraph as its very last page before the index (page 972).
It is easy to use annotations that someone else designed. It is also easy to design an annotation interface. But annotations are useless without tools. Building annotation tools is undeniably complex. The examples that we presented in this chapter give you an idea of the possibilities. and we expect many far more sophisticated tools to emerge inthe future. This chapter has given you background knowledge for evaluating annotation tools, and perhaps has piqued your interest in developing your own tools.

Now, it is 18 months since that was written, so thing smay have changed, but the annotation is still a new feature, and we probably don't yet know how it is to be used to its fullest extent.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

I agree, probably nobody has yet enough experience with annotations, so there aren't any "best practices", patterns or anti-patterns to guide programmers with the use of annotations.

It's a powerful mechanism, which means it can make programming easier, but you can also easily make a mess of your software if you abuse it.
I agree. Here's the link:
subject: Metadata
It's not a secret anymore!