Java Lang Reflect Package Tutorial

java.lang.reflect package provides classes and interfaces which are used to obtain reflective information about classes and objects. Reflection API allows programmatic access to information about the fields, methods, and constructors of loaded classes. It allows the use of reflected fields, methods, and constructors to operate on their underlying counterparts, within security restrictions. This reference will take you through simple and practical methods available in java.lang.reflect package.

This tutorial is prepared for the beginners to help them understand the basic functionality related to all the methods available in java.lang.reflect package. If you are new to Java reflection then we suggest you read our top Java Reflection API Tutorial

Let's discuss a list of important commonly used classes and interfaces under java.lang.reflect
package. We explained all the methods with lots of examples from each class and interface. Our suggestion is to do lots of hands experience using this tutorial.

Click on each class will navigate to their respective page.

>> java.lang.reflect Arrays Class

In this article, we will learn how the programmatic access and manipulate Arrays using java.lang.reflect.Array in Java.

>> Java Reflection for Methods

The java.lang.reflect.Method class provides APIs to access information about a method's modifiers, return type, parameters, annotations, and thrown exceptions. It also is used to invoke methods.

>> Java Reflection for Fields

In this article, we will learn how to programmatically access and manipulate fields using Reflection Fields class. A field may be either of primitive or reference type. There are eight primitive types: boolean, byte, short, int, long, char, float, and double. A reference type is anything that is a direct or indirect subclass of java.lang.The object including interfaces, arrays, and enumerated types.

>> Java Reflection for Constructors

In this article, we will learn how to use Reflection Constructors class for creation of an object that is an instance of a class. Typically it performs operations required to initialize the class before methods are invoked or fields are accessed. Constructors are never inherited.

>> Java Reflection for Enums

In this article, we will learn how to apply and programmatically access information about Enums in Java using this class. An enum is a language construct that is used to define type-safe enumerations which can be used when a fixed set of named values is desired. All enums implicitly extend java.lang.Enum.

If you are new to Java reflection then visit our top Java Reflection API Tutorial


Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours

Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course