Problem Set 0

Creating and Running a Program in VSCodium

  1. On your laptop, create a folder for your work in this course by following these instructions.

  2. Within your s22 folder, create a subfolder called ps0 for the program that you are about to create.

  3. Launch VSCodium on your laptop.

  4. In VSCodium, select the File->Open Folder menu option, and use the resulting dialog box to find and open the ps0 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 VSCodium window.

  5. Select File->New Text 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 following name:

    HelloWorld.java
    

    Important: When naming a Java file, the case of the letters matters. Make sure to use the exact combination of upper-case and lower-case letters that we have specified.

  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. Save the file again by selecting File->Save or using Ctrl-S.

  9. Open VSCodium’s built-in Terminal pane. You can do this by pressing the Control key and the backtick key, or by selecting Terminal->New Terminal from the menu.

  10. The Terminal should open at the bottom of the VSCodium window. It should already be in the ps0 folder. To compile your program, type the following command in the Terminal and then press Enter:

    javac HelloWorld.java
    

    If the command succeeds, you should not see any output. You should see a new file named HelloWorld.class in the Explorer pane.

  11. To run your program, type the following command in the Terminal and then press Enter:

    java HelloWorld
    

    You should see the following output:

    hello, world!
    

    Important: When using the java command, use the class name HelloWorld, not the file name HelloWorld.java. Java class names are case-sensitive, so the capitalization must match exactly.

If you encounter any problems in getting the program to run, please let us know by posting a question on Ed Discussion or emailing cscie22-staff@lists.fas.harvard.edu