Codectionary / Developer documentation / Java

Install a suitable macOS JDK for Apple Silicon or Intel, verify it in Terminal and run Main.java.

Choose the right JDK package

You need a JDK to compile Java, not merely a runtime for opening an existing application. Check the release your course or project requires and select a maintained JDK from an official vendor. Oracle JDK and Eclipse Temurin are distributions with their own download and licensing information.

Choose the package matching your Mac: Apple Silicon uses AArch64/ARM64, while an Intel Mac uses x64. The processor choice is about the JDK installer; ordinary Java bytecode is normally portable across compatible JVMs.

Install with the vendor’s macOS package

Download the appropriate macOS package from your chosen vendor. Oracle’s documentation describes opening the .dmg and running its .pkg installer; Adoptium also documents its macOS PKG installer. Follow the installer’s prompts, then open a new Terminal window.

macOS can contain more than one JDK. Do not delete /usr/bin/java or change protected system files to switch versions; inspect the installed JDKs and configure the one your project needs.

Verify the compiler and launcher

In Terminal, run java -version and javac -version. Both should point to a compatible JDK release. The macOS java_home utility can list installed JDKs; use it to diagnose a mismatch between Terminal and your IDE. If you see an installation prompt instead of a version, the desired JDK is not selected in that terminal.

Terminal — inspect Java

java -version
javac -version
/usr/libexec/java_home -V

Compile and run Main.java

Save the example as Main.java in a practice folder. Open Terminal in that folder, run javac Main.java and then java Main. The first command creates Main.class; the second launches it and prints Hello, Codectionary!. A successful version check alone does not prove you saved and ran the file correctly.

After editing the text, compile again. If the terminal is in another directory, use pwd and ls to find the saved source file before retrying.

Main.java

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Codectionary!");
    }
}

Terminal — compile and run

javac Main.java
java Main

Common macOS setup problems

If javac is missing, check that you installed a JDK rather than a runtime-only package. If an IDE uses a different Java version, set its project JDK deliberately. If a command runs an unexpected release, inspect /usr/libexec/java_home -V and your shell’s PATH; avoid replacing Apple-managed launchers in /usr/bin.

If javac reports that class Main is public and should be in Main.java, rename the source file to match. If java Main cannot find the class, check for a successful Main.class in the working folder.

Syntax

java -version
javac -version

Examples

Check the macOS JDK with a real program

A successful compile and run proves more than a version check alone.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Codectionary!");
    }
}
  1. The public Main class is saved in Main.java so javac can compile it.
  2. The main method gives the launcher an entry point.
  3. println prints one line; edit the string, recompile and confirm the change.

Best practices

  • Use a maintained JDK release that fits your course or project; check the vendor’s release and support information.
  • Check both java and javac in a newly opened terminal after installation.
  • Never paste passwords, tokens or private data into a remote code runner.

Runtime & versions

Java Virtual Machine. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Java Language Specification

Specifications & further reading