Lecture Notes 0: Welcome to CS1111
Objectives
By the end of this module, you will be able to:
- Identify the rules for the course.
- Identify all the tools and mechanisms that will be used in the course.
- At a high level, understand how your computer runs code.
- Run code in the Java Visualizer website.
The Syllabus (Course Information)
The class information is located in the Syllabus link of the navigation bar.
We will go over it now. When you are done checking it out, make sure to continue here.
The Most Important Point: This course is designed so that anyone can learn to program and do well even without any prior experience!
Class participation activity 1: [2 minutes]:
Introduce yourself to at least two people sitting at your table. If you feel comfortable, share whether or not this is your first coding class (and/or share if this is your first time in this building and what you think about the lecture hall).
Using Ed
We will use Ed as our main communication hub.
Please join Ed (via invite emailed to you).
Putting this class in context
Please fill out the Day 1 survey on Ed now.
Let's cover some tips for how to do well in this class (slides will be posted to Ed later)
The HelloWorld program
So, you're taking this course -- what kinds of programs do you want to build one day?
For now, we'll learn about the simplest program we could write in Java: "Hello World". This is the classic basic example (the colors are just highlighting):
public class Hello {
public static void main(String[] args) {
// generate some simple output
System.out.println("Hello, World!");
}
}
This program is written in a programming language called Java. After it gets processed and executed by the computer, the result is that a phrase is printed in the Terminal (more on this later):
"Hello, World!"
First Question: Why not just use English?
- The English language is rich but ambiguous!
- "I saw someone on the hill with a telescope."
- "Look at the dog with one eye."
- "Acceptable uniform colors are red, green, or blue."
- A computer can't know what you "really" meant if you try to specify it in English! So,
- it will do what you said, not what you meant
- this distinction may not be obvious to a human
Solution: Use an unambiguous form of the language, even if it is a little less expressive.
In this case, we will be using the
high-level programming language called
Java.
What is a High-Level Language?
How does a computer execute code? What are the main components of a computer? Let's discuss!
A Low-Level language is composed of the set of instructions that
can be directly executed by the computer's central processing unit (CPU). It is "machine-speak" and it is
very distant from English. To the human, it looks like 0s and 1s. This is because on a computer, 0s and 1s
can be represented through electrical currents (either on or off), and gates can be used to control how
the current flows. No human wants to write in this language.
Solution: represent this low-level language in something easier for humans to deal with. Why? Because
someone needs to eventually be able to easily understand the code to debug it. Then, have software
translate the human-readable language into a low-level language that the machine can process.
These programming languages that are closer to English and that allow you to use abstract terms and
instructions are called High-Level Languages. Some of these are (C, C++, Java, Python, etc).
The conversion of a program (written in a High-Level language) into an executable (written in machine code)
is called Compilation. Note: we'll assume this model for
this course, but there are actually some details we're leaving out right now for the sake of clarity for
those of us new to programming.
Computing Basics
Let's take a little time to explain how computers work, keeping in mind the program above. Take notes! This will be on your first quiz. You should understand:
- What are the main hardware components of a computer.
- What a file system is, and how to navigate through its folders.
- How a file is stored in memory
- At a very high level, explain how the Central Processing Unit (CPU) is used by the computer to execute a computer program that is in memory.
Now you have a basic understanding of how the computer executes any code that you write. This execution happens using a program, typically the Terminal.
Class participation activity 2: [2 minutes]:
Find the "Terminal" (if on Mac) or the "Command Prompt" (if on Windows) on your computer, and open that application. What do you see?
The Terminal is a direct interface with the operating and file system on your computer. You can use it to run your code (we'll do this in lab).
One can also run code on other applications besides the Terminal. We'll do a lot of this using a website called the Java Visualizer (because it allows you to trace through your code live, which really helps with learning how to debug).
Class participation activity 3: [2 minutes]:
Let's visualize running Hello World by copying it (already done for you) into the
Java Visualizer! Note: we will be using the Java Visualizer most of the semester.
Class participation activity 4: [5 minutes]:
Modify the code in the
Java Visualizer to print out your favorite color (you can make this up). Then, run the visualization to make sure it prints
to the terminal. Finally, copy the link the Visualizer creates for a code snippet, and share this link with
the class on Ed under the thread titled "week 1 participation A". Ask a neighbor if you need help with
any part of this exercise -- we want to make sure the whole class is able to use these tools! If both of you
still have questions, raise your hand in lecture and we'll be happy to help!
Class participation activity 5: [1 minute]:
Modify the code in the
Java Visualizer that we used earlier to try to "break" it by making the compiler unable to translate
the Java code into bytecode. We know that it is "safe" for us to change the message "Hello World!"
that gets printed, but see what happens when you touch other parts of this code. You should see an error
message if you successfully broke the code -- we'll see a lot of these during the semester, so don't
be afraid of them! We'll also learn how to interpret these error messages from the compiler.
Class participation activity 6 :[10 minutes] Printing out Hello World is easy, but what if we wanted to write a program for something much more useful? Imagine we wanted to sort a pack of
exams by students' last names -- this makes it a lot easier to enter grades into Blackboard for the TA, since
the student roster there appears alphabetically. In groups of 1-3 students, work together to provide a set
of human instructions (so no code) that explains how to take a stack of unsorted paper exams (they each have one student name
written on them) and convert it into a sorted stack of exams for the TA to use. Write up your answers in
a format "Step 1: ..., Step 2: ..., etc."
Later, you'll write Java code to actually implement a sorting algorithm for this, but that won't be for months! Right now, we're just going to try to get
our first taste at coming up with an algorithm, in English, to do this. Warning: if you haven't done this before, it's actually quite hard! Don't worry if your algorithm isn't perfect.
When you are
finished, each person submit a copy of these answers
(you can take a photo from your phone), under the "week 1 participation B"
link on Blackboard for participation points.
Algorithms vs Programs
Algorithm: The High-Level steps to solve a problem (in English). This is the hard part where we will focus most of our energy this semester.
Program: The algorithm implemented as a set of steps written with correct syntax, and using a set of existing programming features. This is the easier part where you convert your algorithm into a programming language of your choice (like Java).
Syntax and Semantics
We will look into this next class. Just so you have these terms in mind for next class:
Syntax: The set of rules that define well formed sentences in a given language.
In other words: Is the spelling correct, given the language (Java)?
Example: the sentence "He!lp the d,og ate the pizza" has incorrect syntax (even if, as a human,
you might be able to pick up on the meaning.
Semantics: This looks at the meaning of the sentences rather than at how
they are written. In other words, Does the code actually do what we want it to do?.
Example: the sentence "Help, the pizza ate the dog!" has correct syntax but it does not reflect
what the person attempted to say:
Next class:
We'll discuss the basic parts of a program using the Hello World example.
Assignments for next lecture:
Bring your laptop to your lab section to work on Lab 1. Make sure you submit your Lab 1 screenshot to BlackBoard.
On the Schedule, read the "Lecture Notes 02" and be prepared to take a short quiz on Blackboard at the start of the next class on
that material.