Sometimes I find there is an assumption it has to be terribly complication when it is not. It is actually very simple.
I do not understand a single line of the bytecode. I want to understand some part of it if not all. or what some of these lines mean such as iconst_2?
iconst_2
stands for the integer constant 2
is bytecode and .class file same or .class files contains bytecode?.
The .class contains more than byte code. It also contains some constants e.g. String literals and large primitives. However, you can treat them as one and the same.
The picture below shows both .class and bytecode are same
The diagram is a simplified view. In simple terms they are the same thing.
If they are different, how is bytecode extracted from .class files by the JVM?
A .class has a specific format which if you follow that format you will find the byte code. As you can see there is more than just byte code in the file, but the byte code is the only bit you should care about. (Actually you shouldn't really care about the byte code in 99% of cases)
From the Class file format linked above.
A class file consists of a single ClassFile structure:
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}