{"id":1655,"date":"2011-03-14T22:28:31","date_gmt":"2011-03-14T16:58:31","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1655"},"modified":"2011-03-14T22:28:31","modified_gmt":"2011-03-14T16:58:31","slug":"introduction-to-annotation-in-java","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/introduction-to-annotation-in-java\/","title":{"rendered":"Introduction to Annotation in JAVA"},"content":{"rendered":"<p>Annotation is the powerful feature provided by JAVA in version 5 (Tiger). <strong>It provides Data about the program to the compiler.<\/strong><br \/>\nBy Convention,<strong> Annotation comes first on its line<\/strong>.<br \/>\nExample:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n *\n * @author jitendra Zaa\n * @version 1.0.5\n *\n *\/\npublic class TestAnnotations\n<\/pre>\n<p><!--more-->If there is just one element named &#8220;value,&#8221; then the name may be omitted, as in:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@SuppressWarnings(&quot;unchecked&quot;)\npublic void display()\n<\/pre>\n<p>Also, if an annotation has no elements, the parentheses may be omitted, as in:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@Override\npublic void display()\n<\/pre>\n<p><strong>Annotations used by the Java Compiler:<\/strong><\/p>\n<p><strong><\/strong>There are basically three types of the annotations used by the Java Compiler:<\/p>\n<p><strong>@Deprecated :<\/strong><br \/>\nThe @Deprecated  annotations indicates compiler that the marked class, method or field is deprecated and should not be used. Compiler will generate warning message for that element. In eclipse it is displayed by the strikethrough font, indicating that the element is depreacted. While commenting the deprecated element its javadoc comment should also be start with symbole &#8220;@&#8221;\u009d.Also, note that <strong>the Javadoc tag starts with a lowercase &#8220;d&#8221; and the annotation starts with an uppercase &#8220;D&#8221;.<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/\/ Javadoc comment follows\n    \/**\n     * @deprecated\n     * It should not be used, it causes performance issue, better method is\n     * added.\n     *\/\n    @Deprecated\n    static void deprecatedMethod() { }\n}\n<\/pre>\n<p><strong>@Override:<\/strong><br \/>\nThis annotation means that the element is intended to override the superclass element. The advantage of using this annotation is that it will avoid the any typing error (Spelling Mistakes) while overriding the method. If method marked with this annotation does not override the super class method then compiler generates an error.<br \/>\nExample:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@Override\npublic void display()\n<\/pre>\n<p><strong>@SuppressWarning :<\/strong><br \/>\nThis annotation specifies compiler to suppress the particular warning.<br \/>\nExample:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@SuppressWarnings(&quot;deprecation&quot;)\n    void display() {\n        ...\n    }\n<\/pre>\n<p>Every compiler warning belongs to a category. The Java Language Specification lists two categories: <strong>&#8220;deprecation&#8221; and &#8220;unchecked&#8221;<\/strong>.<\/p>\n<p>To suppress more than one warning, use:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n@SuppressWarnings({&quot;unchecked&quot;, &quot;deprecation&quot;})\n<\/pre>\n<p>Java Documentation and Tutorial:<br \/>\nhttp:\/\/download.oracle.com\/javase\/tutorial\/java\/javaOO\/annotations.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to Annotation in JAVA<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[3],"tags":[36],"class_list":["post-1655","post","type-post","status-publish","format-standard","hentry","category-java","tag-annotation"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1676,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/meta-annotation-annotate-other-annotation\/","url_meta":{"origin":1655,"position":0},"title":"Meta Annotation &#8211; annotate other annotation","author":"Jitendra","date":"March 16, 2011","format":false,"excerpt":"What is Meta Annotation and its usage in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Inbuilt Annotation and Meta Annotations in JAVA","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Inbuilt-Annotation-and-Meta-Annotations-in-JAVA.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1683,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/reading-and-writing-custom-annotation\/","url_meta":{"origin":1655,"position":1},"title":"Reading and Writing Custom Annotation","author":"Jitendra","date":"March 16, 2011","format":false,"excerpt":"Article on Reading and Writing Custom Annotation with example","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1959,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/servlet\/create-servlet-using-annotation\/","url_meta":{"origin":1655,"position":2},"title":"Create Servlet using Annotation &#8211; Servlet 3.0","author":"Jitendra","date":"April 13, 2011","format":false,"excerpt":"Create the Servlet without any deployment descriptor. Using Annotations","rel":"","context":"In &quot;Servlet&quot;","block_context":{"text":"Servlet","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/servlet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1851,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/dynamic-results-in-struts-2\/","url_meta":{"origin":1655,"position":3},"title":"Dynamic Results in Struts 2","author":"Jitendra","date":"March 30, 2011","format":false,"excerpt":"Example and sourcecode of creating Dynamic Results in Struts 2","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1984,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/compile-and-run-java-program-in-package-from-command-line\/","url_meta":{"origin":1655,"position":4},"title":"Compile and run Java program in package from command line","author":"Jitendra","date":"April 14, 2011","format":false,"excerpt":"How to Compile JAVA Program in Package from command line","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Java Directory structure","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/Java-Directory-structure.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1756,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/searching-xml-file-using-dom-parser-of-jaxp\/","url_meta":{"origin":1655,"position":5},"title":"Searching XML File using DOM Parser of JAXP","author":"Jitendra","date":"March 22, 2011","format":false,"excerpt":"Example of Searching XML File using DOM Parser of JAXP","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1655"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1655\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}