{"id":3426,"date":"2012-11-20T10:00:31","date_gmt":"2012-11-20T08:00:31","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=3426"},"modified":"2012-11-20T10:38:33","modified_gmt":"2012-11-20T08:38:33","slug":"java-annotations-tutorial-with-custom-annotation","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html","title":{"rendered":"Java Annotations Tutorial with Custom Annotation"},"content":{"rendered":"<p><a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/java\/javaOO\/annotations.html\">Java Annotations<\/a> provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java annotations, how to <strong>write custom annotation<\/strong>, annotations usage and how to <strong>parse annotations<\/strong> using reflection.<\/p>\n<p>Annotations are introduced in Java 1.5 and now it\u2019s heavily used in Java frameworks like Hibernate, <a href=\"http:\/\/www.journaldev.com\/498\/rest-using-jersey-complete-tutorial-with-jaxb-exception-handling-and-client-program\">Jersey<\/a>, Spring. Annotation is metadata about the program embedded in the program itself. It can be parsed by the annotation parsing tool or by compiler. We can also specify annotation availability to either compile time only or till runtime also.<\/p>\n<p>Before annotations, program metadata was available through java comments or by javadoc but annotation offers more than that. It not only contains the metadata but it can made it available to runtime and annotation parsers can use it to determine the process flow. For example, in <a href=\"http:\/\/www.journaldev.com\/498\/rest-using-jersey-complete-tutorial-with-jaxb-exception-handling-and-client-program\">Jersey webservice<\/a> we add PATH annotation with URI string to a method and at runtime jersey parses it to determine the method to invoke for given URI pattern.<\/p>\n<p><strong>Creating Custom Annotations in Java<\/strong><\/p>\n<p>Creating custom annotation is similar to writing an interface, except that it interface keyword is prefixed with <strong><em>@<\/em><\/strong> symbol. We can declare methods in annotation. Let\u2019s see annotation example and then we will discuss it\u2019s features.<\/p>\n<pre class=\" brush:java\">package com.journaldev.annotations;\r\n\r\nimport java.lang.annotation.Documented;\r\nimport java.lang.annotation.ElementType;\r\nimport java.lang.annotation.Inherited;\r\nimport java.lang.annotation.Retention;\r\nimport java.lang.annotation.RetentionPolicy;\r\nimport java.lang.annotation.Target;\r\n\r\n@Documented\r\n@Target(ElementType.METHOD)\r\n@Inherited\r\n@Retention(RetentionPolicy.RUNTIME)\r\npublic @interface MethodInfo{\r\n\tString author() default 'Pankaj';\r\n\tString date();\r\n\tint revision() default 1;\r\n\tString comments();\r\n}<\/pre>\n<ul>\n<li>Annotation methods can\u2019t have parameters.<\/li>\n<li>Annotation methods return types are limited to primitives, String, Enums, Annotation or array of these.<\/li>\n<li>Annotation methods can have default values.<\/li>\n<li>Annotations can have meta annotations attached to them. Meta annotations are used to provide information about the annotation. There are four types of meta annotations:\n<ol>\n<li><strong>@Documented<\/strong> \u2013 indicates that elements using this annotation should be documented by javadoc and similar tools. This type should be used to annotate the declarations of types whose annotations affect the use of annotated elements by their clients. If a type declaration is annotated with Documented, its annotations become part of the public API of the annotated elements.<\/li>\n<li><strong>@Target<\/strong> \u2013 indicates the kinds of program element to which an annotation type is applicable. Some possible values are TYPE, METHOD, CONSTRUCTOR, FIELD etc. If Target meta-annotation is not present, then annotation can be used on any program element.<\/li>\n<li><strong>@Inherited<\/strong> \u2013 indicates that an annotation type is automatically inherited. If user queries the annotation type on a class declaration, and the class declaration has no annotation for this type, then the class\u2019s superclass will automatically be queried for the annotation type. This process will be repeated until an annotation for this type is found, or the top of the class hierarchy (Object) is reached.<\/li>\n<li><strong>@Retention<\/strong> \u2013 indicates how long annotations with the annotated type are to be retained. It takes RetentionPolicy argument whose Possible values are SOURCE, CLASS and RUNTIME<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\n<strong>Java Built-in Annotations<\/strong><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Java Provides three built-in annotations.<\/p>\n<ol>\n<li><strong>@Override<\/strong> \u2013 When we want to override a method of Superclass, we should use this annotation to inform compiler that we are overriding a method. So when superclass method is removed or changed, compiler will show error message.<\/li>\n<li><strong>@Deprecated<\/strong> \u2013 when we want the compiler to know that a method is deprecated, we should use this annotation. Java recommends that in javadoc, we should provide information for why this method is deprecated and what is the alternative to use.<\/li>\n<li><strong>@SuppressWarnings<\/strong> \u2013 This is just to tell compiler to ignore specific warnings they produce, for example using raw types in generics. It\u2019s retention policy is SOURCE and it gets discarded by compiler.<\/li>\n<\/ol>\n<p>Let\u2019s see a java example showing use of built-in annotations as well as use of custom annotation created by us in above example.<\/p>\n<pre class=\" brush:java\">package com.journaldev.annotations;\r\n\r\nimport java.io.FileNotFoundException;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\npublic class AnnotationExample {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t}\r\n\r\n\t@Override\r\n\t@MethodInfo(author = 'Pankaj', comments = 'Main method', date = 'Nov 17 2012', revision = 1)\r\n\tpublic String toString() {\r\n\t\treturn 'Overriden toString method';\r\n\t}\r\n\r\n\t@Deprecated\r\n\t@MethodInfo(comments = 'deprecated method', date = 'Nov 17 2012')\r\n\tpublic static void oldMethod() {\r\n\t\tSystem.out.println('old method, don't use it.');\r\n\t}\r\n\r\n\t@SuppressWarnings({ 'unchecked', 'deprecation' })\r\n\t@MethodInfo(author = 'Pankaj', comments = 'Main method', date = 'Nov 17 2012', revision = 10)\r\n\tpublic static void genericsTest() throws FileNotFoundException {\r\n\t\tList l = new ArrayList();\r\n\t\tl.add('abc');\r\n\t\toldMethod();\r\n\t}\r\n\r\n}<\/pre>\n<p>I believe example is self explanatory and showing use of annotations in different cases.<\/p>\n<p><strong>Java Annotations Parsing<\/strong><\/p>\n<p>We will use Reflection to parse java annotations from a class. Please note that Annotation Retention Policy should be <em>RUNTIME<\/em> otherwise it\u2019s information will not be available at runtime and we wont be able to fetch any data from it.<\/p>\n<pre class=\" brush:java\">package com.journaldev.annotations;\r\n\r\nimport java.lang.annotation.Annotation;\r\nimport java.lang.reflect.Method;\r\n\r\npublic class AnnotationParsing {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\ttry {\r\n\t\t\tfor (Method method : AnnotationParsing.class\r\n\t\t\t\t\t.getClassLoader()\r\n\t\t\t\t\t.loadClass(('com.journaldev.annotations.AnnotationExample'))\r\n\t\t\t\t\t.getMethods()) {\r\n\t\t\t\t\/\/ checks if MethodInfo annotation is present for the method\r\n\t\t\t\tif (method\r\n\t\t\t\t\t\t.isAnnotationPresent(com.journaldev.annotations.MethodInfo.class)) {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\/\/ iterates all the annotations available in the method\r\n\t\t\t\t\t\tfor (Annotation anno : method.getDeclaredAnnotations()) {\r\n\t\t\t\t\t\t\tSystem.out.println('Annotation in Method ''\r\n\t\t\t\t\t\t\t\t\t+ method + '' : ' + anno);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tMethodInfo methodAnno = method\r\n\t\t\t\t\t\t\t\t.getAnnotation(MethodInfo.class);\r\n\t\t\t\t\t\tif (methodAnno.revision() == 1) {\r\n\t\t\t\t\t\t\tSystem.out.println('Method with revision no 1 = '\r\n\t\t\t\t\t\t\t\t\t+ method);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t} catch (Throwable ex) {\r\n\t\t\t\t\t\tex.printStackTrace();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} catch (SecurityException | ClassNotFoundException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n\r\n}<\/pre>\n<p>Output of the above program is:<\/p>\n<pre class=\" brush:bash\">Annotation in Method 'public java.lang.String com.journaldev.annotations.AnnotationExample.toString()' : @com.journaldev.annotations.MethodInfo(author=Pankaj, revision=1, comments=Main method, date=Nov 17 2012)\r\nMethod with revision no 1 = public java.lang.String com.journaldev.annotations.AnnotationExample.toString()\r\nAnnotation in Method 'public static void com.journaldev.annotations.AnnotationExample.oldMethod()' : @java.lang.Deprecated()\r\nAnnotation in Method 'public static void com.journaldev.annotations.AnnotationExample.oldMethod()' : @com.journaldev.annotations.MethodInfo(author=Pankaj, revision=1, comments=deprecated method, date=Nov 17 2012)\r\nMethod with revision no 1 = public static void com.journaldev.annotations.AnnotationExample.oldMethod()\r\nAnnotation in Method 'public static void com.journaldev.annotations.AnnotationExample.genericsTest() throws java.io.FileNotFoundException' : @com.journaldev.annotations.MethodInfo(author=Pankaj, revision=10, comments=Main method, date=Nov 17 2012)<\/pre>\n<p>That\u2019s all for the java annotation tutorial, I hope you learned something from it.<br \/>\n&nbsp;<\/p>\n<p><strong><em>Reference: <\/em><\/strong><a href=\"http:\/\/www.journaldev.com\/721\/java-annotations-tutorial-with-custom-annotation-example-and-parsing-using-reflection\">Java Annotations Tutorial with Custom Annotation Example and Parsing using Reflection<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Pankaj Kumar at the <a href=\"http:\/\/www.journaldev.com\/\">Developer Recipes<\/a> blog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java annotations, how to write custom annotation, annotations usage and how to parse annotations using reflection. Annotations are introduced in Java 1.5 and now it\u2019s heavily used in Java frameworks &hellip;<\/p>\n","protected":false},"author":26,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[343],"class_list":["post-3426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-annotations"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java Annotations Tutorial with Custom Annotation<\/title>\n<meta name=\"description\" content=\"Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Annotations Tutorial with Custom Annotation\" \/>\n<meta property=\"og:description\" content=\"Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/JournalDev\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-20T08:00:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-11-20T08:38:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Pankaj Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/journaldev\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pankaj Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html\"},\"author\":{\"name\":\"Pankaj Kumar\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/4e0e33e2f8fd3dcdb0b5239f79fdddc0\"},\"headline\":\"Java Annotations Tutorial with Custom Annotation\",\"datePublished\":\"2012-11-20T08:00:31+00:00\",\"dateModified\":\"2012-11-20T08:38:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html\"},\"wordCount\":701,\"commentCount\":15,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Annotations\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html\",\"name\":\"Java Annotations Tutorial with Custom Annotation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2012-11-20T08:00:31+00:00\",\"dateModified\":\"2012-11-20T08:38:33+00:00\",\"description\":\"Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/11\\\/java-annotations-tutorial-with-custom-annotation.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java Annotations Tutorial with Custom Annotation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/4e0e33e2f8fd3dcdb0b5239f79fdddc0\",\"name\":\"Pankaj Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2f858dbb96781814cab524da3bfeeecf59a9327a985d0d8d35f20ba80b964586?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2f858dbb96781814cab524da3bfeeecf59a9327a985d0d8d35f20ba80b964586?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2f858dbb96781814cab524da3bfeeecf59a9327a985d0d8d35f20ba80b964586?s=96&d=mm&r=g\",\"caption\":\"Pankaj Kumar\"},\"sameAs\":[\"http:\\\/\\\/www.journaldev.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/JournalDev\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/journaldev\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Pankaj-Kumar\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Annotations Tutorial with Custom Annotation","description":"Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html","og_locale":"en_US","og_type":"article","og_title":"Java Annotations Tutorial with Custom Annotation","og_description":"Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java","og_url":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/JournalDev","article_published_time":"2012-11-20T08:00:31+00:00","article_modified_time":"2012-11-20T08:38:33+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Pankaj Kumar","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/journaldev","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Pankaj Kumar","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html"},"author":{"name":"Pankaj Kumar","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/4e0e33e2f8fd3dcdb0b5239f79fdddc0"},"headline":"Java Annotations Tutorial with Custom Annotation","datePublished":"2012-11-20T08:00:31+00:00","dateModified":"2012-11-20T08:38:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html"},"wordCount":701,"commentCount":15,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Annotations"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html","url":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html","name":"Java Annotations Tutorial with Custom Annotation","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2012-11-20T08:00:31+00:00","dateModified":"2012-11-20T08:38:33+00:00","description":"Java Annotations provide information about the code and they have no direct effect on the code they annotate. In this tutorial, we will learn about Java","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/11\/java-annotations-tutorial-with-custom-annotation.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Java Annotations Tutorial with Custom Annotation"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/4e0e33e2f8fd3dcdb0b5239f79fdddc0","name":"Pankaj Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2f858dbb96781814cab524da3bfeeecf59a9327a985d0d8d35f20ba80b964586?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2f858dbb96781814cab524da3bfeeecf59a9327a985d0d8d35f20ba80b964586?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2f858dbb96781814cab524da3bfeeecf59a9327a985d0d8d35f20ba80b964586?s=96&d=mm&r=g","caption":"Pankaj Kumar"},"sameAs":["http:\/\/www.journaldev.com\/","https:\/\/www.facebook.com\/JournalDev","https:\/\/x.com\/https:\/\/twitter.com\/journaldev"],"url":"https:\/\/www.javacodegeeks.com\/author\/Pankaj-Kumar"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/3426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=3426"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/3426\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=3426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=3426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=3426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}