Posts Tagged ‘Java’

Java Annotations provide Java developers full potential of doing things in more easy and nice way. I will not go explaining Java annotations pros, cons, and the definitions; you can find out here http://java.sun.com/docs/books/tutorial/java/javaOO/annotations.html

instead I will add some piece which I hardly found: how can I write my own Annotation class and make use of them?! here you go:

I will take a simple Beans that Document who wrote some Java class and who reviewed it.


  1. Author, Data Type: String
  2. Reviewers, Data Type: Array of String

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;


public @interface Documentation {

String author();

String [] reviewers() default {};


what have we done? we created a file called Documentation.java that is an interface, and because it’s an annotation it’s written like this @interface

we have add two methods signatures:

  1. author: returns a String.
  2. reviewers: returns an array of string, that is an optional element to mention, so we provided a default value of empty string array (I know you noticed that 😉

a question: what does@Retention(RetentionPolicy.RUNTIME) do? well, it indicates to the JVM that this annotation is intended to be used at runtime, simply.

now, it’s time to introduce the famous Hello World class 😀

import java.lang.annotation.Annotation;

@Documentation(author=”Alex”, reviewers={“Divid”, “Osama”})

public class HelloWorld {

public static void main(String [] args){

System.out.println(“checking documentation for class HelloWorld.java”);

Annotation annotation = HelloWorld.class.getAnnotation(Documentation.class);

if (annotation == null) {

System.out.println(“No Documentation was found for class HelloWorld, exit”);



Documentation doc = (Documentation) annotation;

System.out.println(“author: ” + doc.author());

for (String reviewer : doc.reviewers()) {

System.out.println(“reviewer: ” + reviewer);





what have we done? we created a Java Class called HelloWorld, that uses @Documentation annotation.

we have extracted the informtion provided for this class in @Documentation annotation element.


Read Full Post »

pointing out http://stackoverflow.com/questions/461896 write your experience ….

Read Full Post »

Reading .. Grails

Grails is an open source MVC and full-stack framework, and uses Groovy for views – you have Rails capabilities with Java’s Taste and Capabilities.

super-productivity  – what a framework!

I am now reading Getting Started with Grails, and will be writing some useful, real-world tutorials soon.

Read Full Post »

Today I installed Netbeans 6 and my first Impression is Wow! I will be posting in-depth look at netbeans-6.0 later.

but, what is new on netbeans-6.0?

Editor Improvements

  • Smarter code completion
  • Highlights
  • Better Navigation and Inspection
  • Live Templates and Surround Functionality

Ruby/JRuby/Ruby on Rails Support

  • Project support including Gems and RSpec
  • Advanced Ruby Editing
  • ActiveRecord Code Completion
  • Ruby Debugger
  • Ruby on Rails Support


  • Profiler integrated into NetBeans IDE
  • Compare Memory Snapshots
  • Heap Walker
  • JMeter Integration
  • Dynamic Attach on JDK 1.6

Web and Java EE

  • Built-in visual design for web applications
  • Visual page flow editing
  • Enhanced JavaScript support
  • Enhanced web services support
  • Support for Ajax-enabled JavaServer Faces components


  • New Integrated UI for CLDC/MIDP and CDC development
  • New game builder
  • New Visual Mobile Designer
  • Re-written JSR-172 stub compiler


  • Artifacts for service composition and assembly
  • Graphical WSDL editor
  • XSLT editor to edit transformations.
  • Tooling support for binding components
  • Java EE Web Service project support

Check out NetBeans 6.0 Released with Support for Ruby, Mobility Enhancemens, and Integrated Profiles

Read Full Post »