CS I · Mon Nov 9 · 15.1 · We Do

Before the bell

You are responsible for all of this before the end of class.

  1. The discussion form in the I Do deck. All three sections. If you are here, this should be done.
  2. Your classwork. This form on the right. Section 1 before the exit ticket pops up; Section 2 past the floor.
  3. Today's Bench Basics activity: Boxes and Types. It opens later in class and lives on slide 4 of this deck.
  4. The exit ticket. It opens 15 minutes before the bell and lives on the last slide of this deck.
Classwork

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

Boxes and Types

This reading explains how Java gives every box a type, and then it works through one program that makes five boxes.

Four Types for Four Kinds of Value

Last week, a box held one value at a time, and = stored a new value in it. In Java, every box also has a type, and the type decides which values fit in the box. The type is written in front of the box's name the first time the box appears. This course uses four types this semester. The type `int` holds whole numbers, such as 12 or 40, and the type `double` holds numbers with a decimal point, such as 3.5. The type `boolean` holds only one of two values, `true` or `false`. The type `String` holds text inside double quotes, and it is always written with a capital S. A line such as `int stops = 12;` is called a declaration, because it makes the box, names its type and stores the first value.

One Program, Line by Line

The program below makes five boxes and prints each one.

1public class Main {
2    public static void main(String[] args) {
3        int stops = 12;
4        double miles = 3.5;
5        boolean raining = false;
6        String street = "Esplanade";
7        System.out.println(stops);
8        System.out.println(miles);
9        System.out.println(raining);
10        System.out.println(street);
11        double half = 4;
12        System.out.println(half);
13    }
14}
12
3.5
false
Esplanade
4.0

Line 3 makes an `int` box named `stops` and stores 12 in it, and line 4 makes a `double` box named `miles` and stores 3.5 in it. Line 5 makes a `boolean` box named `raining` and stores `false`, and line 6 makes a `String` box named `street` and stores the text Esplanade. Lines 7 to 10 print the four values in the order the lines run, one value on each line of output. Line 11 stores the whole number 4 in a `double` box named `half`, and line 12 prints it.

Two Points Bench Basics Checks

The first point is that a whole number fits in a `double` box, and Java stores it as a number with a decimal point, which is why `half` prints `4.0` instead of 4. The second point is that a decimal does not fit in an `int` box. Java will not compile `int miles = 2.5;`, and the compiler reports "possible lossy conversion from double to int." The word lossy means that part of the number, the .5, would be lost if Java stored it in a box for whole numbers. The output also shows that the quotes around `"Esplanade"` are not printed, because they only mark where the text starts and where it stops.

Sources: Oracle, Primitive Data Types (n.d.); Oracle, The Java Language Specification, Java SE 21 Edition, Chapter 5 (n.d.); classroom data, Reading 2 program run with the course JDK (2026).

Files, Folders and File Paths

This section explains how files are named, how they are kept in folders, and how one file finds another.

Files and Folders

Every Java program in this course is stored in a file, and every file is kept in a particular place on the computer. Most computers organize their files in a structure shaped like a tree. A folder is a container that holds files, and it can also hold other folders. Each of those folders can hold more files and folders, so the files grow into a tree. Windows uses the word folder, and some other systems call the same container a directory. For example, the class folder in Figure 1 is named `cs1-java`. Inside it are two more folders, `src` and `out`, and one loose file, `notes.txt`. A folder is not a file, so it has no extension, and no program opens a folder as a document.

What a File Extension Tells the Computer

A file extension is the group of letters after the last period in a file's name. The extension tells the computer what kind of file it is, and so which program should open the file. For example, a file ending in `.txt` holds plain text, a file ending in `.png` holds a picture, and a file ending in `.mp3` holds sound. In Java, two extensions matter. A file ending in `.java` holds source code that a person writes, and a file ending in `.class` holds the bytecode that the compiler makes from it. As the Oct 28 lesson explained, Java is compiled to bytecode, which runs on the Java Virtual Machine. A file extension names only the kind of file, and it does not say what the file is about or when the file was made. An extension is also a naming habit that programs rely on, so renaming `notes.txt` to `notes.png` does not turn the text into a picture.

Java adds one rule of its own about file names. The Java compiler, `javac`, requires a public class named `Hello` to sit in a file named `Hello.java`, and it checks that the two names match. When a file named `Stops2.java` holds the public class `Stops`, the compiler stops with the message `Stops2.java:1: error: class Stops is public, should be declared in a file named Stops.java`.

How a File Path Finds a File

A file path is the written route from one place on a computer to a file. The path names each folder along the way, puts a slash after each folder, and ends with the name of the file. From the `cs1-java` folder, the path to the source file is `src/Hello.java`, which means the folder `src` and then the file `Hello.java` inside it. Figure 1 shows this path and a second one, `out/Hello.class`, which leads to the file the compiler made. Two files in the same folder can reach each other by name alone. A file's name alone is not a full file path when the file is in a different folder, so `Hello.java` is a name and `src/Hello.java` is a path. A path that starts from the folder where the computer already is, such as `src/Hello.java`, is called a relative path. An absolute path starts at the top of the whole file system instead, and this class uses relative paths. Windows writes the separator as a backslash, so the same path appears as `src\Hello.java` on a Windows computer.

When a File Path Stops Working

A link or a picture on a web page holds a file path, and so does the command that compiles a Java file. The computer follows the path exactly as it is written, and it does not search other folders for the file. If the file is renamed or moved, the path still points to the old place, so the link breaks. For example, a class web page shows a picture using the path `photos/streetcar.png`. After the picture is moved into a folder named `art`, the page still opens, but a broken-image icon appears where the picture was. The same thing happens with Java. In the `cs1-java` folder, the command `javac -d out src/Hello.java` compiles the source file and writes `Hello.class` into the `out` folder. After `Hello.java` is moved into a new folder inside `src`, the same command stops with `error: file not found: src\Hello.java`. The fix is to change the path so that it matches the file's new place, or to put the file back where the path points.

Summary

A folder holds files and other folders, so the files form a tree. A file extension tells the computer what kind of file it is, such as `.java` for source code and `.class` for bytecode. A file path is the route to a file through its folders, and it stops working when the file it points to is renamed or moved.

Sources: Oracle, What Is a Path? (And Other File System Facts) (n.d.); Oracle, "Hello World" for Microsoft Windows (n.d.); Oracle, The javac Command, JDK 21 (n.d.); MDN, Dealing with files (n.d.); MDN, Creating links (n.d.); MDN, The Image Embed element (n.d.); MDN, Common media types (n.d.); Oracle, The Java Language Specification, Java SE 21 Edition, Chapter 7 (n.d.); classroom data, cs1-java folder and class page tests (2026).

Classwork · Section 1 — Reading 2

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

MC 1. In the file name parade-route.txt, which part is the file extension, and what does it name?

  • parade-route, which names what the file is about
  • .txt, which names the kind of file, plain text
  • .txt, which marks the file as a folder of text files
  • parade-route.txt, which is the full path to the file

MC 2. In the path out/Hello.class, which part is the folder and which part is the file?

  • out is the file, and Hello.class is the folder that holds it
  • out is the folder, and Hello.class is the file inside it
  • Hello is the folder, and .class is the file inside it
  • out/Hello is the folder, and .class is the file

MC 3. Use Figure 1. Which path reaches Stops.java from the cs1-java folder?

  • Stops.java
  • out/Stops.java
  • src/Stops.java
  • cs1-java/src

MC 4. A class web page shows a picture using the path images/levee.png. Someone renames the picture levee-photo.png and leaves it in the images folder. What does the page show?

  • the picture, because the computer looks in the folder for the closest name
  • the picture, because the page updates its path to the new name
  • nothing at all, because the whole page stops opening
  • the page with a broken-image icon, because the path still names levee.png

MC 5. Which type of box holds the value true?

  • String
  • int
  • boolean
  • double

MC 6. Which type of box holds the value "Treme", in double quotes?

  • boolean
  • String
  • double
  • int

MC 7. A program counts 40 students. Which line makes a box that holds only whole numbers and stores 40 in it?

  • double count = 40;
  • String count = 40;
  • int count = 40;
  • boolean count = 40;

MC 8. Which type of box holds the value 2.5?

  • double
  • int
  • String
  • boolean

MC 9. These two lines run inside the standard wrapper. What is printed?

1double blocks = 6;
2System.out.println(blocks);
  • 6
  • 6.0
  • blocks
  • Nothing, because 6 does not fit in a double box

MC 10. Three of these declarations compile. Which one does not compile?

  • double laps = 3;
  • int laps = 3.5;
  • boolean late = false;
  • String name = "Bayou St. John";

CR 1. Name the type of box that each value fits: 16, 0.75, false and "Canal". For each one, give the reason in a few words.

Write your answer in your lab notebook, labeled CR 1.

CR 2. In Reading 2, the line double half = 4; is followed by printing half, and the output is 4.0. In two sentences, explain why Java prints 4.0 here.

Write your answer in your lab notebook, labeled CR 2.

Figure 1. The cs1-java folder holds a src folder with two source files, an out folder with the compiled Hello.class, and a loose notes.txt; the two straight arrows are tagged with the paths that reach Hello.java and Hello.class from cs1-java, and the curved arrow shows javac making Hello.class from Hello.java.
Classwork · Section 2 — Past the floor

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

CR 3. Here is a real folder tree with three folders: bus-app, src and art. Write the path from the bus-app folder to each of the three files: plan.txt, Route.java and bus.png. Then explain how you built the path to bus.png.

bus-app (folder)
    plan.txt
    src (folder)
        Route.java
        art (folder)
            bus.png

Write your answer in your lab notebook, labeled CR 3.

CR 4. A file named Greeting.java holds the code below. Using the passage's Stops2.java example, say what javac reports when it compiles Greeting.java, and give two different ways to fix it.

1// This does not compile.
2public class Hello {
3    public static void main(String[] args) {
4        System.out.println("Hello");
5    }
6}

Write your answer in your lab notebook, labeled CR 4.

Bench Basics

Boxes and Types

Open the bench, do its six jobs, then paste your credit code into the credit-code form. You can turn in up to three codes per bench; your best score is your grade.

Bench Basics opens during your class period.

Classwork

The classwork form is not linked yet. Use Station View and write your answers in your lab notebook with the item labels.

Exit Ticket

This opens during your class period.