Hello World

In Visual Studio Code, open HelloWorld.java. Take a few minutes to look the code over and discuss it with a neighbor. You should notice some comments, a class declaration, a main function, and a line of code inside the main function. What do each of these parts do?

Now we’ll run the code. Unlike Python, Java is a compiled language, which means that first we need to compile our file into java bytecode, then run it. The command to compile a java file is javac, and the command to run it is java. In your Terminal window, type

javac HelloWorld.java
java HelloWorld 

This first compiles the file HelloWorld.java into a java class named HelloWorld, then runs the class.

When you ran HelloWorld, it should have printed out the phrase “Hello World” in your Terminal. Working with a neighbor, change the code so it prints “Hello CS 151” instead of “Hello World”. Compile and run it to test your solution.

Once you’ve successfully changed the code, you should save your changes to GitHub. You’ll do this the same way you did when you saved your changes to README.md. Run the add command to add the file to your commit, and then run the commit command (the text in quotes after -m is a message to help you remember what you are committing). Finally, you will need to push your changes to GitHub. To do all of this, in the Terminal type:

git add HelloWorld.java
git commit -m “changed the print message”
git push

You can look at your repository on GitHub to make sure your changes were saved.