This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes about java annonation. How it is effective on java coding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about java annonation. How it is effective on java coding?" Watch "about java annonation. How it is effective on java coding?" New topic

about java annonation. How it is effective on java coding?

Mohammad Ashrafuddin Ferdousi
Ranch Hand

Joined: Jan 14, 2010
Posts: 111
Hi all,
I want to konw about java annonation feature. How it is effective on java coding and java web application development. please give me some example so that i can clearly understand java annonation.

thanking you
Henry Wong

Joined: Sep 28, 2004
Posts: 20370

Not exactly sure what you mean by "effective". An annotation is merely a way to attach some sort of data to java, sort of like making little notes in the margin of a book, which is where the term annotation comes from.

You define a datastructure, similar to defining an interface. And then you declare (attach) these annotations anywhere you are able to use a java modifier -- a class, a method, or a class or instance variable.

Another java component, can then use reflection to get and use these little notes. For example, the compiler uses annotations to get hints from the programmer on what to do with certain warning conditions. Hibernate uses annotation to get information on how to map a class to a database table (the previous technique of using an XML file, which is harder to keep in sync with the java class, is now optional). Etc.

I don't know how any of these examples can be considered "effective" though.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15037

See Sun's Java Tutorial on annotations to learn about annotations in detail. The starting page gives some reasons why annotations are useful:
Annotations have a number of uses, among them:

  • Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compiler-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
  • Runtime processing — Some annotations are available to be examined at runtime.

  • Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    I agree. Here's the link:
    subject: about java annonation. How it is effective on java coding?
    It's not a secret anymore!