user11244708
user11244708

Reputation:

How does the Java Virtual Machine deal with constants

So I compiled this code and decompiled it into bytecode:

System.out.println("hi");

compiles to:

getstatic
ldc
invokevirtual

From what I can see here, the literal value "hi" isn't explicitly stored in any bytecode format, so does a .class file also contain a hidden representaion of a stack for that program. For example when I compiled that program would the .class file contain that bytecode, and a heap data structure containing the literal value "hi". And more generally, does a .class file contain more than just bytecode (e.g. a representation of the heap, stack and registers). thanks!

Upvotes: 1

Views: 308

Answers (1)

yachoor
yachoor

Reputation: 939

Constants are stored in seperate parts of class files than bytecode, called Constant Pools. You can find more information about them here: What is the purpose of the Java Constant Pool?

The class file format is publicly available in Java Virtual Machine Specification

Upvotes: 3

Related Questions