Skip to content

mrjameshamilton/java-class-file-api-hello-world-translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Class-File API Hello World Translator

JEP 484 Class-File API (previously JEP 457 and JEP 466) is an API introduced in Java 24 to provide a standard API for parsing, generating, and transforming Java class files.

The example here shows how easy it is to use to read and modify an existing class file. The example modifies a single ldc instruction to change the constant printed from "Hello World" to another string provided as an argument.

For examples of generating a class from scratch see Java Class-File API Hello World and Java Class-File API Brainf*ck Compiler.

Building

You'll need JDK 24. The easiest way to install this on Linux is with SDK man:

sdk install java 24.ea.36-open

If you have Java 24, you can then execute the run.sh script which will compile and execute HelloWorld.java and HelloTranslator.java. HelloTranslator will transform HelloWorld.class, changing the constant "Hello World" into the script argument, and then executing it.

$ ./run.sh "Hallo Wereld"

Similar projects

There are many similar projects for parsing, generating, and transforming Java class files, including:

About

A simple demonstration of transforming a class with the Java Class File API

Topics

Resources

License

Stars

Watchers

Forks