Week 12 Flashcards
o Char[] characters = { ‘A’, ‘B’, ‘C’ } This array is less an “array of chars” it’s an
A reference to an array object, with elements of char datatype that each store one char
o String[] strings = {‘A’, ‘B’, ‘C’} This array is less of an “array of strings” it’s
A reference to an array object, with elements of reference type, and each element stores one reference to a string object
T/F – Elements in an array can be of the programmers created reference type (object), such as Apple[] apples = new Apple[3]
True
o You can create new objects inside of array ___________ _____ , allowing the objects in sequential order to slot into index 1,2,3 and so
Initializer lists, relating back to the issue with parallel arrays
o There are 2 ways to call methods on objects that are referenced inside of an array
1. Call the method using the array name and subscript ie. Apples[0].getVar
2. Copy the reference into a variable, to make it easier to understand
ie. Apple myApple = Apples[0] myApple.setVar
o the String[] in method main
indicates it is an array of references to string objects
o 3 notable things about args
just an identifier, that is called args by convention
Any identifier will work
It’s also a reference variable, that references an array object, that has in each element a reference to a string object
o In cmd, “java” + any argument afterwards
Is placed into an array , with the left-most argument placed at 0. Each argument is treated as a string.
o Checking for ____ first is a defensive programming technique
null
- By-Value versus By-Reference
By value: passing an entire copy. By reference: making an alias to the memory location of something
o Does java allow By value+ By reference?
Java only uses By-value
o What is the value of a reference type?
A reference value, not a copy
o Arrays are a _________ type
A reference type
o Do not directly access values in an array with a custom object and then return a reference to the array
JUST DONT DO IT