I had been a backstreet crawler...only tried to replace works in NB3.6 with NB4 and felt doomed if failed. Sorry NB4's developpers, you must have crying "Why don't you look at the new features of it ?!"...for example Tiger, JDK5.0. Yes, it's high time to walk in a sunny mainstreet. Don't look back anymore!....or twice a week, if you do.
is my present impression. Anyway I tried it as far as I could.
Metadata works to embed given informations
to a program code in JDK5.0. It was not possible in J2SE1.4 so comments in a
program or separate files as hogehoge.xml were needed to keep those informations.
If you write an other program to deal with those embedded information you can
create new files automatially. IF YOU WRITE. Seems difficult though.
Now let's make a project to test metadata.Create a project for standard Java application. In this article you see the project named "metadata3", because I had tried a few times and failed.
Metadata is written in a Java file. To notice this is describe metadata, a format as follows is used.

This is the content of the file Male.java, describing a very simple metadata.
I confess I don't like to use metahogehoge because
But no other way. Retention was a
metameta data included in the metadata Male. This metameta data means like keep
this Male's information to runtime.
The content of Male is empty. This empty metadata is called "marker"
type. The name "Male" itself is the data, such as ID. I make this
ID to mean
FOR GENT
Unfortunately there is not yet a template for metadata or annotations. I first create an ordinary Java Class file and modified it manually. But you can feel NB4 supports this format because it makes no error, "@" is colored in the source editor...you can see also

Umm, NB4 does know this new feature of Tiger, KNOWs. though not supports explicitly....
Anyway, I made the same kind, Female.java.
package metadata3;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface Female {}
You can see this is "For Ladies."
At last I created a Main program to use these metadata. First declare an inner class :

You can see the description "@Male" at the constructor.
NetBeans enables adding an inner class graphically...

But in this simple case it's not so hard work to write the code manually.
Then the similar inner class Girl...
static class Girl {
String name;
@Female public Girl(String name){
this.name=name;
}
}
and inner class Martian.
static class Martian
{
String name;
public Martian(String name){
this.name=name;
}
}
No metadata were included here.
And then main method:
public static void main(String[] args) {
Main thismain=new Main();
Boy john=new Boy("John");
Girl jane=new Girl("Jane");
Martian someone= new Martian("\\@&%!??");
System.out.println(john.name+thismain.getGender(john.getClass()));
System.out.println(jane.name+thismain.getGender(jane.getClass()));
System.out.println(someone.name+thismain.getGender(someone.getClass()));
}
The main method calls the method "getGender" which takes Class (Boy, Girl...) as a parameter.Method getGender is described:
public String getGender(Class c){
String gender=" is unknown";
try{
Constructor cs=c.getConstructor(String.class);
if (cs.isAnnotationPresent(Male.class)){
gender= "is a gentleman";
}
else if(cs.isAnnotationPresent(Female.class)){
gender= "is a lady";
}
}
catch(Exception e){
System.out.println("An Exception Occurred");
gender=null;}
return gender;
}
Executing this Main class:

There! Information embedded by metadata could be read by other programs. How nice...