CS 112
Spring 2024

Creating and Running a Program in VS Code

  1. On your laptop, create a folder for your work in this course (e.g., one called cs112).

  2. Within your cs112 folder, create a subfolder for the program that you are about to create (e.g., a folder called lab0).

  3. Launch VS Code on your laptop:

    • On Windows, use the Windows button in the lower-left corner of your Desktop to search for and run Visual Studio Code.

    • On macOS, use the Spotlight tool to search for and and run Visual Studio Code.

  4. In VS Code, select the File->Open Folder or File->Open menu option, and use the resulting dialog box to find and open the folder that you created in step 2. The name of the folder should appear in a new Explorer pane on the left-hand side of the VS Code window.

  5. Select File->New File, which will open up an empty window known as an editor window for your new program. It will initially have a name that is something like Untitled-1.

  6. Select File->Save, and give the file the name HelloWorld.java.

  7. Copy and paste the following code into the editor window for HelloWorld.java:

    public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("hello, world!");
        }
    }
    
  8. To run the program, use the F5 key. Doing so should open a Terminal pane at the bottom of the VS Code window. In the Terminal, you should see (among other messages) the output of your program:

    hello, world!
    

    Note: If pressing F5 does not immediately work, find the name HelloWorld.java in the Explorer pane, right click on the name HelloWorld.java, and choose Run or Run Java to run the program.

If you encounter any problems in getting the program to run, please post your question to Piazza, our class discussion site. The link to our Piazza course page is available on this site’s navigation bar. We will also be offering limited office hours this weekend, which you are welcome to go to for additional assistance.