Codectionary / Developer documentation / Java

Choose a JDK for your Linux distribution, verify the active tools and compile a first Java program.

Choose a supported package for your distribution

Linux distributions use different package managers and may ship different JDK releases. Choose a maintained JDK supported by your distribution, course or project. A JDK includes javac; a runtime-only package may provide java without the compiler. Read your distribution’s package information and the JDK vendor’s support and licence pages before installing.

Oracle documents archive, Debian and RPM packages, while Eclipse Adoptium documents DEB, RPM and APK repositories for supported distributions. Use the instructions for your actual distribution and architecture rather than copying a command intended for a different Linux system. For the simplest first step, a distribution-supported OpenJDK JDK package is often convenient; confirm its release before installing.

Package familyExamplesWhere to check
DEBDebian and Ubuntu familiesDistribution repositories or vendor DEB instructions
RPMFedora, RHEL and related familiesDistribution repositories or vendor RPM instructions
Other / archiveOther distributions or local user installsVendor platform support and archive guidance

Install using your distribution or vendor guide

Search your package manager for a JDK package for the release you need, then follow the distribution’s documented install procedure. If you choose a vendor package, follow the vendor’s current repository setup and signing-key instructions. Oracle’s installer guide covers archive, DEB and RPM choices; Adoptium publishes package names such as temurin-<version>-jdk.

An archive can be installed in a user-writable directory without root access, but then you must configure PATH and possibly JAVA_HOME yourself. Do not overwrite system JDK directories or change global alternatives merely to repair a single practice project.

Identify the active Java tools

Open a new terminal and check both versions. command -v reports the executable selected by PATH, and readlink -f can help resolve a symlink on systems that provide it. If java and javac are from different installations, select a consistent JDK using your distribution’s documented mechanism.

Terminal — inspect selected tools

java -version
javac -version
command -v java
command -v javac

Compile and run a program

Save Main.java in a practice directory and run the commands there. javac writes Main.class; java Main launches it and prints Hello, Codectionary!. If you modify the source, compile again. The public class name must match the filename exactly, including case on typical Linux file systems.

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

Missing compiler, mismatched versions or wrong folder

If java works but javac is missing, inspect the installed package: you may have only a runtime. If javac compiles but java reports an unsupported class-file version, the selected runtime is older than the compiler output. Check both versions and PATH. If Main.class cannot be found, confirm compilation succeeded and run from the directory containing it.

Package names, repository availability and support vary by distribution and release. If a command from another distro fails, return to the vendor or distribution guide rather than forcing an incompatible repository.

Syntax

java -version
javac -version

Examples

Prove the Linux JDK can compile and run

Use the same public-class example across platforms.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Codectionary!");
    }
}
  1. The class and filename must both be Main.
  2. javac generates bytecode from the saved source file.
  3. java Main runs the generated class and prints the greeting.

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