Note: For a beginner, it can be overwhelming to set up and work with an IDE (Integrated Development Environment, which is a program for coding).
You may want to skip this step for now, and instead start programming on an online programming environment, such as
w3schools or
codewars.
1. Get the JDK (Java Development Kit) on your computer (for Windows 11) -
- Go to jdk.java.net and download the latest OpenJDK version that is ready for use
- Find or create the folder C:/Program Files/Java on your computer
- Unzip the download and put the jdk folder into the Java folder
- Access your computer's environmental variables (in the toolbar, search "Edit the System Environment Variables")
- Click the "Environment Variables" button
- In the System Variables section, create an environmental variable called JAVA_HOME, and set its value to the path of the JDK folder
- Edit the System Variable called "Path", and add %JAVA_HOME% and %JAVA_HOME%\bin as values
- Open the Command Prompt (type "cmd" in the Windows search bar)
- To test it, type "java -version" (without quotes) in Command Prompt. It should show the jdk version
- At this point, java files can be run from the command line. See step 2 below
2. (Optional, if not wanting to use an IDE) Running java files from the Command Prompt (Windows 11) +
- Open the Command Prompt and navigate to the Desktop directory/folder with this command: cd Desktop
- Make a directory called JavaPractice: mkdir JavaPractice
- Navigate to the new directory: cd JavaPractice
- Make a java file called MainClass.java: notepad MainClass.java
- Follow the instructions in the Basics lesson to write a simple program that displays text
- Save the file in Notepad (File -> save)
- Compile the java file from the Command Prompt: javac MainClass.java
- Run the java file from the Command Prompt: java MainClass.java
- Whatever you name the file (e.g. "MainClass"), it must match the word after "class" in the file
- The folder and file names used above (Desktop, JavaPractice, MainClass) are only examples and can be changed
- If you are unfamiliar with Command Prompt navigation commands, see this tutorial
3. Set up Eclipse IDE (Windows 11) +
- Go to eclipse.org
- Click the download button
- Run the installer
- Select the version you want ("for Java Developers" or "for Enterprise Java and Web Developers")
- Run Eclipse
- Set the path to Java in Eclipse (if needed) Tutorial
4. Create and run code in Eclipse +
- New -> Project -> Java Project
- Name it and click finish
- It will show up in the left column
- Right click the project name, new -> package, name it (lowercase letters), click Finish
- Right click the package name, new -> Class, name it, click Finish
- If the editor doesn't show up for the new class, double click it in the left column
- Follow instructions in the "Basics" lesson to write code in it
- Save it
- Run it with the Run button in the top toolbar
- Set Java build path in project (if needed) Tutorial