Learning the Java Class File Format

Did you ever read that ("string 1" == "string 1") == true but ("string 1" == new String("string 1")) == false? Ever came across the terms “Constant Pool“, “StackMapTable” or the “java.lang.UnsupportedClassVersionError: Unsupported major.minor version” exception?

I did, a lot of times. All of this terms (and many others) apply to the Java Class File Format, which is a key concept of the JVM. It contains all the information for the runtime, from String constants, visibility modifiers, fields, methods, down to the actual byte codes. You can find a complete description of the format in the JVM specification, which may be complete, but is not what I’d call an easy read.

I think learning by doing is the best way of learning. So what I want to do the next weeks, is dive into the Java class file format to fully understand it’s structure and the underlying concepts and optimizations. The result will be a kind of parser that reads and displays a class file in a human-readable way. I created a nice little GitHub project called classfilereader where the Class File Reader can thrive and prosper.

Of course there are already tools like javap or libraries like ASM, BCEL, ByteBuddy and cglib that we can use to examine or parse class files. Maybe I will take a look at some of these in the blog. Nevertheless I think doing it by yourself for the sake of learning can never be a bad thing.

Author: Thomas Lemmé

Something about me...

Leave a Reply

Your email address will not be published. Required fields are marked *