Page 309 - CITS - Computer Software Application -TT
P. 309
COMPUTER SOFTWARE APPLICATION - CITS
When a .java file is compiled, it produces .class files that contain bytecode and share the same class names
as the corresponding .java files. When these .class files are executed, they undergo a series of steps that
collectively define the functionality of the JVM (Java Virtual Machine).
Java bytecode
Java bytecode serves as the instruction set for the Java Virtual Machine (JVM). It functions akin to an assembler,
providing a symbolic representation of Java code, much like how C++ code can be represented in an alias
form. When a Java program is compiled, it results in the generation of Java bytecode. To put it succinctly, Java
bytecode can be thought of as machine code encapsulated in a .class file. The utilisation of Java bytecode is what
enables Java to attain platform independence, ensuring that Java programs can run on different systems without
modification.
How does it work?
When we develop a program in Java, the initial step involves compiling the code, resulting in the creation of
bytecode. This bytecode serves as an intermediary representation of the code. Importantly, when we intend
to execute this .class file on different platforms, we can readily do so. Following the initial compilation, it’s the
Java Virtual Machine (JVM), rather than the specific processor of the platform, that takes charge of running the
bytecode.
In essence, this implies that we only need a basic Java installation on any platform where we wish to execute
our code. The JVM plays a crucial role by managing the resources required for executing the bytecode. It
communicates with the processor to allocate the necessary resources. It’s worth noting that JVMs operate in a
stack-based manner, using a stack implementation to interpret and execute the bytecode instructions.
296
CITS : IT&ITES - Computer Software Application - Lesson 78 - 84