[公开课] CS61B打卡(Spring2018) 第一部分week1-6:Java基础

这是一个关于加州大学伯克利分校CS61B春季2018课程的资源汇总,涵盖了Java基础知识、数据结构、编程作业和资源链接,包括官方讲义、自动评分系统、IDEA教程、Java和数据结构讲义等。
摘要由CSDN通过智能技术生成

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一直没看,也要看!!!!!!!

作业中做错的地方:

  • disc02: Scope; Pass-by-Value; Static:
  • disc03:
    • SLList: insert; reverse(iterative and recursive)
    • AList: insert; reverse(iterative and recursive), replicate
  • proj1a: Double Ended Queue (DataStructure: Deque)
  • proj1b: Palindrome and OffByN (HoFs)
  • disc04 exam prep
    1. distinguish overload from override
    2. Upcasting (always safe) and downcasting (allowable but can be dangerous).
    3. 第四题值得再看看一看
  • class: Syntax: ArrapMap implementation:
    note: “x == y” means asking “are these two pointing to the same object” ? so you probably want to use (x.equals(y)).

Textbook: 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.

    • All functions are methods. Functions in Java return only one value.
    • Java is an object oriented language with strict requirements:
    1. Every Java file must contain a class declaration*( This is not completely true, we can also declare “interfaces” in .Java files that may contain code. We’ll cover these later).
    2. All codes lives inside a class*, even helper functions, global constants, etc.
    3. To run a Java program, you typically define a main method using public static void main(String[] args)
    • Java is statically typed!
    1. All variables, parameters, and methods must have a declared type.
    2. That type can never change.
    3. Expressions also have a type.
    4. The compiler checks that all the types in your program are compatible before the program ever runs! (This is unlike Python, where type checks are performed DURING execution)
    • Style Guide!!! https://sp19.datastructur.es/materials/guides/style-guide.html
    • Javadoc comments: https://en.wikipedia.org/wiki/Javadoc
    • Defining a Typical Class (Terminology)
      • Instance variable.
      • Constructor
      • Non-static method, a.k.a. Instance Method.
      • Roughly speaking: If the method needs to use “my instance variables”, the method must be non-static.
    • Instantiating a Class and Terminology
      • Declaration of a Dog variable
      • Instantiation of the Dog class as a Dog Object.
      • Instantiation and Assignment
      • Declaration, Instantiation and Assignment
      • Invocation of the 150 lb Dog’s makeNoise method.
    • Static vs. Non-static (a.k.a. instance)
      • Static methods are invoked using the class name, e.g. Dog.makeNoise();
      • Instance methods are invoked using an instance name, e.g. maya.makeNoise();
      • Static methods can’t access “my” instance variables, because there is no “me”.
    • Why Static Methods?
      • Some classes are never instantiated.
    • public static void main(String[] args)
    • Using Libraries (e.g. StdDraw, In): A useful library: The Princeton Standard Library
  • Project 0 (TODO: Test and Extra)

  • Week 2 (1/22-1/26) : References, Recursion, and Lists; SLLists, Nested Classes, Sentinel Nodes; DLLists, Arrays

    • Lists1
      • The Mystery of the Walrus
      • Primitive Types (8: byte, short, int, long, float, double, boolean, char)
      • Reference Types (everything else, including arrays, is a reference type)
      • Parameter Passing: passing parameters obeys the same rule: simply copy the bits to the new scope(passing by value)
      • Summary: there are 9 types of variables in Java: 8 primitive types and reference type.
      • Instantiating Arrays
        • Declaration and Instantiation of Arrays
      • IntList and Linked Data Structures
        • IntList, IntList size(recursive method), IntList iterativeSize(no recursive method), More Exercises
    • Lists2: The SLList (“naked” linked lists like the IntList class are hard to use; SLList class acts as a middle man between user and raw data structure)
      • Intro
      • Access Control: using private keyword
        • Why Restrict Access? Hide implementation details from users of your class.
          • Less for user of class to understand.
          • Safe for you to change private methods(implementation).
        • Car analogy:
          • Public: Pedals, Steering Wheel; Private: Fuel line, Rotary valve.
        • Despite the term ‘access control’:
          • Nothing to do with protection against hackers, spies, and other evil entities.
      • Nested Classes
        • static: if IntNode class never try to use its outer class stuff, then you can make IntNode static.
      • Adding More SLList Functionally
        • .addLast(int x)
        • .size()
      • Caching: After implementing .addLast and .size, both of them are very slow. How to improve? Fast size()
        • Solution: Maintain a special size variable that caches the size of the list.
        • Caching: putting aside data to speed up retrieval.
      • Sentinel Node (哨兵) : 去除特殊例子(比如 if x == null)的代码改进处理。
        • Notes:
          • I’ve renamed first to be sentinel;
          • sentinel is never null, always points to sentinel node.
          • Sentinel node’s item needs to be some integer, but doesn’t matter what value we pick.
          • Had to fix constructors and methods to be compatible with sentinel nodes.
        • Bottom line: Having a sentinel simplifies our addLast method.
      • Invariants(Invariants make it easier to reason about code)
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?

    • Lists3: The DLList (Double Linked Lists): reverse pointers allow all operations (add, get, remove) to be fast.
      • DLList(Naive) -> DLList(Double Sentinel) (use for proj1) -> DLList(Circular Sentinel) (proj1)
      • Generic Lists
        • Java allows us to defer type selection until declaration.
        • In the .java file implementing your data structure, specify your “generic type” only once at the very top of the file.
        • In .java files that use your data structure, specify desired type once:
          • Write out desired type during declaration.
          • Use the empty diamond
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值