Create a folder named section1 for your work on these
exercises. You can find instructions for doing so
here.
In VSCodium, select the File->Open Folder or File->Open menu
option, and use the resulting dialog box to find and open your
section1 folder. The name of the folder should appear in the
Explorer pane on the left-hand side of the VSCodium window.
Important: In general, you should not use File->Open File to open a specific file in VSCodium. Rather, you should create a folder for the files that belong to a given assignment or section, and you should use File->Open Folder or File->Open to open the folder.
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. The
Terminal should open at the bottom of the VSCodium window,
and it should already be in the section1 folder.
In Java, what is an identifier? 1
Indicate whether the following names are valid Java identifiers. 2
SECRET_NUMBERaverage?num2twotwo2secret wordmy#variableAre the identifiers secretNum and secretnum
the same? 3
In Java, what is the difference between the statement
System.out.print(...) and System.out.println(...)?
4
Make sure that you have taken the preliminary steps in the Getting started section above.
In VSCodium, select File->New Text File, which will open up an empty editor window. It will initially have a name that is something like Untitled-1.
Select File->Save, and give the file the following name:
Section1.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 specify. For this file, make sure to
begin with an upper-case S.
Copy and paste the following buggy code into the editor window
for Section1.java:
Public Class section1 {
public static main(String args) {
System.out.println(Go Crimson);
System.out.pritnln("S-111 is the best"!);
System.out.println("///Are you having fun?\\\");
System.out.println()
System.println("Bye!";
{
}
Identify all of the bugs in the program and fix them. 5
VSCodium can help you to identify the bugs if you use it to compile the code as follows:
Save the changes that you made to the file by selecting File->Save or using Ctrl-S.
To compile your program, type the following command in the Terminal and then press Enter:
javac Section1.java
Doing so word will produce a list of any syntax errors in the code.
Notes:
Each error message includes the line number of the code that produced the error. For example, let’s say that you see an error message that begins with the following
Section1.java:1: error: ...
The :1 that comes after the name of the file tells
you that the error is on line 1 of the file.
If you press the Ctrl key as you click on the line number in an error message, the corresponding line of code should be highlighted in the editor window.
Continue editing the code and recompiling until javac
does not report any errors.
Important: Make sure to save any changes that you make before you try to recompile.
Once all of the syntax errors have been fixed, run the program by entering the following command from the Terminal:
java Section1
Important: When using the java command, use the class
name Section1, not the file name Section1.java. In
addition, don’t forget that class names are case-sensitive,
so the capitalization must match exactly.
Write a System.out.println(...) statement that would produce
the following output: 6
Joe said, "We're my teaching assistant's favorite class!"
Write a Java class called HarvardSpirit that produces
the following output. Make sure your HarvardSpirit.java
file has a block comment at the top listing the file name,
the author, and a short description of the file. 7
///////////// HARVARD S-111 \\\\\\\\\\\\\
The following StickFigure class draws a stick figure graphic
using only text characters. Copy this code into a new file
in VSCodium, then write a method drawFigure() that draws an
entire stick figure. Then change the main() method so that
it calls drawFigure() twice. 8
public class StickFigure { public static void main(String[] args) { System.out.println("\\ O /"); System.out.println(" \\|/"); System.out.println(" |"); System.out.println(" / \\"); System.out.println("/ \\"); System.out.println(); System.out.println(); System.out.println("\\ O /"); System.out.println(" \\|/"); System.out.println(" |"); System.out.println(" / \\"); System.out.println("/ \\"); } }
What output is produced by the following program? Note: Don’t just copy the code into VSCodium! First, trace the program by hand, and then you can verify your answer by creating a new file for the program in VSCodium and running it. 9
public class Blastoff { public static void main(String[] args) { three(); two(); one(); System.out.println("blastoff"); } public static void one() { three(); System.out.println("one"); } public static void two() { one(); System.out.println("two"); three(); } public static void three() { System.out.println("three"); } }
An identifier is a name used in code to refer to a method, class, or other construct. Programmers have control over what identifiers to use when writing a program. ↩
SECRET_NUMBER and two2 are valid identifiers. average?num
is invalid because it contains a ? character. 2two is invalid,
since it starts with a number. secret word is invalid because
it contains a space. my#variable is invalid because it contains
a # character. ↩
secretNum and secretnum are not the same, since identifiers
are case-sensitive. Here, secretNum and secretnum would
refer to different things. ↩
System.out.println(...) automatically includes a newline
character (\n) after the string, whereas System.out.print(...)
does not include a newline. ↩
The following is a fixed version of the class:
public class Section1 { public static void main(String[] args) { System.out.println("Go Crimson"); System.out.println("S-111 is the best!"); System.out.println("///Are you having fun?\\\\\\"); System.out.println(); System.out.println("Bye!"); } }
System.out.println("Joe said, \"We're my teaching assistant's favorite class!\""); ↩
The output is as follows:
three three one two three three one blastoff
Last updated on June 23, 2026.