Java: Getting Started with Reflection

Java    |    Intermediate
  • 14 videos | 1h 55m 46s
  • Includes Assessment
  • Earns a Badge
Rating 4.3 of 18 users Rating 4.3 of 18 users (18)
Reflection is a popular programming technique that accesses and modifies class and object information at runtime. Reflection is available in many programming languages, but Java has an especially powerful set of reflection APIs that reflect - no pun intended - the emphasis that Java lays on type safety. Learn how to access a Java class object. Use reflection APIs to view class fields, constructors, and methods. Create objects for various built-in classes and use reflection to view the class of an object. Investigate the significance of the fully qualified name of a class and how you can use the .forName() method from the built-in class java.lang.Class. Use this method to obtain variables of primitive types and arrays of differing dimensionality. Then use reflection to access modifiers applied to member fields. Upon completion, you'll be able to use reflection in your Java operations with confidence.

WHAT YOU WILL LEARN

  • Discover the key concepts covered in this course
    Create and set up a basic intellij project to write java code
    Define new classes and instantiate objects of these classes
    Use class handles accessed via reflection to explore properties of classes
    View fields, methods, and their modifiers using reflection
    Examine how you can identify classes from their objects
    Use reflection to identify a variety of classes from objects
  • Get fully qualified names and simple names of classes using their handles
    Investigate how you can get a handle to class objects using just the class name
    Use reflection to identify the modifiers of class members
    Identify anonymous, local, member classes, and interfaces using reflection
    Identify enums, arrays, and primitives using reflection
    Access package information, superclass, and declaring class information
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 2m 19s
    In this video, you’ll learn more about this course and your instructor. In this video, you’ll learn how to access a Java object that represents the class of a Java object. You’ll then move on to the use of Reflection APIs to view the fields, constructors, and methods in a class. You’ll learn to create objects of a variety of built-in classes and use Reflection to view the class of an object. FREE ACCESS
  • 6m 51s
    Here, you’ll watch a demo. You’ll explore the use of reflection in Java. You’ll start at a terminal prompt on a Unix-based system. Then, you’ll switch over from a terminal prompt to IntelliJ. IntelliJ is an extremely powerful and popular Java IDE. You’ll launch IntelliJ and see the sections corresponding to projects, customizations, plugins, and learning IntelliJ. In the Projects tab, you’ll see three options. These allow you to create a new project. FREE ACCESS
  • Locked
    3.  Creating Classes and Instantiating Objects
    7m 1s
    Here, you’ll watch a demo. You’ll begin by writing some code. You’ll see this is in the Employee.java class. Then, you’ll edit this class. You’ll start with an import statement. You’ll need to import java.util.Random. You’ll use this to generate random employee IDs for the objects of our Employee class. Next, you’ll paste in the implementation of this class. This includes a constructor, various getters and setters, the member variables, and the String method. FREE ACCESS
  • Locked
    4.  Extracting Class Information from Objects
    10m 35s
    Here, you’ll watch a demo. You’ll perform some simple operations using Reflection. You already have a class called Employee. You’ve instantiated that class and examined the two objects of the class you created. You’ll build up towards a Reflection. First, you’ll instantiate another object of this class and invoke different member functions on that object. You’ll start by clearing the output. FREE ACCESS
  • Locked
    5.  Viewing Class Fields, Methods, and Their Modifiers
    10m 53s
    Here, you’ll watch a demo. Here, you’ll move to reflection and make use of code to find the various methods, properties, and constructors that a particular object supports. You’ll clear most of the code you’ve already written. You have an import statement, and you’ll import the class java.lang.reflect.Field. In the context of a reflection, Field has a specific meaning. This class is going to represent every field, every member variable contained within a class. FREE ACCESS
  • Locked
    6.  Examining Class Objects for Different Data Types
    9m 43s
    Here, you’ll watch a demo. You’ll continue to explore the Reflection APIs in Java. The starting point for the use of Reflection is getting a handle on the class a particular object belongs to. That class is itself an object of a class and that class is named Class. Onscreen you’ll see the URL to the Java documentation for this class. This is the entry point from which you’ll access Reflection APIs in Java. FREE ACCESS
  • Locked
    7.  Identifying Classes Using Objects
    11m 42s
    Here, you’ll watch a demo. As you’ve learned, every object knows its class. You had variables which were of type list and list is an interface in Java. You’ll explore how different types of objects in Java know their class and how that class can be accessed in different ways. You’ll remember that arrays hold primitive types such as basic ints. This makes arrays different from ArrayLists, which can only hold reference types. FREE ACCESS
  • Locked
    8.  Viewing Fully Qualified Class Names
    8m 37s
    Here, you’ll watch a demo. You’ll continue with the theme of accessing the class of an object. You’ll turn your focus to user-defined classes. First, you’ll clear the contents of your current main class and open up Project Explorer. You’ll see classes that have been added to your project. These classes are called Deliverable, Department, Employee, and Organization. In the code tab at the center of your screen, you’ll see the necessary code.   FREE ACCESS
  • Locked
    9.  Creating Class Handles from Class Names
    9m 11s
    Here, you’ll watch a demo. You’ll see how to get a handle on a class from the name of the class in the form of a string. This is an important bit of functionality. You’ll use it to make runtime decisions about which object you are going to instantiate. Using the technique provided, you’ll instantiate an object of that class. FREE ACCESS
  • Locked
    10.  Viewing Modifiers of Class Members
    8m 8s
    Here, you’ll watch a demo. You’ll pick up from where you left off in the last demo. You’ll continue with reflection operations. You’ll see how to query all of the properties of a class object. For instance, its modifiers, whether it's final, public, static, and so on. Here, you’ll set up your classes exactly as you need them. Onscreen, you’ll see the organization class, which has been marked final. This means it cannot be extended. FREE ACCESS
  • Locked
    11.  Anonymous, Local, Member Classes, and Interfaces
    11m 40s
    Here, you’ll watch a demo. You’ll learn about other kinds of metadata that you might want to query. For instance, you’ll learn about type parameters, whether a class is an anonymous or an inner class, and so on. First, you’ll clear the contents of the main method and then open up the Project Explorer. The Project Explorer provides you with a sense of the different files and the directory structure. FREE ACCESS
  • Locked
    12.  Identifying Enums, Arrays, and Primitives
    4m 34s
    Here, you’ll watch a demo. In this demo, you’ll continue exploring metadata. You’ll start with enumerated types also known as enums. First, you’ll clear the contents of your Main method and then introduce our enum Weekday. You’ll see that enum is the keyword and it’s followed by the name of the enumerator type, that's Weekday. Then, within curly braces, you have the acceptable values for variables of this enum. FREE ACCESS
  • Locked
    13.  Viewing Class Package, Superclass, Declaring Class
    11m 57s
    Here, you’ll watch a demo. You’ll turn your attention to type parameters and package information. You’ll clear the code. Then, you’ll reintroduce your private static final class HR. This extends Department. Department is an abstract class contained within the same package which is com.skillsoft.reflection. You’ll declare an exception using the throws keyword in the definition of the public static void main method. FREE ACCESS
  • Locked
    14.  Course Summary
    2m 35s
    In this video, you’ll summarize what you’ve learned in this course. You’ve learned how to access a Java object that represents the class of that Java object using the .getClass method. You explored the use of various Reflection APIs to view the fields, constructors, and methods in a class. You created objects of a variety of built-in classes and used Reflection to view the class of an object. 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.

YOU MIGHT ALSO LIKE

Rating 3.7 of 11 users Rating 3.7 of 11 users (11)
Rating 4.5 of 84 users Rating 4.5 of 84 users (84)
Rating 4.7 of 84 users Rating 4.7 of 84 users (84)

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.3 of 47 users Rating 4.3 of 47 users (47)
Rating 4.5 of 36 users Rating 4.5 of 36 users (36)
Rating 4.3 of 63 users Rating 4.3 of 63 users (63)