> For the complete documentation index, see [llms.txt](https://htooaunklinn-organization.gitbook.io/htooaunklinn-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://htooaunklinn-organization.gitbook.io/htooaunklinn-docs/hardware-and-iot/java.md).

# Java

## Installing OpenJDK on macOS

To set up OpenJDK on a macOS system, follow these steps:

1. **Install OpenJDK with Homebrew:**

   ```
   brew install openjdk
   ```
2. **Create a symbolic link:**

   * Establish a link to make Java accessible system-wide.

   ```
   sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
   ```
3. **Update the PATH environment variable:**

   * Ensure the OpenJDK binaries are prioritized when executing Java commands.

   ```
   echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
   ```
4. **Set C++ flags:**

   * This is necessary if you're compiling C++ programs that interact with Java.

   ```
   export CPPFLAGS="-I/opt/homebrew/opt/openjdk/include"
   ```

After these steps, restart your terminal or run `source ~/.zshrc` to apply the changes.

## To compile and run a simple Java program, follow these steps

1. Create a Java file named `Main.java` with the following content:

   ```java
   public class Main {
       public static void main(String[] args) {
           System.out.println("Hello, World!");
       }
   }
   ```
2. Open a terminal and navigate to the directory containing `Main.java`.
3. Compile the Java program:

   ```
   javac Main.java
   ```
4. Run the compiled Java program:

   ```
   java Main
   ```

Ensure the file is saved with the correct syntax to prevent errors.

## Compile and Run a JavaFX Application on Mac

To compile and run a JavaFX application on Mac, ensure the filename matches the `public class` name.

**Compile:**

```sh
javac --module-path "./javafx-sdk-23.0.2/lib/" --add-modules javafx.controls,javafx.fxml [YourJavaFile].java
```

**Run:**

```sh
java --module-path "./javafx-sdk-23.0.2/lib/" --add-modules javafx.controls,javafx.fxml [YourJavaFile]
```

Replace `[YourJavaFile]` with the name of your Java
