Java 8 Fundamentals: The Java Reflection API Method Handles
The Reflection API brings class and object introspection to Java, on top of which Spring and Hibernate are built. This course covers object creation, field modification, and method invocation.
What you'll learn
As a Java developer, mastering the reflection API allows you to build powerful frameworks that will bring advanced functionalities to your application. In this course, Java Fundamentals: The Java 8 Reflection API Method Handles, you will learn how you can use reflection API efficiently. This API is very technical, so this course is organized around the study of two real-life use cases: the building of an Object Relational Mapper, on the model of Hibernate, and the creation of a dependency injection framework, on the model of Spring. First, you will understand how to introspect classes and objects and how to discover their structure. Next, you will learn how to build objects without knowing their class at compile time, to set values to their fields and to invoke their methods. Finally, you will understand the performance issues of this API, and be able to use method handles and var handles to fix these issues. By the end of this course, you will be able to master the reflection API that will help you in creating performant and versatile Java applications.
Table of contents
- Version Check 0m
- Introduction to the Course, What Are You Going to Learn? 3m
- Who Are You? What Should You Know to Follow This Course? 1m
- Agenda of the Course 2m
- Agenda of This Module 1m
- Introducing the Java Reflection API: Class, Field, and Method 2m
- Introducing the Class Named Class, Getting an Instance of Class 2m
- Getting a Class Instance Using the Object.getClass() Method 3m
- Getting a Class Instance from the Name of the Class 3m
- Wrapping up the Three Patterns to Get a Class Object 1m
- Getting the Super Class and the Implemented Interfaces of a Class 2m
- Getting the Declared and Non Declared Fields of a Class 4m
- Getting the Methods and the Constructors of a Class 3m
- Reading the Modifier to Tell if a Class Member Is Public 4m
- Demo: Using the Reflection API to Read Fields and Methods 7m
- Module Wrap Up 1m
- Introduction to the Module and Agenda 1m
- Introducing the Mapping of Objects to Databases, XML, and JSON 1m
- Creating a Metamodel by Adding Annotations to Fields 2m
- Using the Reflection API to Read and Write a Field of an Object 4m
- Making a Field Accessible to Reading from Outside its Class 3m
- Designing an EntityManager for Reading and Writing to a Database 2m
- Demo: Designing a Generic Metamodel 3m
- Demo: Adding Application Specific Annotations to a Bean 2m
- Demo: Setting the Retention Policy of an Annotation 2m
- Demo: Implementing the Generic Metamodel 3m
- Demo: Running the Generic Metamodel 2m
- Module Wrap Up 1m
- Introduction to the Module and Agenda 1m
- Introducing the Database Server and the Person Bean 2m
- Demo: Setting up the Project and Its Dependencies 2m
- Demo: Runnning the H2 Server and Launching SQL Requests 4m
- Demo: Writing the Pattern to Create and Persist Person Instances 2m
- Demo: Creating and Implementing the EntityManager Interface 4m
- Demo: Building the SQL Query to Insert a Person Bean 5m
- Demo: Preparing the Statement to Execute the Query 4m
- Demo: Setting the Primary Key Value to the Insert Statement 4m
- Demo: Setting the Field Values to the Statement 4m
- Demo: Running the EntityManager to Persist Person Instances 3m
- Demo: Creating the Find Pattern and the Select Query 3m
- Demo: Setting the Primary Key Value to the Select Statement 2m
- Demo: Creating an Instance of the Object Read from the Database 2m
- Demo: Setting the Primary Key Value to the Object 2m
- Demo: Setting the Column Values and Reading the Objects 3m
- Demo: Creating an EntityManager Specific to a Database 3m
- Demo: Closing Properly the PreparedStatement and ResultSet 1m
- Demo: Specifying the Mapping through the Annotations 4m
- Module Wrap Up 2m
- Introduction to the Module and Agenda 2m
- Applying Dependency Inversion Using Dependency Injection 2m
- Designing an EntityManager Independent of the Database 2m
- Designing a BeanManager to Perform Dependency Injection 4m
- Getting and Invoking Methods Using the Reflection API 3m
- Demo: Preparing the Project for Dependency Injection 2m
- Demo: Updating the EntityManager with Dependency Injection 3m
- Demo: Creating the BeanManager to Create the EntityManager 2m
- Demo: Associating Types to Creation Recipes in the BeanManager 6m
- Demo: Injecting the Connection Value to Provide the EntityManager 4m
- Module Wrap Up 1m
- Introduction to the Module and Agenda 1m
- Spotting Security Checks While Calling Reflection Code 2m
- Introducing MethodHandles VarHandle and the Lookup Object 2m
- Getting a Private Trusted Lookup Object 1m
- Using a Method Handle to Get a Reference on a Class 1m
- Creating MethodType Object to Get a Reference on a Method 3m
- Getting a Method Handle on a Method or a Constructor 2m
- Getting a Method Handle to Read and Write a Field 3m
- Using a Method Handle to Invoke a Method of a Class 2m
- Accessing Public and Private Fields Using Method Handles 5m
- Adding Concurrent Field Access Using the VarHandle API 2m
- Using VarHandle to Gain Concurrent Access to Fields 2m
- Demo: Creating Person Beans Using Method Handles on Constructors 4m
- Demo: Invoking Methods Using Method Handles 2m
- Demo: Reading and Writing Private Fields Using Method Handles 3m
- Course Wrap Up 3m