{"id":79195,"date":"2020-06-27T09:00:17","date_gmt":"2020-06-27T03:30:17","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79195"},"modified":"2020-06-27T09:00:17","modified_gmt":"2020-06-27T03:30:17","slug":"reflection-in-java","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/","title":{"rendered":"Reflection in Java with Examples"},"content":{"rendered":"<p>In this Java article, we are going to discuss Reflection in Java. Here, we will learn what Java Reflection is and how we can utilize it to get data. We will also look at the advantages and drawbacks of Reflection in Java.<\/p>\n<p>Then we will discuss various methods of the Class that are used in Reflection. Finally we will understand each concept with the sample code using Reflection in Java and Java reflection class.<\/p>\n<h3>What is Reflection in Java?<\/h3>\n<p>Reflection in Java is an API(Application Programming Interface) that is used at runtime to analyze or change classes, methods, and interfaces. It is a process of examining or modifying the run time behavior of a class at run time.<\/p>\n<p>The java.lang.Class is a class that provides many methods that we can use to get metadata of the class and to examine and change the runtime behavior of a class. There are two packages- java.lang and java.lang.reflect that provide classes for Java Reflection.<\/p>\n<p>Some points about Reflection in Java are:<\/p>\n<ul>\n<li>The classes required for reflection in Java are present in the java.lang.reflect package.<\/li>\n<li>Reflection gives us data about the class with the associated objects and the methods for that class.<\/li>\n<li>Through reflection, we can call a method at runtime independent of their access specifier.<\/li>\n<\/ul>\n<h2><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Java-Reflection-Reflection-API.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79239\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Java-Reflection-Reflection-API.jpg\" alt=\"Java Reflection\" width=\"800\" height=\"193\" \/><\/a><\/h2>\n<h3>Where Reflection is used?<\/h3>\n<p>The Reflection API of Java is mainly used in:<\/p>\n<ul>\n<li>Integrated Development Environment(IDEs) such as Eclipse, MyEclipse, NetBeans, etc.<\/li>\n<li>Debugger<\/li>\n<li>Test Tools<\/li>\n<\/ul>\n<h3>java.lang.Class class<\/h3>\n<p>The java.lang.The class performs two essential tasks:<\/p>\n<ul>\n<li>It provides methods to get the metadata of a class at runtime.<\/li>\n<li>It provides methods to examine and change the behavior of the class at runtime.<\/li>\n<\/ul>\n<p><strong>Commonly used methods of the Class class:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public String getName()<\/span><\/td>\n<td><span style=\"font-weight: 400\">returns the name of the class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public static Class forName(String className)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method loads the class and returns the reference of Class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public Object newInstance()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It creates a new object of the class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public boolean isInterface()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks if it is an interface.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public boolean isArray()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks if it is an array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public boolean isPrimitive()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks if it is primitive.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public Class getSuperclass()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It returns the superclass or parent class reference.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public Field[] getDeclaredFields()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It returns the total number of fields in the class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public Method[] getDeclaredMethods()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It returns the total number of methods of the class.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public Method getDeclaredMethod(String name,Class[] parameterTypes)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the method class instance.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">public Constructor[] getDeclaredConstructors()<\/span><\/td>\n<td><span style=\"font-weight: 400\">It returns the total number of constructors of this class.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>How can we get the object of Class class?<\/h3>\n<p>There are three ways to get the object of Class class. They are:<\/p>\n<ul>\n<li>forName() method of Class class.<\/li>\n<li>getClass() method of Object class.<\/li>\n<li>the .class syntax.<\/li>\n<\/ul>\n<p>We will discuss each of the methods with an example:<\/p>\n<h4>1) The forName() method of Class class<\/h4>\n<p>The forName() method loads the class dynamically or at runtime. This method returns the instance of Class class. We should use it only if we know the fully qualified name of the class. We cannot use this name for primitive types.<br \/>\nLet&#8217;s see the example of forName() method to get the instance of the class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Demo {}\nclass Test {\n  public static void main(String args[]) {\n    try {\n      Class c = Class.forName(\"Demo\");\n      System.out.println(c.getName());\n    }\n    catch(Exception e) {\n      System.out.println(e);\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Demo<\/div>\n<h4>2) The getClass() method of Object class<\/h4>\n<p>The getClass() method belongs to the Object class and it returns the instance of Class class. We should use it when we know the type. We can also use it with primitives.<\/p>\n<p>Let us see the example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Demo {}\nclass Test {\n  void printName(Object obj) {\n    Class c = obj.getClass();\n    System.out.println(c.getName());\n  }\n  public static void main(String args[]) {\n    Demo obj = new Demo();\n    Test t = new Test();\n    t.printName(obj);\n  }\n}\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Demo<\/div>\n<h4>3) The .class syntax<\/h4>\n<p>Sometimes, there is a situation when a type is available but there is no instance of the class. In such cases, we can obtain the Class by appending the .class syntax to the name of the type. We can also use this syntax with primitives.<\/p>\n<p>Let us see its example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Demo {\n  public static void main(String args[]) {\n    Class c1 = boolean.class;\n    System.out.println(c1.getName());\n\n    Class c2 = Demo.class;\n    System.out.println(c2.getName());\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">boolean<br \/>\nDemo<\/div>\n<h3>Example of Reflection API to determine the type of object<\/h3>\n<p>Let&#8217;s see the simple example of the reflection API to determine the object type.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Demo {}\n\ninterface MyInterface {}\n\nclass Test {\n  public static void main(String args[]) {\n    try {\n      Class c = Class.forName(\"Demo\");\n      System.out.println(c.isInterface());\n\n      Class c2 = Class.forName(\"MyInterface\");\n      System.out.println(c2.isInterface());\n\n    }\n    catch(Exception e) {\n      System.out.println(e);\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">false<br \/>\ntrue<\/div>\n<h3>Getting Information using Reflection API<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Getting-Information-using-Reflection-API.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79238\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Getting-Information-using-Reflection-API.jpg\" alt=\"Java reflection api\" width=\"624\" height=\"291\" \/><\/a><\/p>\n<p>We can use Reflection to get the information about:<\/p>\n<p><strong>1. Class:<\/strong> The getClass() method gives the name of the class to which an object belongs.<\/p>\n<p><strong>2. Constructors:<\/strong> The getConstructors() method returns all the public constructors of the class to which an object belongs.<\/p>\n<p><strong>3. Methods:<\/strong> The getMethods() method gives all the public methods of the class to which an object belongs.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.lang.reflect.Method;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Constructor;\nclass ReflectionDemo {\n  private String str;\n  public ReflectionDemo() {\n    str = \"Techvidvan Java Tutorial\";\n  }\n  public void method1() {\n    System.out.println(\"\\nThe string is: \" + str);\n  }\n  public void method2(int num1) {\n    System.out.println(\"\\nThe number is: \" + num1);\n  }\n  private void method3() {\n    System.out.println(\"\\nprivate method invoked\");\n  }\n}\npublic class Test {\n  public static void main(String args[]) {\n    ReflectionDemo obj = new ReflectionDemo();\n    Class cls = obj.getClass();\n    System.out.println(\"\\nThe name of the class is: \" + cls.getName());\n\n    Constructor constructor = cls.getConstructor();\n    System.out.println(\"\\nThe name of the constructor is: \" + constructor.getName());\n\n    System.out.println(\"\\nThe public methods of the class are: \");\n    Method[] methods = cls.getMethods();\n\n    for (Method method: methods)\n    System.out.println(method.getName());\n\n    Method methodCall1 = cls.getDeclaredMethod(\"method2\", int.class);\n    methodCall1.invoke(obj, 35);\n    Field field = cls.getDeclaredField(\"str\");\n    field.setAccessible(true);\n    field.set(obj, \"Java\");\n    Method methodCall2 = cls.getDeclaredMethod(\"method1\");\n    methodCall2.invoke(obj);\n    Method methodCall3 = cls.getDeclaredMethod(\"method3\");\n    methodCall3.setAccessible(true);\n    methodCall3.invoke(obj);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">The name of the class is: ReflectionDemo<br \/>\nThe name of the constructor is: ReflectionDemo<br \/>\nThe public methods of the class are:<br \/>\nmethod2<br \/>\nmethod1<br \/>\nwait<br \/>\nwait<br \/>\nwait<br \/>\nequals<br \/>\ntoString<br \/>\nhashCode<br \/>\ngetClass<br \/>\nnotify<br \/>\nnotifyAll<br \/>\nThe number is: 35<br \/>\nThe string is: Java<br \/>\nprivate method invoked<\/div>\n<h3>Getting Interfaces<\/h3>\n<p>We can use the getInterfaces() method of Class to get the information about the interfaces implemented by the class. The getInterfaces() method returns an array of interfaces.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.lang.Class;\nimport java.lang.reflect. * ;\n\ninterface Bike {\n  public void display();\n}\n\ninterface Bicycle {\n  public void makeNoise();\n}\n\nclass TwoWheeler implements Bike,\nBicycle {\n  public void display() {\n    System.out.println(\"I am a bike\");\n  }\n\n  public void makeNoise() {\n    System.out.println(\"I make noise\");\n  }\n}\n\nclass ReflectionDemo {\n  public static void main(String[] args) {\n    try {\n      \/\/create an object of TwoWheeler class\n      TwoWheeler t = new TwoWheeler();\n\n      \/\/create an object of Class using getClass()\n      Class obj = t.getClass();\n\n      \/\/find the interfaces implemented by TwoWheeler\n      Class[] objInterface = obj.getInterfaces();\n      for (Class c: objInterface) {\n        \/\/print the name of interfaces\n        System.out.println(\"Interface Name: \" + c.getName());\n      }\n    }\n    catch(Exception e) {\n      e.printStackTrace();\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Interface Name: Bike<br \/>\nInterface Name: Bicycle<\/div>\n<h3>Getting Superclass and Access Modifier in Java<\/h3>\n<p>We can use the getSuperclass() method of the class Class to get information about the superclass of a particular class. The Class class also provides a method getModifier() that returns the access modifier of class in integer form.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.lang.Class;\nimport java.lang.reflect. * ;\n\ninterface Person {\n  public void display();\n}\n\npublic class Student implements Person {\n  public void display() {\n    System.out.println(\"I am a student.\");\n  }\n}\n\nclass ReflectionDemo {\n  public static void main(String[] args) {\n    try {\n      \/\/create an object of Student class\n      Student s1 = new Student();\n\n      \/\/create an object of Class using getClass()\n      Class obj = s1.getClass();\n\n      \/\/Get the access modifier of Student in integer form\n      int modifier = obj.getModifiers();\n      System.out.println(\"Access Modifier: \" + Modifier.toString(modifier));\n\n      \/\/Find the superclass of Student\n      Class superClass = obj.getSuperclass();\n      System.out.println(\"Superclass: \" + superClass.getName());\n    }\n    catch(Exception e) {\n      e.printStackTrace();\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Access Modifier: public<br \/>\nSuperclass: java.lang.Object<\/div>\n<h3>Advantages of using Java Reflection<\/h3>\n<p><strong>1. Extensibility Features:<\/strong> Reflection allows an application to use user-defined and external classes by creating instances of extensible objects using their fully-qualified names.<\/p>\n<p><strong>2. Debugging and testing tools:<\/strong> Debuggers make use of the property of reflection to detect the private members of a class.<\/p>\n<h3>Disadvantages of using Java Reflection<\/h3>\n<p><strong>1. Performance Overhead:<\/strong> The performance of operations of Reflection is slower than the non-reflective operations. We should avoid the use of reflection in sections of code that we call frequently in performance-sensitive applications.<\/p>\n<p><strong>2. Exposure of Internals:<\/strong> Reflective code violates the concept of abstraction and therefore there may be a change in the behavior with upgrades of the platform.<\/p>\n<h3>Important Observations about Reflection in Java<\/h3>\n<p>1. We can invoke a method through reflection if we know its name and parameter types. We use two methods for this purpose<\/p>\n<p>a<strong>.<\/strong> <strong>getDeclaredMethod():<\/strong> To create an object of the method to be invoked.<br \/>\nThe syntax for this method is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Class.getDeclaredMethod(name, parametertype)<\/pre>\n<p>name- The name of a method whose object is to be created<br \/>\nparametertype- parameter is an array of Class objects<\/p>\n<p><strong>b.<\/strong> <strong>invoke() method:<\/strong> To invoke a method of the class at runtime we use the following method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Method.invoke(Object, parameter)<\/pre>\n<p>If the method of the class doesn\u2019t accept any parameter then null is passed as an argument.<\/p>\n<p><strong>2.<\/strong> We can access the private methods and variables of a class using Reflection. We can access them using its class object, and invoke the method by using the object as discussed above. Two methods are there for this purpose. These methods are:<\/p>\n<p><strong>a. Class.getDeclaredField(FieldName):<\/strong> Returns the private field of the class. It returns an object of type Field for the specified field name.<\/p>\n<p><strong>b. Field.setAccessible(true):<\/strong> Allows accessing the field irrespective of the access modifier used with the field.<\/p>\n<h3>Conclusion<\/h3>\n<p>Hence, in this article, we completely understood the concept of reflection in Java. Moreover, we also discussed classes and methods used for reflection in Java. Along with this, we also discussed the advantages and disadvantages of Java Reflection. We learned how to get the name of the class, interfaces, methods, and constructors of the class. We can easily get the data about the class using the reflection API.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Java article, we are going to discuss Reflection in Java. Here, we will learn what Java Reflection is and how we can utilize it to get data. We will also look at&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79237,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2946,2947,2948,2949],"class_list":["post-79195","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java-reflection","tag-java-reflection-example","tag-java-reflection-tutorial","tag-reflection-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Reflection in Java with Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about Reflection in java with uses &amp; examples, its advantages disadvantages, classes&amp; methods used for reflection in Java, Getting Superclass &amp; Access Modifier\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reflection in Java with Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about Reflection in java with uses &amp; examples, its advantages disadvantages, classes&amp; methods used for reflection in Java, Getting Superclass &amp; Access Modifier\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-27T03:30:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/java-reflection.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reflection in Java with Examples - TechVidvan","description":"Learn about Reflection in java with uses & examples, its advantages disadvantages, classes& methods used for reflection in Java, Getting Superclass & Access Modifier","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:\/\/techvidvan.com\/tutorials\/reflection-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Reflection in Java with Examples - TechVidvan","og_description":"Learn about Reflection in java with uses & examples, its advantages disadvantages, classes& methods used for reflection in Java, Getting Superclass & Access Modifier","og_url":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-27T03:30:17+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/java-reflection.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Reflection in Java with Examples","datePublished":"2020-06-27T03:30:17+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/"},"wordCount":1229,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/java-reflection.jpg","keywords":["Java Reflection","java reflection example","java reflection tutorial","reflection in java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/","url":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/","name":"Reflection in Java with Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/java-reflection.jpg","datePublished":"2020-06-27T03:30:17+00:00","description":"Learn about Reflection in java with uses & examples, its advantages disadvantages, classes& methods used for reflection in Java, Getting Superclass & Access Modifier","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/java-reflection.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/java-reflection.jpg","width":1200,"height":628,"caption":"Reflection in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/reflection-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Reflection in Java with Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79195"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79195\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79237"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}