Install Java/JDK on Windows
The general method installs Java JDK on a Windows environment.
Configure JDK
Download JDK
- Google Search "oracle jdk download"
- Open Oracle JDK download page
- Select
Windows
if you are using a windows machine. Then, download thex64 Installer
file.
Check whether the installer was damaged
- Click
sha256
You will get some random letters and numbers, like this
4f66bf2c67aee5c0f2ed148086b257ddc4fad29c4c18b31f8ae85a93e8e7da8f
- Find your file, and copy the installer file path, NOT the installer itself
- Using keyboard shortcut,
Win
+R
, then typecmd
, hitenter
to open the command prompt
Using the formula below to output the sha256 value of your downloaded installer file
certutil -hashfile [Your file path] SHA256
Example:
certutil -hashfile C:\Users\danni\Downloads\jdk-19_windows-x64_bin.exe SHA256
- Check if the sha 256 output value in the command prompt is the same as the website provided. If not, your file is damaged, please delete the installer file and re-download it again!
Start Installing
- Double click the
jdk-19_windows-x64_bin.exe
file
- Click
next
, and remember the installation path
- Click
next
. Then, close the installer.
Check whether your JDK successfully installed in your machine
- Using the keyboard shortcut,
Win
+R
, then typecmd
, hitenter
to open the command prompt type command
java -version
If you received any output like this below, you are good to go
C:\Users\danni>java -version java version "19" 2022-09-20 Java(TM) SE Runtime Environment (build 19+36-2238) Java HotSpot(TM) 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)
If you received any output like this below, the JDK may be partially installed. You may need to configure system environment variables manually.
C:\Users\danni>java -version 'java' is not recognized as an internal or external command.
Configure environment variables
You can simply skip this step if you installed your JDK successfully.
- For windows 11, go to
Settings
-->System
-->About
- Click
Advanced system settings
- Click
Environment Variables
Add/Edit the following
System variables
Variable name: JAVA_HOME Variable value: C:\Program Files\Java\jdk-19 //This is your actual installation path Variable name: Path Variable value: %JAVA_HOME%\bin Variable name: Path Variable value: %JAVA_HOME%\jre\bin
Using Code Editor
In order to edit your code locally, you need to install code editor software on your machine.
If you are using Linux based operating system and you are familiar with terminal commands, you can use nano
, vi
, vim
, or emac
. We will not discuss the Linux terminal environment here.
If you are using a Windows operating system. You can use any editor your like, for example, VS Code, Notepad, or Notepad++. I personally recommend VS Code.
To create a new file:
Select File
>> New File
Then, type your file name here. (Please include your file extension name)
Finally, select the path that you want to save your file.
Run Your Code
Save the code below and named it as
test.java
import java.util.Date; public class test { public static void main(String[] args) { System.out.println("Current Time: " + getTime()); System.out.println("Congratulation, your Java has been successfully run locally."); } public static String getTime() { Date date = new Date(); return date.toString(); } }
- Using the keyboard shortcut,
Win
+R
, then typecmd
, hitenter
to open the command prompt Using
javac
to compile your.java
file
For example:C:\Users\danni\Downloads>javac test.java
- Then, the compiler will generate a
.class
file. This file is intended to be run. Using
java
command to run your file
For example:C:\Users\danni\Downloads>java test
Notes: This is just an example, and you need go to your test.java directory in order to run your java file!
Comments are disabled.