CS 151 - Lecture 1

Cay S. Horstmann
CS 151
The Textbook

- Great book, if I may say so
- Ok, it was great circa 2005
- I am revising the book
- You'll get draft pages here
- Username:
design
, password patterns
- Refresh your copy when I tell you as the semester progresses
- Don't post them anywhere!
- No need to buy a printed book
What? No Lectures?

- A thousand years ago, books were expensive
- Few students were able to read
- Solution: Lectures
- But lectures are inefficient
- Far longer than attention span
- Meaningful interaction limited to small number of students
- Good news: Books are cheap and students can read
- Read the textbook ahead of class
- Class time: Labs, discussions, activities
- Be prepared to answer questions about the pre-class readings in class
What You Need to Succeed

- Prerequisites
- CS1/CS2: Loops, arrays, input/output, sets and maps, etc.
- Java
- Time
- You can't expect to learn complex skills just by listening to lectures
- Spend 9 hours per week for this class
- 2.5 hours in class
- 6.5 hours (!) outside class for preparation and homework
- Laptop
- Bring it to each class meeting
- Be able to run a Bash shell
Questions

- Ask questions right away when you are stuck
- Use the online discussion group (https://piazza.com/class/spring2019/cs151).
- You'll get a better grade if you ask lots of questions.
- Answer your peers' questions. You'll get a better grade if you do.
- Private or confidential questions—email or office hours
Plagiarism and Cheating

- When you submit work, it must be your intellectual creation
- Can you copy and paste?
- Always ok to copy—pasting is the problem ☺
- Ok to use code from the problem statement or the textbook without attribution
- Otherwise, you must attribute the source
- You can post snippets (but not a solution) on Piazza for critique
- But you cannot copy from Piazza
- Don't email working code—you don't know what the recipient will do with it
- Sending someone a solution is cheating
- I periodically run a plagiarism checker
- If I find cheating, I don't play Sherlock Holmes to find who wrote it—I report both
- I report everyone whom I find cheating to Student Conduct
- I have to
- And I will recommend that an appropriate penalty is for you to fail the course
Git

- You submit all class work via Git
- Make a private repo on BitBucket, GitHub, or GitLab
- Add me as a contributor to your repo. My BitBucket, GitHub, GitLab ids are
cayhorstmann
- Use a single repo for all homework and exams
- That's a single repo for everything. Not a separate repo for each assignment.
- Did I mention it's just one repo for all your work in this class?
- Make folders
hw1
, hw2
, lab1
, exam1
, ..., as directed.
- Don't be a knucklehead. When I say
hw1
, I mean the small letters h, w, and the digit 1 (Unicode U+0068, U+0077, U+0031). And not homework1
, HW1
, Homework 1
, etc.
- Commit at least once a day for homework/every 10 min in an exam
- Push before midnight on due date. Grace period until 6am next morning. No mercy afterwards.
Adding

- Do homework 1 and send me your answers.
- I will send you an add code when space becomes available. Use it within 24 hours, or it will become invalid
- Show up for all classes/labs even if you haven't received your code
Things To Do Today

- Log into Piazza
- Start reading the textbook
- Install Java 11 and Git on your laptop
- You need bash. If you run Windows, install VirtualBox and a Linux VM.
- Complete Homework 1 and send me your Git repo URL
- Important: In lieu of a roll call today, you must turn in homework 1, or I will drop you from this course for lack of presence/prerequisites.
Lab

- Solving a simple programming problem
- Getting going with Git
A Simple Programming Problem
- Solve this simple problem: In Java, implement the method
Arrays.swapLargestAndSmallest(int[] a)
that swaps the largest and smallest element in a. If there are multiple largest or smallest elements, pick the first one.
- Check your answer in CodeCheck.
Bash

- You must be able to run Bash commands
- This was supposed to have been covered in CS46B
- If not, consider working through this lab
- If you run Windows, you can install the Windows subsystem for Linux, use Cygwin, or whatever, if you know what you are doing
- If you use Mac OS, you can use bash, and make the occasional adjustments from Linux to BSD commands, if you know what you are doing
- If you want any support from me, run Linux, either dual boot (if you know what you are doing), or install a Linux virtual machine.
Git

- Make an account on BitBucket, or if you prefer (and you know what you are doing), on GitHub or GitLab. I give instructions for BitBucket.
- Make a repository on BitBucket. Be sure it is a private repo. Call it
cs151
. Add me (cayhorstmann
) as a collaborator with Write access (in Settings → Access Management → Users).
- Start a Bash shell.
- Clone the repo:
git clone git@bitbucket.org:yourname/cs151.git cs151
where you replace yourname
with your BitBucket user name.
Adding to the Repository
- Open a terminal and change to the directory into which you cloned the repo:
cd cs151
- Make a subdirectory
lab1
:
mkdir lab1
- In that directory, make a file
Arrays.java
:
touch lab1/Arrays.java
- Open the file with your favorite text editor and paste in the solution to the simple programming problem. If you couldn't solve the problem, just put in the outline from CodeCheck.
- Add the file: Type
git add lab1/Arrays.java
- Commit all changes: Type
git commit -a -m "Added lab1"
- Push to BitBucket: Type
git push origin master
- In the BitBucket web interface, locate
Arrays.java
- Did you find it? Hooray—you have just reached level 2.
- Those three commands—add, commit, push—are all you need to know about Git to complete homework 1.
Be The Grader

- Check out your repo into a temporary location (which we'll call the grader repo). Replace
yourname
with your BitBucket user name.
cd /tmp
rm -rf cs151
git clone git@bitbucket.org:yourname/cs151.git cs151
- Do what the grader would: Compile and run the program on the command line.
cd /tmp/cs151/lab1
curl -O http://horstmann.com/sjsu/spring2019/cs151/day1/Tester.java
javac Tester.java
java Tester
- Did it work? If not, why not? Ponder what the grader will do when it doesn't work the first try. (Hint: Nothing.)
- If it didn't work at the outset, fix your issues in your student repo. In another terminal, push the changes to your student repo. In the terminal in which you are the grader, run
git pull
. Try compiling and running again.
- Add the compiler and tester output to a file
lab1/report.txt
in your student repo (not the grader repo). Put in your and your buddy's name.
- Add the file, commit, and push.