This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mohammad Ashrafuddin Ferdousi
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
codeperl
 
Henry Wong
author
Marshal
Pie
Posts: 20992
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Henry


 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic