CS I · Mon Nov 9 · 15.1 · Do Now

Files, Folders and Paths

Open the discussion form on the right and answer Section 1 from your first reading.

Announcements

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).

I Do questions
  1. notebook cue: file extension

    A folder holds Hello.java and Hello.class. Which file holds source code a person wrote, and which holds bytecode the compiler made? How can you tell from the names alone?

    Check

    Hello.java holds the source code a person wrote, and Hello.class holds the bytecode the compiler made from it. The file extension tells you: .java names a source file and .class names a bytecode file. See What a File Extension Tells the Computer, paragraph 1.

  2. notebook cue: folder

    A file is stored at src/Hello.java. Which part is the folder, and which part is the file?

    Check

    src is the folder and Hello.java is the file. A path names each folder first, puts a slash after it, and ends with the file's name. See How a File Path Finds a File, paragraph 1, and Figure 1.

  3. notebook cue: file path

    A class web page shows a picture using the path photos/streetcar.png. A student moves the picture into a folder named art. What does the page show now, and why?

    Check

    The page still opens, but a broken-image icon appears where the picture was. The page's file path still points to photos/streetcar.png, and the computer follows the path exactly as written without searching other folders. See When a File Path Stops Working, paragraph 1.

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.
I Do questions
  1. notebook cue: file extension

    A folder holds Hello.java and Hello.class. Which file holds source code a person wrote, and which holds bytecode the compiler made? How can you tell from the names alone?

    Check

    Hello.java holds the source code a person wrote, and Hello.class holds the bytecode the compiler made from it. The file extension tells you: .java names a source file and .class names a bytecode file. See What a File Extension Tells the Computer, paragraph 1.

  2. notebook cue: folder

    A file is stored at src/Hello.java. Which part is the folder, and which part is the file?

    Check

    src is the folder and Hello.java is the file. A path names each folder first, puts a slash after it, and ends with the file's name. See How a File Path Finds a File, paragraph 1, and Figure 1.

  3. notebook cue: file path

    A class web page shows a picture using the path photos/streetcar.png. A student moves the picture into a folder named art. What does the page show now, and why?

    Check

    The page still opens, but a broken-image icon appears where the picture was. The page's file path still points to photos/streetcar.png, and the computer follows the path exactly as written without searching other folders. See When a File Path Stops Working, paragraph 1.

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).

Table Talk
A Java file named Hello.java sits inside a folder named src. Write the path to it from the folder that holds src. Then name one change that would make that path stop working.

Each table writes the path the same way and agrees on two changes that would break it.

Chromebooks stay closed while your table talks. Sections 1 and 2 of the discussion form are already done. After you talk, finish Section 3 right here under My View. Submit before the exit ticket.

This form has three sections. Section 1: answer today's Board Question. Section 2: after the reading. Section 3 opens later in class. Today's Board Question: A Java file named Hello.java sits inside a folder named src. Write the path to it from the folder that holds src. Then name one change that would make that path stop working.

CR 1. Board Question: A Java file named Hello.java sits inside a folder named src. Write the path to it from the folder that holds src. Then name one change that would make that path stop working. Give your answer and one reason.

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

MC 1. Think about your answer to the board question. A Java file named Hello.java sits inside a folder named src. Write the path to it from the folder that holds src. Then name one change that would make that path stop working. Which position is closest to yours now?

  • Hello.java is enough, because the computer searches every folder for it.
  • src/Hello.java, and it stops working if the file or the folder is renamed or moved.
  • The path is just Hello, because Java does not need the extension.

MC 2. (Reading claim 1) A file path keeps working after the file it points to is moved.

  • Agree
  • Disagree

MC 3. (Reading claim 2) The extension .class tells you the file holds bytecode, not source code.

  • Agree
  • Disagree

MC 4. (Reading claim 3) A folder can hold other folders.

  • Agree
  • Disagree

MC 5. (Reading claim 4) In Figure 1, the path from cs1-java to Stops.java is out/Stops.java.

  • Agree
  • Disagree

MC 6. (Reading claim 5) Two files in the same folder can reach each other by name alone.

  • Agree
  • Disagree

MC 7. (Reading claim 6) Renaming notes.txt to notes.png turns the text into a picture.

  • Agree
  • Disagree

MC 8. (Reading claim 7) A public class named Stops can be kept in a file named Stops2.java.

  • Agree
  • Disagree

MC 9. (Reading claim 8) In Figure 1, notes.txt is inside the cs1-java folder but not inside src or out.

  • Agree
  • Disagree

CR 2. (A different view) Write the view at your table that was most different from yours. If everyone agreed, write the strongest argument against your table's answer.

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

CR 3. Think about the Board Question again: A Java file named Hello.java sits inside a folder named src. Write the path to it from the folder that holds src. Then name one change that would make that path stop working. Do you have the same opinion as when you first answered the board question? If it is the same, what from the reading or table talk reaffirmed your opinion? If it is different, what from the reading or table talk changed your opinion?

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