Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 14, 2023
Section 2.4 - COMP SCI 300: Programming II
A parameter of reference type allows object modification only through the object's public methods or fields. Assigning a different value to a parameter variable of reference type, as in device = new DeviceOrientation();, assigns a new object to the reference variable, but does not modify the original object to which the variable first referred.
Because reference variables store object locations and not the object data itself, passing a reference variable as a method argument assigns the argument's stored reference to the corresponding method parameter. Similarly, returning a reference variable returns an object reference.
Assigning the variable travelTime later with another value, such as travelTime = 11;, creates a completely new object and assigns travelTime to refer to the new object's reference.
Section 2.4 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 14, 2023
Section 2.3 - COMP SCI 300: Programming II
When the result of an expression is assigned to an Integer reference variable, memory for a new Integer object with the computed value is allocated, and the reference (or address) of this new object is assigned to the reference variable. A new memory allocation occurs every time a new value is assigned to an Integer variable, and the previous memory location to which the variable referred, remains unmodified.
t Java maintains a cache of Integer objects for literal values -128 to 127 (inclusive).
A new Integer object is created and assigned with 400 / 60, or 6, and timeHrs is updated to refer to that new Integer object.
Section 2.3 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 14, 2023
Section 1.8 - COMP SCI 300: Programming II
This mistake occurs because programmers forget that primitive data values, like the size of an array, cannot be modified within methods.
new array size
Section 1.8 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 13, 2023
Quiz: Practice Quiz Part1
= new int[0];
Quiz: Practice Quiz Part1canvas.wisc.edu
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 11, 2023
Section 4.10 - COMP SCI 300: Programming II
A testbench is a program whose job is to thoroughly test another program (or portion) via a series of input/output checks known as test cases.
Regression testing means to retest an item like a class anytime that item is changed; if previously-passed test cases fail, the item has "regressed".
Section 4.10 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 11, 2023
Section 4.8 - COMP SCI 300: Programming II
The keyword static indicates a variable is allocated in memory only once during a program's execution. Static variables reside in the program's static memory region and have a global scope.
When a Store object is created, memory is allocated for the object's name, type, and id fields, but not the static field nextId.
Any class method can access or mutate a static field. Because nextId is public, nextId can also be accessed outside the class using the member access operator (.) keyboard_arrow_up
Section 4.8 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 11, 2023
Section 4.6 - COMP SCI 300: Programming II
the object's reference, which can be thought of as the object's memory address, is passed to the method via the implicit "this" parameter.
The "this" keyword can also be used in a constructor to invoke a different (overloaded) constructor. In the default constructor below, this(0, 0); invokes the other constructor to initialize both fields to zero. For this example, a programmer could have just set both fields to zero within the default constructor. However, invoking other constructors is useful when a class' initialization routine is lengthy and avoids rewriting the same code.
Section 4.6 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 11, 2023
Section 4.6 - COMP SCI 300: Programming II
An object's member method
if a field member and parameter have the same identifier.
the object's reference, which can be thought of as the object's memory address, is passed to the method via the implicit "this" parameter.
Section 4.6 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 10, 2023
Section 4.5 - COMP SCI 300: Programming II
Programmers often want to provide different initialization values when creating a new object. A class creator can overload a constructor by defining multiple constructors differing in parameter types
If a programmer defines any constructor, the compiler does not implicitly define a default constructor, so good practice is for the programmer to also explicitly define a default constructor so that an object creation like new MyClass() remains supported
Section 4.5 - COMP SCI 300: Programming IIlearn.zybooks.com
Sukriti Somvanshi
@sukritisomvanshi24k0tzadexcg• Feb 10, 2023
Section 4.4 - COMP SCI 300: Programming II
member method,
f a class does not have a programmer-defined constructor, then the Java compiler implicitly defines a default constructor with no arguments. The Java compiler also initializes all fields to their default values.
when an object of that class type is created, and which can be used to initialize all fields. The constructor has the same name as the class. The constructor method has no return type, not even void.
Section 4.4 - COMP SCI 300: Programming IIlearn.zybooks.com