ByteBrawl - Compilation And Execution - Intro To Java - Java Basics

Intro To Java - Compilation And Execution

Java Compilation and Execution

When you code in java, you type your code into a .java file. However, this file cannot be run on its own. First, you must tell java to compile it using a command (part of the JDK):

By doing this, you get a .class file (MyProgram.class in this case). The compiler turns your code into Java bytecode. Finally, you can execute your program:

When you run this command, the JVM installed on your system uses an interpreter and the JIT (just-in-time) compiler to run your code. This means a Java .class file can be executed regardless of operating system or architecture, as long as the JRE (which contains the JVM) is correctly installed. Also, note that when you use the "java" command, you don't include the .class file extension of the target file.