Java: Accessing Constructors, Methods, & Fields Using Reflection

Java 15    |    Intermediate
  • 13 videos | 1h 38m 12s
  • Includes Assessment
  • Earns a Badge
Likes 11 Likes 11
Reflective access allows a whole range of operations on objects that may not be permitted when you construct and use objects in the regular manner. This is extremely useful while building frameworks that may need access to the internals of your object. Use this course to extract information and metadata about the constructors in a class and use them, accessed via reflection, to instantiate objects. Access and modify fields or the member variables in an object. Access and invoke the methods defined on a class. Invoke static methods on the class itself and instance methods on specific objects of a class. When you're done, you'll have the ability to use reflection to access and work with all class members, whether they are fields, constructors, or methods.

WHAT YOU WILL LEARN

  • discover the key concepts covered in this course
    access the constructors in a class using reflection
    create objects of a class with handles to constructors
    access member variables of a class and its metadata
    access and update values of fields
    access and update protected and private fields
    access public, private, and protected methods
  • view method parameters, annotations, return types, and exceptions
    view annotations on methods and recall the use of the retention policy
    observe how not all annotations are available at runtime for reflective access
    use method heuristics to identify getters and setters in a class
    invoke and call methods using handles
    summarize the key concepts covered in this course

IN THIS COURSE

  • Playable
    1.  Course Overview
    2m 57s
    In this video, you’ll learn more about your instructor and this course. In this course, you’ll learn how to extract information and metadata about the constructors in a class. You’ll see how the .getConstructors method… FREE ACCESS
  • Playable
    2.  Accessing Constructors Using Reflection
    9m 33s
    Here, you’ll watch a demo. In this demo, you’ll learn to instantiate objects of a given class. First, you’ll examine the Java docs for the class you see mentioned onscreen. These refer to using the reflection API's in… FREE ACCESS
  • Locked
    3.  Creating Objects Using Constructor Handles
    8m 54s
    Here, you’ll watch a demo. You’ll pick up where you left off at the end of the last demo. There, you used the newInstance method on a constructor object. You used that to create an object of a specific class. That code is… FREE ACCESS
  • Locked
    4.  Accessing Field Metadata
    10m 14s
    Here, you’ll watch a demo. You’ll learn more about fields. In the context of a reflection, the term field is used for member variables. Member variables whether private, public, or protected, static or non-static, are all… FREE ACCESS
  • Locked
    5.  Getting and Setting Field Values
    8m 52s
    Here, you’ll watch a demo. Here, you’ll clear up the current contents of your main method and then add in a new import statement that you’ll need. This is java.lang.reflect.Modifier. It allows you to interpret the… FREE ACCESS
  • Locked
    6.  Accessing and Updating Private and Protected Fields
    9m 13s
    Here, you’ll watch a demo. Here, you’ll run the code and examine the output you see onscreen. You can see from the output that initially, your employee object has no real values for any of its fields. Initially, the only… FREE ACCESS
  • Locked
    7.  Accessing Public, Private, and Protected Methods
    8m 36s
    Here, you’ll watch a demo. You’ll work with methods, which are member functions. You’ll begin by importing a specific class. This is a java.lang.reflect.Method. This class contains much of the functionality in the Java… FREE ACCESS
  • Locked
    8.  Viewing Method Parameters, Annotations, and More
    7m 14s
    Here, you’ll watch a demo. You’ll turn your attention to a user-defined class, specifically the employee class, which you now see onscreen. This particular iteration of the employee class is slightly different than in… FREE ACCESS
  • Locked
    9.  Accessing Annotations on Methods
    7m 8s
    Here, you’ll watch a demo. In this demo, you’ll learn how reflection and annotations interact. You’ll begin by importing additional bits of functionality. Onscreen you’ll see you’ve imported… FREE ACCESS
  • Locked
    10.  Recognizing Annotation Runtime Policy Implications
    8m 12s
    Here, you’ll watch a demo. In this demo, you’ll recognize annotation runtime policy implications. You’ll learn the printMethodProperties utility can be very helpful. It provides you with information about any method that… FREE ACCESS
  • Locked
    11.  Identifying Getters and Setters Using Heuristics
    10m 14s
    Here, you’ll watch a demo. In this demo, you’ll move on to another aspect of using reflection to invoke methods on a specific object. This is a logical next step and it's an important operation in real-world uses of… FREE ACCESS
  • Locked
    12.  Invoking Functions Using Reflection
    4m 32s
    Here, you’ll watch a demo. In this demo, you’ll move on to changing the state of an object by invoking the setter methods on that object. First, you’ll add in some additional code. Onscreen, you’ll see you have yet… FREE ACCESS
  • Locked
    13.  Course Summary
    2m 33s
    In this video, you’ll summarize what you’ve learned in this course. You’ve learned how to extract information and metadata about the constructors in a class. You saw how the .get constructors method only returns the… FREE ACCESS

EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE

Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.

Digital badges are yours to keep, forever.