Java Setup in VS Code - Quick Start for Students
What Is Java?
Java is a programming language used to give computers instructions.
We can use Java to build programs, solve problems, and later program robots.
Java files end with:
.java
Why Are We Learning Java?
Java will help us learn how to:
- Give a computer instructions
- Store information
- Make decisions
- Repeat actions
- Create reusable commands
- Prepare for future robotics programming
For now, we will run Java programs on our computer and see the results in VS Code.
Later, the same programming ideas can be used with robot motors, sensors, servos, arms, and gamepad controls.
1. Install Java and VS Code
The easiest way to get everything ready is to use Microsoft's Coding Pack for Java.
The Coding Pack includes:
- Visual Studio Code
- Java Development Kit (JDK)
- Java extensions for VS Code
Click Below
Java in Visual Studio Code - Microsoft
On that page, find the Coding Pack for Java section.
Choose the installer for your computer:
- Windows
- macOS
Download the correct version and follow the installation instructions.
If you already have VS Code or Java installed, that is okay. The Coding Pack can help complete your Java setup.
2. Check That Java Is Installed
After installation, let's make sure Java is working.
Windows
- Click Start
- Type:
cmd
- Open Command Prompt
- Type:
java --version
Press Enter.
Then type:
javac --version
Press Enter.
Mac
- Press Command + Space
- Search for:
Terminal
- Open Terminal
- Type:
java --version
Press Enter.
Then type:
javac --version
Press Enter.
What Should You See?
You should see a Java version.
For example:
openjdk 17...
and:
javac 17...
Your version may be different. That is okay.
If both commands show a version number, Java is ready.
What do these commands mean?
java --version
checks whether Java can run on your computer.
javac --version
checks whether the Java compiler is installed.
3. Open VS Code
Open:
Visual Studio Code
If you installed the Coding Pack, the Java extensions should already be installed.
4. Create Your Java Course Folder
Create a folder on your computer called:
Java-Robotics-Course
Inside it, create another folder:
Lesson01
Your folders should look like this:
Java-Robotics-Course
└── Lesson01
5. Open the Folder in VS Code
Open VS Code.
Then:
- Click File
- Click Open Folder
- Select:
Java-Robotics-Course
You should now see the folder on the left side of VS Code.
6. Create Your First Java File
Inside the Lesson01 folder, create a new file called:
HelloRobot.java
Make sure the file ends with:
.java
7. Write Your First Java Program
Copy this code into HelloRobot.java:
public class HelloRobot {
public static void main(String[] args) {
System.out.println("Hello Robot!");
}
}
You do not need to understand every part yet.
For now, remember these three pieces.
Program Name
public class HelloRobot
Our program is called:
HelloRobot
The file name should match:
HelloRobot.java
Starting Point
public static void main(String[] args)
This is where Java starts running the program.
For now, remember:
main() = Start Here
Display Something
System.out.println("Hello Robot!");
This tells Java to display:
Hello Robot!
8. Run Your Program
In VS Code, look near the main() method.
You should see:
Run | Debug
Click:
Run
You may also see a ▶ Run button near the top of VS Code.
9. Check the Output
At the bottom of VS Code, you should see:
Hello Robot!
🎉 Congratulations — you just ran your first Java program!
10. Change It and Run Again
Change this:
System.out.println("Hello Robot!");
to:
System.out.println("My robot is ready!");
Run the program again.
You should now see:
My robot is ready!
This is how programmers learn:
Write → Run → Check → Change → Run Again
11. Try a Simple Robot Program
Now update your program:
public class HelloRobot {
public static void main(String[] args) {
System.out.println("Robot starting...");
System.out.println("Driving forward");
System.out.println("Turning right");
System.out.println("Stopping robot");
System.out.println("Mission complete!");
}
}
Run the program again.
You should see:
Robot starting...
Driving forward
Turning right
Stopping robot
Mission complete!
Now change:
System.out.println("Turning right");
to:
System.out.println("Turning left");
Run it again and watch the output change.
Common Problems
java --version Does Not Work
Go back to:
Java in Visual Studio Code — Microsoft
Find the Coding Pack for Java and reinstall the version for your computer.
javac --version Does Not Work
The Java Development Kit may not have installed correctly.
Go back to the Microsoft Java page and run the Coding Pack installer again.
VS Code Does Not Show Run
Check that:
- Your file ends with
.java - You opened your course folder in VS Code
- Java extensions are installed
- Your program contains
main()
Your Program Shows an Error
Check for small syntax mistakes.
For example:
System.out.println("Hello Robot!")
This is missing a semicolon:
;
Correct:
System.out.println("Hello Robot!");
Errors are normal.
Finding and fixing errors is an important part of programming.
You Are Ready!
You are ready for class when:
- [ ] VS Code opens
- [ ]
java --versionworks - [ ]
javac --versionworks - [ ]
HelloRobot.javaruns - [ ] You can see
Hello Robot!in the output - [ ] You can change the program and run it again
Setup Link
Java in Visual Studio Code — Microsoft
Go to this page and choose the Coding Pack for Java for either Windows or macOS.
