Within the JVM, you’ll find rich runtime type information about every executing Java program, such as about its class hierarchy. As Ben Evans explains, the details of the hierarchy are contained in the class files, because each individual class refers to the types it depends upon.
The JVM, during the class loading process, assembles this data into a representation of a graph that describes the class inheritance and interface implementation of every type in the system. This includes JDK types, third-party libraries, and custom, user-defined classes of the application.
This inheritance metadata is always present for every type. And guess what? The good news is that your program can access and leverage that runtime metadata, leading to reflective programming that lets you solve interesting problems in an interesting way.
Effectively, with reflection, you write Java source code that composes and prepares code written for the JVM’s low-level, dynamically typed environment.
Take care, Alan Zeichick Editor in Chief, Java Magazine @zeichick
P.S. Java 20 is officially here! Links to key resources are included below.
The newest Java Magazine articles
Reflection for the modern Java programmer Reflection can be complicated, but as Ben Evans explains, one way of thinking about reflection is that it’s posing the following question: “What if the JVM exposed the Java application’s runtime metadata (which is guaranteed to exist) and allowed programmers to access and use it during the execution of their programs?”
Java 20 is here: Strengthening Java’s foundation for the future The innovative new enhancements in Java 20 reflect the vision and invaluable efforts the global community has contributed throughout the platform’s existence. Java has never been more relevant as a contemporary language and platform that helps developers improve productivity.
Pseudorandom numbers in Java, Part 1: The Background What is randomness? And how does it relate to Java’s random number generators? Ian Darwin unpacks this subject for software developers who may or may not be mathematics whizzes. He even talks about lava lamps.
Pseudorandom numbers in Java, Part 2: Randomness with Java 17 Java 17 introduced a new interface, java.util.random.RandomGenerator, to consolidate the implementations of existing and new random number generators. Building off the previous article, Ian Darwin explores the latest interface and shows how it works.
Java! Read all about it in these new developer books. Ready to gain more knowledge about Java? Do you want to share the gift of Java knowledge with your colleagues or with aspiring developers? Check out a bunch of recently published or forthcoming titles on a variety of Java-related topics.
Resources from the Java 20 launch
Java 20 was released on March 21. Here are several key resources.
Java Magazine is a deep dive into Java and the JVM. Find detailed explanations about the language and the platform written by experts and members of the Java development team.
Join a quarter of a million subscribers in getting useful, authoritative programming information delivered directly to your inbox.