[课程笔记]UCB CS61B
Java 数据结构课程,因为懒所以荒废了很久。。
讲课十分有趣清晰,老师很逗( •̀ ω •́ )✧
1.2 Defining and Using Class
javac: compile the java file to class file
java : run the compiled program
why make a class file?
- type check
- ‘simpler’ to execute, distributed code is faster
- protects your intellectual, NO need to give out source code
for every single dog make a new class ?
classe can contain not just functions, but also data
static method and instant method
some classes never instantiated like **math** class i = 0 bark i = 1 woof i = 2 woof i = 3 ? not initializedi = 3 java.lang.NullPointerException
i=3 is not a dog at all
public static void main(String[] args)
command ling argument
Exercise
using libraries
amazing and cool thing of being a programmer
2.1References Recursion and Lists
In class Dog
many instance variables
static variables every dog shares this variable
constructor determine how to instantiate the class Dog in launcher , looks like a method(but its not)
instance method : the method is going to be invoked by a instance variable in this class, then it should be instance(non-static)
In LaunchDog
declaration : declares a variable belongs to a specific class
instantiation : create a new dog
assignment : assign the new dog to a variable
Variables in Java
~~NO?~~ YESa and b are like pointers
NO? NO! simply changing the values y copies xtypes
tells how to interpret these bits in the memory
- byte
- short
- int
- long
- float
- double
- boolean
- char
declaration and assignment
get boxes and filled up with certain bits
Reference type
class instantiation
**new** : find bits(size of the types in the class) "return" the addressDeclaration of reference type
(a pointer :64bits)
reference type works like an arrow
List
1 | Dog[] dogs = new Dog[2] //create 2 dog houses |
Parameter Passing
create a local variable and store the parameter in their scope
called pass by value (always copy the bit)
Declaration and Instantiation of Arrays
1 | Planet p = new APlanet(0,0,0); |
1 | int[] a //Declaration (create a new box, no object is insrantiated) |
Int List
1 | public class IntList { |
1 | public class IntList { |
add methods
1.size
1 | public int size() { |
```
1 | //return the size without using recursion |
2.get
1 | public int iterativeGet(int i) { |
become a super magical list creator