Javatpoint Logo
Javatpoint Logo

How to Create a Class File in Java

A class file is the compiled form of a .java file. When we compile the Java source code (.java file), it generates a .class file. If a Java program has more than one class, in such cases after compiling the source file, we get the same number of .class files as the number of classes a Java program has.

So, the compiler creates class files depending on the number of classes declared in that Java source file.

How to Create a Class File in Java

When we compile the above program, the compiler generates a .class file of that Java source code.

To generate the .class file of the file, we need to execute the following command in the command prompt.

The .class file of the file will look like as:

How to Create a Class File in Java

Description of .class file

The .class files describes the instructions to the Java Virtual Machine. The .class file contains the bytecode that will translate by the JVM into platform-specific machine code. The .class file can understand only by the JVM, not by the machine. When we run the Java source file using the javac command, we provide the class name that contains the main() method. The JVM first loads the Java source file, and then JVM executes the main() method of that source file. In Java application, the entry point is the main() method.

The javac command is used to convert the Java source file into the class file. The java command is used to run a Java program stored in a .class file. As we discussed above, the .class file contains the bytecode in the hex format.

The class file format is well documented, so anyone can easily break the Java security grant by tempering with the class file. During the byte code validation process, each class file is verified by the Verifier to prevent the Java security grant. The class files that violate the Java programming constraints are rejected by the Verifier to save the Java security grant or class file code.

Structure of Class file

Let's understand the structure of the Class file. Definition of a single class, module or interface is contained by each class file. A stream of 8-bit bytes is contained in the class file. In big-endian order, multi-byte data items are stores. Big-endian order is an order in which high bytes come first.

We define the description of each byte used in the class file:

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA