Reading bytecode with javap
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
read the bytecode of a small method and map it to source.
Planned topics
javap -c -p Shopdisassembles a class, including private members.- The JVM is a stack machine: instructions push and pop an operand stack.
- Common instructions:
iload,imul,invokevirtual,invokestatic,ireturn. - Local variables sit in numbered slots; slot 0 is
thisin instance methods. - Lambdas appear as
invokedynamic; modern JDKs also use it for string concatenation (verify version before recording).
Draft outline details
Demonstration
static int total(int price, int qty) { return price * qty; }iload_0
iload_1
imul
ireturnCheck your understanding
In total, what does imul consume?
Show answer
The two top operand-stack values.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.