Archive: http://inst.eecs.berkeley.edu/~cs61b/archives.html
Spring 2019: https://sp19.datastructur.es
Spring 2018: https://sp18.datastructur.es
LectureCode: https://github.com/Berkeley-CS61B/lectureCode
Autograder: https://www.gradescope.com (To sign up, use the entry code 93PK75)
The autograder is now open to the public. Sign up using entry code MNXYKX at gradescope.com.
grepcode.
A Java Reference: http://www-inst.eecs.berkeley.edu/~cs61b/fa14/book1/java.pdf
Head First Java: https://www.safaribooksonline.com/library/view/head-first-java/0596009208/
其他资源:
https://www.1point3acres.com/bbs/thread-282583-1-1.html
这是数据结构讲义:
https://inst.eecs.berkeley.edu/~cs61b/fa18/materials/book2/data-structures.pdf
这是Java讲义:
https://inst.eecs.berkeley.edu/~cs61b/fa18/materials/book1/java.pdf
IntelliJ IDEA破解版教程:https://blog.csdn.net/qq_42914528/article/details/89710864
IntelliJ IDEA遇到的一些问题
这门课边看边学。
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
Reading一直没看,也要看!!!!!!!
作业中做错的地方:
rm
指令没法在回收站里找到。。。突然脑抽把mv
达成rm
,结果文件被删没了。。。解决方法参考这个 https://www.jianshu.com/p/5552f3340682Textbook: CS61B
https://joshhug.gitbooks.io/hug61b/content/chap1/chap11.html
Week 0 : Welcome to CS61B & Course Policies and Logistics
Week 1 (1/17-1/19) : Intro, Hello World Java & Defining and Using Classes.
public static void main(String[] args)
Project 0 (TODO: Test and Extra)
Week 2 (1/22-1/26) : References, Recursion, and Lists; SLLists, Nested Classes, Sentinel Nodes; DLLists, Arrays
private
keyword
first
to be sentinel;addLast
method.Methods | Non-Obvious Improvements |
---|---|
addFirst(int x) | #1: Rebranding: IntList -> IntNode |
getFirst | #2: Bureaucracy: SLList |
addLast(int x) | #3: Access Control: public -> private |
size() | #4: Nested Class: Bringing IntNode into SLList |
#5: Caching: Saving size as an int | |
#6: Generalizing: Adding a sentinel node to allow representation of the empty list. | |
#7: Looking back: .last and .prev allow fast removeLast (SLList -> DLList) | |
#8: Sentinel upgrade: Avoiding special cases with sentBack or circular list. Fancier Sentinel Node(s) |
How could we modify our list data structure so that addLast is also fast?
System.arraycopy(b, 0, x, 3, 2)
:
Week 3 (1/29-2/2) : ALists, Resizing, vs. SLists; Testing; Inheritance, Implements.
get(int i)
, if we use DList it is too slow. How can we fixed this? Glorp[] items = (Glorp []) new Object[8];
public interface Animal {
default void greet(Animal a) {
print("hello animal"); }
default void sniff(Animal a) {
print("sniff animal"); }
default void flatter(Animal a) {
print("u r cool animal"); }
}
public class Dog implements Animal {
void sniff(Animal a) {
print("dog sniff animal"); }
void flatter(Dog a) {
print("u r cool dog") ; }
}
Animal a = new Dog();
Dog d = new Dog();
a.greet(d); // "hello animal"
a.sniff(d); // "dog sniff animal"
d.flatter(d); // "u r cool dog"
a.flatter(d); // "u r cool animal"
The way we define overriding is they have EXACT the same signature, so flatter example is overloading, not overriding.
Inheritance 1: Is a v.s. Has a, Interface v.s. Implementation Inheritance
Week 4 (2/5-2/9) : Extends, Casting, Higher Order Functions; Subtype Polymorphism vs. HoFs; Libraries, Abstract Classes, Packages.
Inheritance 2: Implementation Inheritance: Extends keyword. Basic Use of Extends
public class RotatingSLList- extends SLList
Inheritance 2: Extends with Overriding (Example VengefulSLList)
super
call superclass’s method.Inheritance 2: A Boring Constructor Gotcha
super(x)
Inheritance 2: The Object Class
Inheritance 2: Encapsulation
Inheritance 2: Implementation Inheritance Breaks Encapsulation
Inheritance 2: Type Checking and Casting
public static void main(String[] args) {
VengefulSLList<Integer> vsl = new VengefulSLList<Integer>(9);
SLList<Integer> sl = vsl;
sl.addLast(50);
sl.removeLast();
sl.printLostItems(); //Compilation errors!
VengefulSLList<Integer> vsl2 = sl; //Compilation errors!
SLList<Integer> sl3 = new VengefulSLList<Integer>(); //OK
maxDog(frank, frankJr);
(Poodle) maxDog(frank, frankJr);
Inheritance 2: Higher Order Functions in Java
% python
def tenX(x):
return 10*x
def do_twice(f,x):
return f(f(x))
print(do_twice(tenX, 2))
/** java file 1 */
public interface IntUnaryFunction {
int apply(int x);
}
/** java file 2 */
public class TenX implements IntUnaryFunction {
public static int TenX(int x) {
return 10 * x;
}
}
/** java file 3 */
public class HoFDemo {
public static int do_twice(IntUnaryFunction f, int x) {
return f.apply(f.apply(x));
}
public statc void main(String[] args) {
IntUnaryFunction tenX = new TenX();
do_twice(tenX, 2);
}
Implementation Inheritance Cheatsheet
Inheritance 3 - 4: 写到Packages部分网页崩了。没保存。我哭了。
Inheritance 4: Packages
import ug.joshh.animal.Dog;
Dog d = new Dog(...);
Week 5 (2/5-2/9) : Coding in the Real World, Review, Generics, Autoboxing, Exceptions, Iterators, Iterables
@Test
public void test() {
ArrayMap<Integer, Integer> am = new ArrayMap<Interger, Integer>();
am.put(2, 5);
int expected = 5;
assertEquals(expected, am.get(2));
}.
/**
* the actual call is: assertEquals(int, Integer)
* So we need to: assertEquals(long, long)
* Step1: Widen expected to long
* Step2: Unbox am.get(2)
* Step3: Widen the unboxed am.get(2) to long.
* Or assertEquals(Object, Object)
* Step: Autobox "expected" into an Integer (**However, it is ambiguous and won't complie**)
* Or casting
* assertEquals( (Integer) expected, am.get(2)); (**works!**)
*/
public static <K, V> V get(Map61B<K, V> sim, K key) {
... }
public static <K extends Comparable<K>, V> K maxKey(Map61B<K, V> map) {
List<K> keylist = map.keys();
K largest = keylist.get(0);
for (K k : keylist) {
if (k.compareTo(largest) > 0) {
. // you cannot say "if (k > largest) because only numericla primitives can be compared with >; New problem: K's don't necessarily have a compareTo methods"
largest = k;
}
}
return largest;
}
public static void gulgate() throws IOException {
... throw new IOException("hi");...
}
Modifier | Class | Package | Subclass | World |
---|---|---|---|---|
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
(put no keyword at all, called package private) | Y | Y | N | N |
private | Y | N | N | N |
Syntax 3: Access Modifier Questions
Syntax 3: Access Control Subtleties
package universe;
public interface BlackHole {
void add(Object x);
}
add might look package-private, but actually public!!! Because in interface, if you don’t say, then it is public.Syntax 3: Object Methods
The Future