Download the Java installer from the official Oracle website or install OpenJDK from a trusted source
Run the downloaded installer
Follow the on-screen installation prompts
Accept the license agreement if prompted
Choose the installation location if required
Complete the installation
Open a terminal or command prompt
Verify the installation by running `java -version`
Verify the compiler by running `javac -version`
If needed, set the `JAVA_HOME` environment variable
If needed, add Java to the system `PATH` variable
