> For the complete documentation index, see [llms.txt](https://cs61b-2.gitbook.io/cs61b-textbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cs61b-2.gitbook.io/cs61b-textbook/1.-introduction/1.2-java-workflow.md).

# 1.2 Java Workflow

{% embed url="<https://youtu.be/Y2vC_SW00TE>" %}

Taking a program from a `.java` file into an executable has two main steps in Java: **compilation** and **interpretation**.&#x20;

<figure><img src="https://2316889115-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCLYj7ccqvV6l4Pt9R0w5%2Fuploads%2FhedhIwHW0XpvKamJ52mc%2F1-2-compile-interpret.svg?alt=media&amp;token=a953a222-d3a8-4f12-9053-5d01e0ec67c8" alt=""><figcaption></figcaption></figure>

To run the code in `Hello.java`, we would first **compile** the code into a `.class` file using the command `javac HelloWorld.java`. Then, to run the code, we would use the command `java HelloWorld`.&#x20;

In your terminal, the result would look like the following:

```
$ javac HelloWorld.java
$ java HelloWorld
Hello World!
```

## Class Files

There are several reasons for the usage of `.class` files, which we will only cover briefly here. First of all, `.class` files are guaranteed to have been type-checked, making the distributed code safer. They are also more efficient to execute, and protect the actual source code in cases of intellectual property. We will not go into the details of `.class` files in this textbook beyond knowing that they are created after compilation.
