Pages

Jun 8, 2015

[CS61B-2015] Notes for class 4-Testing



https://berkeley-cs61b.github.io/public_html/materials/lab/lab2/lab2.html

import org.junit.Test;
import static org.junit.Assert;
assertEquals(expected, actual);

To make testing output more concise
1. Annotate each test with @org.junit.Test
2. Make methods non-static
3. jh61b.junit.textui.runClasses

example:
https://github.com/Berkeley-CS61B/lectureCode/blob/master/lec4/live1/TestSort.java


Jun 7, 2015

Using the "final" keyword in Java

Using the "final" keyword in Java has different meaning depending on what it applied to:

  • Variable: the value cannot be changed once initialized.
  • Method: the method cannot be overridden by a subclass.
  • Class: the class cannot be subclassed.

Notes for "Head first Java"


  • A boolean and an integer are not compatible types in Java
    • int x = 1;
    • While(x)...
  • Objects are stored in heap (Garbage-collectible heap).
  • If you're running low on memory, the Garbage Collector will run, throw out the unreachable objects (no reference points to them).
  • There is no "global variable" in Java. Use public static instead. Any code, in any class of your application, can access a public static method/variable.
  • If the end-user doesn't have a JVM, then you'll also need to include that with your application's classes.

[CS61B-2015] Notes for class 3




A variable name in Java is a name for a simple container.
The 9 things that can go in simple containers:

  • primitive values(byte, short, int, long, float, double, boolean, char
  • references to Objects (an arrow), references may be null

Java is "Pass by value" (in some case, the "value" is a reference?)


Jun 5, 2015

[CS61B-2015] Notes for class 2-Defining and using classes



Static vs. Non-static
A class may have a mix of static and non-static members.

  • A variable or method defined in a class is also called a member of that class.
  • Static members are accessed using class name, e.g. ClassName.StaticMember.
  • Non-static members cannot be invoked using class name: Dog.makeNoise().
  • Static methods must access instance variables via a specific instance, e.g. an object.
  • Static members are shared in a class.

Good Git tutorials