Chapter 3 - Assignments Flashcards
Assignments: Class Members, develop Wrapper Code and Autoboxing Code Determine effects of passing variables to methods Recognize when objects become eligible for garbage collection
Local Variables
Live on the stack
Objects and instance Variables
Live on the Heap
Integer literals
can be decimal, octal, or hexadecimal
Float literals end in
F or f
Double literals end in
D or d
Boolean literals
are true and false
scope
refers to the lifetime of a variable
4 basic scopes
- Static variables live basically as long as their class lives
- Instance variables live as long as their object lives
- Local variables live as long as their method
- Block variables live until the block completes
Literal integers
are implicitly ints
integer expressions
always end in a int-sized result, never smaller
floating point numbers
are implicitly doubles (64 bits)
Narrowing primatives
truncates the high order bits
Compound assignments (eg +=)
perform an automatic cast
A reference variable
holds bits that are used to refer to an object
Reference variables
can refer to subclasses of the declared type but not to the superclasses
When creating an object (new keyword), 3 things happen
- ) Make a reference variable
- ) Create a new Object
- ) Assign object to the reference variable
Array objects that are uninitialized
when instantiated, objects within the array are not initialized automatically, but all reference get the default value of null.
Array primatives
when instantiated receive their default values
Instance variables
always initialized with their default value
local/automatic/method variables
never given a default value, if you attempt to use one before initializing you will get a compiler error
Methods
can take primitive and/or object references as arguments
Method arguments
are always copies
Method arguments
are never actual objects (they can be references to objects)
A primitive argument
is unattached copy of the original primative
A reference argument
is another copy of a reference to the original object
Shadowing
occurs when two variables with different scopes share the same name
Arrays
can hold primitives or objects, but the array itself is always an Object
When you declare an array
the brackets can be left or right of the name
Array size
it is never legal to declare the size of an array in the declaration