Annotations are a metaprogramming facility introduced J2SE 5.0. They allow us to mark code with defined tags. Some developers think that the Java compiler understands the tag and work accordingly. This is not right. The tags actually have no meaning to the Java compiler or runtime itself. There are tools that can interpret these tags. For instance: IDEs, testing tools, profiling tools, and code-generation tools understands these tags.
Why use annotations?
Metadata is beneficial for documentation, compiler checking, and code analysis.
One can use metadata to indicate if methods are dependent on other methods, if they are incomplete, if a certain class must reference another class, and so on. You might be thinking that this can also be done using Javadoc since it provides a fairly easy and robust way to document code. Yes, this is correct but the truth is, there are other benefits associated with metadata.
Metadata is used by the compiler to perform some basic compile-time checking. For example there is a override annotation that lets you specify that a method overrides another method from a superclass. At this, the Java compiler will ensure that the behavior you indicate in your metadata actually happens at a code level as well. This might seem trivial to you but the fact is that many developers have spent long nights trying to discover why their code is not working and later realizing that a method has a parameter wrong, which means that the method is not overriding a method from a superclass.
Another great feature of using annotation is code analysis. A good tool like XDoclet can manage all of these dependencies, ensuring that classes that have no code-level connection, but do have a logic-level tie-in, stay in sync. In this case, metadata is really useful.
Annotations and Annotation type
Wednesday, August 8, 2012
Annotations - metaprogramming facility
Maven
Maven is a Jakarta build project which is used for project management tool and report generation. It is an artifact manager and allows sharing of source code and binaries between projects. Benefits of using Maven are:
Standardization
Reuse across the organization
Dependency management
Plugin architecture
POM
A project is described using POM (Project Object Model) which is written in XML. It defines how to build a project and also defines the external dependencies. The project build results are created in the local repository where as the dependent JARs are downloaded from a remote repository. The Maven functionality is implemented in terms of plugins.
POM contains following:
Java Date
Java.util package is a utility package that contains classes useful for
working with groups of object. It also contains Java Date class. Java
Date class is used to work with dates and times and it allows you to
work with date and time independent of the system.
Date can be created by mentioning the number of milliseconds from the epoch (midnight GMT, January 1st, 1970) or the year, month, date, and, optionally, the hour, minute, and second. Years are specified as the number of years since 1900.
Java Date class has many constructors. If you want the Date to be initialized to the current time and date, you should call Java Date constructor with no arguments. Java Date class has many instance methods tat can be used to get and set the various date and time fields, to compare dates and times, and to convert dates to and from string representations.
If you are using Java 1.1, you should know that many of the date methods have been deprecated. So do read documentation (Java Doc) before using any method.
Java Date class implements Cloneable, Comparable and Serializable interfaces.
I will provide you method summary of Java Date class. You will note that many methods of Date class have been deprecated. It has been largely replaced by the java.util.Calendar class. But still, Java Date class include a few useful methods.
Java Date – Conventions and Representations
Java Date class methods, that accept or return year, month, date, hours, minutes, and seconds values, the following conventions and representations are used:
Date can be created by mentioning the number of milliseconds from the epoch (midnight GMT, January 1st, 1970) or the year, month, date, and, optionally, the hour, minute, and second. Years are specified as the number of years since 1900.
Java Date class has many constructors. If you want the Date to be initialized to the current time and date, you should call Java Date constructor with no arguments. Java Date class has many instance methods tat can be used to get and set the various date and time fields, to compare dates and times, and to convert dates to and from string representations.
If you are using Java 1.1, you should know that many of the date methods have been deprecated. So do read documentation (Java Doc) before using any method.
Java Date class implements Cloneable, Comparable and Serializable interfaces.
I will provide you method summary of Java Date class. You will note that many methods of Date class have been deprecated. It has been largely replaced by the java.util.Calendar class. But still, Java Date class include a few useful methods.
Java Date – Conventions and Representations
Java Date class methods, that accept or return year, month, date, hours, minutes, and seconds values, the following conventions and representations are used:
- A year is represented by the integer y – 2000.
- A month is represented by an integer form 0 to 11; 0 is January, 1 is February, 2 is March, 3 is April, 4 is May, 5 is June, 6 is July, 7 is August, 8 is September, 9 is October, 10 is November and 11 is December.
- A day of month is represented in normal way, by an integer from 1 to 31.
- An hour is represented by an integer from 0 to 23. 12AM is hour 0.
- A minute is represented by an integer from 0 to 59 in the usual manner.
- A second is represented by an integer from 0 to 61. The values 60 and 61 are used for leap calculations.
Enterprise JavaBean 3.0
An Enterprise JavaBean provides reusable, portable J2EE component. It comprises of methods that encapsulate business logic for instance: updating employee data in database can be business logic and it can be in EJBean. The business methods (in EJB) can be invoked by local and remote clients. As an EJBean developer, you have to only focus on business logic that has to be in the bean. Issues like transaction management, clustering, caching, messaging between applications and others are handled by the container.
You must be aware of Plain Old Java Objects (POJOs). EJBeans are developed as POJOs and annotations are used to tell the container how to manage the beans.
Features
Some worth mentioning features of EJBeans 3.0 are listed below:
No need of home and object interface.
No need of any component interface.
Made use of java annotations.
Simplifies APIs to make flexible for bean's environment.
EJB Context
Subscribe to:
Posts (Atom)