Introduction to 61B, Java
1
Lecture 1
CS61B, Spring 2025 @ UC Berkeley
Lecturers: Justin Yokota, Josh Hug
Slides Credit: Josh Hug
Course website: https://sp25.datastructur.es
Ask your questions in the Zoom chat! (link on website)
Welcome to 61B
Lecture 1, CS61B, Fall 2024
2
61B Overview
What is 61B about?
Assumes solid foundation in programming fundamentals, including:
Why 61B?
Other great features of 61B:
About Us (Josh)
Josh Hug: Berkeley faculty since 2014.
5
Plug:
About Us (Justin)
Justin Yokota: Berkeley Lecturer since 2022.
Question for You
What do you hope / expect to learn from this class? Why are you taking it?
Who are you?
61B Logistics
Lecture 1, CS61B, Fall 2024
8
Joining the Course
Course Components
Lectures provide you with an introduction and a foundation.
You’ll learn most of what you learn in the class by:
Class Phase
This class is divided into three phases:
Evaluation
Four types of points in this class:
Full details around point distributions, letter grade assignments, grade replacement, etc. are on the website.
Cheating
Please don't cheat…
Most cases can be categorized into one of three types:
How to avoid Accidental Cheating
Our goal in the class is to maximize the amount of learning that gets done.
General rule: If something can potentially allow someone to get a nonzero score on an assignment without them reaching the assignment's learning objectives, it likely constitutes cheating.
Examples of things that are not allowed:
Examples of things that are allowed:
Why Cheating is not Rational
Many of our misconduct penalties are designed to deter rational cheating
Our cheat detection methods are very robust
Even if you bypass all those cheat-detection methods and get points for something that's not your work, you're losing out on the practice we want you to get from the assignment, and will likely lose any points you gained when you do worse on the next exam as a result.
How to avoid Irrational Cheating
Desperation can cause you to do things you would not normally do, even if you know rationally that it'll likely put you in a worse position later.
The best way to avoid irrational cheating is to make sure you never reach that point of desperation in the first place:
If you're falling behind in the class, let us know! We'll work with you to maximize the amount of learning you can get from the class.
Lateness Policies
The deadlines in this class are the day by which assignments should be completed.
There is no partial credit for work submitted late. Gradescope gives zero points by default to late work.
To provide some flexibility, https://beacon.datastructur.es/ will allow you to request extensions. These can be retroactive, but we recommend requesting in advance.
If you have extenuating circumstances, see syllabus.
Hello World
Lecture 1, CS61B, Fall 2024
18
Intro to Java
Let’s try writing some simple Java programs.
If you’ve never written in code in Python or Java, this will be a little harder for you, but still comprehensible.
This section might be a bit boring if you have Java experience.
(See video or code linked on course website)
Lecture code repository: https://github.com/Berkeley-CS61B/lectureCode-sp25
Coding Demo: Hello World
hello.py
public class HelloWorld {
public static void main(String[] args) {
}
}
HelloWorld.java
Coding Demo: Hello World
print("hello world")
hello.py
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello world");
}
}
HelloWorld.java
Java and Object Orientation
Reflections on Hello World:
Java is an object oriented language with strict requirements:
*: This is not completely true, e.g. we can also declare “interfaces” in .java files that may contain code. We’ll cover these soon.
Hello Numbers
Lecture 1, CS61B, Fall 2024
23
Coding Demo: Hello Numbers
x = 0;
while x < 10:
print(x)
x = x + 1
hellonumbers.py
public class HelloNumbers {
public static void main(String[] args) {
x = 0;
while (x < 10) {
System.out.println(x);
x = x + 1;
}
}
}
HelloNumbers.java
Coding Demo: Hello Numbers
x = 0;
while x < 10:
print(x)
x = x + 1
hellonumbers.py
public class HelloNumbers {
public static void main(String[] args) {
int x;
x = 0;
while (x < 10) {
System.out.println(x);
x = x + 1;
}
}
}
HelloNumbers.java
Coding Demo: Hello Numbers
x = 0;
while x < 10:
print(x)
x = x + 1
hellonumbers.py
public class HelloNumbers {
public static void main(String[] args) {
int x = 0;
while (x < 10) {
System.out.println(x);
x = x + 1;
}
}
}
HelloNumbers.java
Coding Demo: Hello Numbers
x = 0;
while x < 10:
print(x)
x = x + 1
x = "horse" # works
print(x)
hellonumbers.py
public class HelloNumbers {
public static void main(String[] args) {
int x = 0;
while (x < 10) {
System.out.println(x);
x = x + 1;
}
x = "horse"; // doesn't work
String x = "horse"; // doesn't work
}
}
HelloNumbers.java
Coding Demo: Hello Numbers
x = 0;
while x < 10:
print(x)
x = x + 1
# crashes here
print(5 + "horse")
hellonumbers.py
public class HelloNumbers {
public static void main(String[] args) {
int x = 0;
while (x < 10) {
System.out.println(x);
x = x + 1;
}
x = "horse"; // program doesn't run
}
}
HelloNumbers.java
Java and Static Typing
Reflections on Hello Numbers:
Java is statically typed!
Larger
Lecture 1, CS61B, Fall 2024
30
Coding Demo: Larger
def larger(x, y):
if (x > y):
return x
return y
larger.py
public class LargerDemo {
public static larger(x, y) {
if (x > y) {
return x;
}
return y;
}
}
LargerDemo.java
Coding Demo: Larger
def larger(x, y):
if (x > y):
return x
return y
larger.py
public class LargerDemo {
public static int larger(int x, int y) {
if (x > y) {
return x;
}
return y;
}
}
LargerDemo.java
Coding Demo: Larger
def larger(x, y):
if (x > y):
return x
return y
print(larger(-5, 10))
larger.py
public class LargerDemo {
public static int larger(int x, int y) {
if (x > y) {
return x;
}
return y;
}
public static void main(String[] args) {
System.out.println(larger(-5, 10));
}
}
LargerDemo.java
Larger: Reflections
Coding Demo: Larger
/** Demonstrates creation of a method in Java. */
public class LargerDemo {
/** Returns the larger of x and y. */
public static int larger(int x, int y) {
if (x > y) {
return x;
}
return y;
}
public static void main(String[] args) {
System.out.println(larger(-5, 10));
}
}
LargerDemo.java
Reflections on Java
Lecture 1, CS61B, Fall 2024
36
Compilation vs. Interpretation
In Java, compilation and interpretation are two separate steps.
Hello.java
Hello.class
javac
java
stuff
happens
Compiler
Interpreter
Why make a class file at all?
Note: .class files are easily reversible into similar looking Java files.
You can learn more about all this in 61C and particularly 164.
Reflections on Static Typing
The Good:
The Bad:
Reflections on Static Typing
The Good:
�The Bad:
Compilation
Lecture 1, CS61B, Spring 2025
40
Demo: Compilation in Terminal
jug ~/.../intro1
$ ls
HelloWorld.java
$ javac HelloWorld.java
$ ls
HelloWorld.class HelloWorld.java
$ java HelloWorld
Hello World!
IntelliJ
Lecture 1, CS61B, Spring 2025
We won't cover these slides live in class, and they won't be tested on exams. Check out the videos in the playlist if you're interested.
42
Example Workflows
There are many different workflows for writing programs.
Let’s see what our programs look like in the IDE for our course.
IntelliJ Screenshot
Example feature: IntelliJ automatically and continuously detects syntax errors.
Admonition
Our expectation is that everyone in this class is using IntelliJ.
HW0: Due Friday!
Lecture 1, CS61B, Fall 2024
46
Time to Go Learn Java Basics!
I am not going to spend time in this class covering for loops, while loops, etc. in Java!
HW0 is out, and is due this Friday!
If you can, start lab 1 early! Most of it is just downloading and installing software.