Master the fundamental concepts of jvm internals through this focused micro-challenge.
Java bytecode lives in a structured binary format specified in the JVM spec chapter 4. Parsing it manually teaches you what \`javap\` reads under the hood.
After the magic \`0xCAFEBABE\` and version fields:
The constant pool is the spine. Opcodes like \`ldc #5\` index into it; \`invokevirtual\` references a method ref entry pairing class and name.
For example, \`Hello.class\` might pool \`"Hello"\`, \`"java/lang/Object"\`, and \`Code\` bytes for \`main\`.
\`\`\` magic: CA FE BA BE version: minor, major constant_pool_count: ... \`\`\`
Constant pool indices are one-based in the spec but easy to mishandle in parsers. Validate every index against pool length before dereferencing or you will read garbage UTF-8 strings silently.
This exercise asks you to parse or document \`.class\` layout field by field. You will read magic, version, and constant pool entries from raw bytes the way a minimal class loader would.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Write a C program that parses a simulated .class file header and constant pool.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github