JEP 484 defines the class file API as a standard way for parsing, generating, and transforming Java class files. You’ll never need to use it if

A Basic Introduction to the Classfile API

submited by
Style Pass
2024-11-16 05:00:05

JEP 484 defines the class file API as a standard way for parsing, generating, and transforming Java class files. You’ll never need to use it if you don’t write/never plan to write a JVM-based library, framework or compiler. ASM would still be the go-to library for most developers because there’s already a lot of information about it online. As of the time of writing, the API is still in preview and will be finalized with the release of JDK 24.

This article would give a very shallow introduction to creating class files. To be clear, we will be converting the following code to JVM byte code and run the generated bytecode with the java command:

Big Disclaimer: If you’re looking for an in-depth understanding of the API, and JVM bytecode in general, this article is most definitely not for you. ALL the code you see here was gotten by looking at the actual byte code gotten from javap, and the trying to map it to the API which involved lots of digging through different methods/classes/documentation.

The JVM is a stack-based virtual machine - a glorified way of saying that any operation it wants to perform needs to be done with values on the stack. For example, if you want to add two numbers, you would have to do the following:

Leave a Comment