Setup: Verify your setup
Check every tool, then write a Java program, commit it with Git, and push it to GitHub.
Novice · Operating System · Git · Java · Updated
After this lesson you can
- Run a single-file Java program from the terminal
- Commit a file and push it to a new GitHub repository
Windows only. This last exercise checks that your tools work together. You will write a small Java program, save it with Git, and publish it on GitHub.
Check every tool
Open Windows Terminal. It should open in Git Bash. Run these commands one at a time:
git --version
java -version
javac -version
echo $JAVA_HOME
code --version
node --version
npm --version
"/c/Program Files/MySQL/MySQL Server 8.4/bin/mysql" --version
Each one should print a version number or, for JAVA_HOME, a path. If any of them prints command not found or No such file or directory, go back to that tool's Setup exercise.
The last command runs MySQL's command-line tool by its full path, because the MySQL installer does not add it to your terminal. You will use MySQL Workbench instead.
Write a Java program
Create a folder for your bootcamp work and a project folder inside it:
mkdir -p ~/bootcamp/hello-bootcamp
cd ~/bootcamp/hello-bootcamp
Open a new Java file in VS Code:
code HelloBootcamp.java
Type this program into the file, then save it with Ctrl+S:
public class HelloBootcamp {
public static void main(String[] args) {
System.out.println("Hello, bootcamp! My computer is ready.");
}
}
Back in Git Bash, run it:
java HelloBootcamp.java
You should see Hello, bootcamp! My computer is ready.
See your project in File Explorer too:
explorer .
File Explorer opens C:\Users\ followed by your username and \bootcamp\hello-bootcamp, with your HelloBootcamp.java file inside.
Save it with Git
git init
git add HelloBootcamp.java
git commit -m "My first Java program"
git init makes this folder a Git repository. git add chooses the file to save, and git commit saves it with a message. You should see 1 file changed.
Publish it on GitHub
- Sign in at github.com. Click the + at the top right and choose New repository.
- Set Repository name to
hello-bootcamp. Leave everything else as it is: do not add a README, a .gitignore, or a license. - Click Create repository.
GitHub shows a page of commands. Under …or push an existing repository from the command line, copy the line that starts with git remote add origin and run it. It looks like this, with your username:
git remote add origin https://github.com/your-username/hello-bootcamp.git
Then push your commit:
git push -u origin main
The first time you push, Git Credential Manager opens a Connect to GitHub window. Choose Sign in with your browser, then click Authorize on the GitHub page. After that, Git remembers you.
Refresh the repository page on GitHub. You should see HelloBootcamp.java. Click it to read your code online.
Check MySQL
Open MySQL Workbench, open your local connection, and run SELECT VERSION();. You should see a version that starts with 8.4.
Check Insomnia
Open Insomnia, then your Bootcamp project and its First requests collection. Click Glossary categories and click Send. You should see 200 OK and the list of categories.
You did it! Your computer is ready for the bootcamp.
Common problems
| What you see | What to do |
|---|---|
error: src refspec main does not match any |
The commit did not happen. Run the git add and git commit commands again, then push. |
remote origin already exists |
You ran git remote add twice. Run git remote set-url origin followed by the address from GitHub. |
Author identity unknown |
Set your name and email again, as in the Git Setup exercise. |
error: can't find main(String[]) method |
Check the spelling of public static void main(String[] args) in your file, and save it. |
VS Code saved the file as HelloBootcamp.java.txt |
Rename it in File Explorer (with file extensions showing) to HelloBootcamp.java. |