Java maintenance and ecosystem
Read a classfile major version
The fixture is compiled with --release 21 without preview features. The version identifies the classfile format, not all libraries it needs.
Formal Syntax & Structure
java syntaxjava
DataInputStream.readUnsignedShort()Working Example
Example Snippetjava
public class Main { public static void main(String[] args) throws Exception { try(var in=new java.io.DataInputStream(Main.class.getResourceAsStream("Main.class"))) { if(in.readInt()!=0xCAFEBABE) throw new IllegalArgumentException(); int minor=in.readUnsignedShort(); int major=in.readUnsignedShort(); System.out.println(minor); System.out.println(major); } }}