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 (74 cards)

1
Q

Local Variables

A

Live on the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Objects and instance Variables

A

Live on the Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Integer literals

A

can be decimal, octal, or hexadecimal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Float literals end in

A

F or f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Double literals end in

A

D or d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Boolean literals

A

are true and false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

scope

A

refers to the lifetime of a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

4 basic scopes

A
  1. Static variables live basically as long as their class lives
  2. Instance variables live as long as their object lives
  3. Local variables live as long as their method
  4. Block variables live until the block completes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Literal integers

A

are implicitly ints

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

integer expressions

A

always end in a int-sized result, never smaller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

floating point numbers

A

are implicitly doubles (64 bits)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Narrowing primatives

A

truncates the high order bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Compound assignments (eg +=)

A

perform an automatic cast

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A reference variable

A

holds bits that are used to refer to an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Reference variables

A

can refer to subclasses of the declared type but not to the superclasses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When creating an object (new keyword), 3 things happen

A
  1. ) Make a reference variable
  2. ) Create a new Object
  3. ) Assign object to the reference variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Array objects that are uninitialized

A

when instantiated, objects within the array are not initialized automatically, but all reference get the default value of null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Array primatives

A

when instantiated receive their default values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Instance variables

A

always initialized with their default value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

local/automatic/method variables

A

never given a default value, if you attempt to use one before initializing you will get a compiler error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Methods

A

can take primitive and/or object references as arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Method arguments

A

are always copies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Method arguments

A

are never actual objects (they can be references to objects)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A primitive argument

A

is unattached copy of the original primative

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
A reference argument
is another copy of a reference to the original object
26
Shadowing
occurs when two variables with different scopes share the same name
27
Arrays
can hold primitives or objects, but the array itself is always an Object
28
When you declare an array
the brackets can be left or right of the name
29
Array size
it is never legal to declare the size of an array in the declaration
30
You must include the size of an array when you construct it
(using new) unless you are creating an anonymous array.
31
Elements in an array of objects
are not automatically created, although primitive array elements are given their default values
32
You will get a NullPointerException
if you try to use an array element in an object array if that element does not refer to a real object
33
arrays
are indexed beginning with 0
34
An ArrayIndexOutOfBoundsException
occurs if you use a bad index value
35
Arrays have a length variable
whose value is the number of array elements
36
Last index in an array
is always one less than the length of the array
37
Multidimensional Arrays
are just arrays of arrays
38
The dimensions in a multidimensional array
can have different lengths
39
Array primitives
can accept any value that can be promoted implicitly to the array's declared data type.
40
An array of objects
can hold any object that passes an IS-A test for the declared type of array.
41
If you assign an array to a previously assigned array reference
the array you are assigning must have the same dimension as the reference your assigning it to
42
You can assign an array of one type
to a previously declared array of one of its supertypes.
43
Static initialization blocks
run once when the class is first loaded
44
Instance initialization blocks
run every time a new instance is created. They run after ALL super-constructors, and before the constructor's code has run
45
If multiple init blocks exist in a class
they follow the previous 2 rules on initialization AND they run in the order in which they appear in the source file.
46
The wrapper class
correlate to the primitive types
47
Wrappers have 2 main fuctions
1. to wrap primitives so they can be handled like objects. | 2. to provide utility methods for primitives (usually conversions)
48
The 3 most important method families are
1. xxxValue(); takes no args, returns primitive 2. parseXXX();takes a string, returns primative, throws NFE 3. valueOf; takes a String, returns a wrapped object, throws NFE
49
Wrapper constructors
can take a string or a Primitive, except for Character, which can take a char.
50
Radix refers to
bases other than 10; octal is radix = 8, hex = 16
51
Boxing
as of Java 5, allows you to convert primitives to wrappers or to convert wrappers to primitives automatically.
52
Using == with wrappers created through boxing
those with the same small values, typically lower than 127 will be ==; larger values will NOT be ==
53
Primitive widening
uses the "smallest" method argument possible
54
used individually, boxing and var-args
are compatible with overloading
55
You CANNOT widen from one wrapper type to another
IS-A fails
56
You CANNOT widen and then box
An int can't become a long
57
You can box then widen
An int can become an Object, via an Integer
58
You can combine var-args with either
widening or boxing
59
Garbage collection
Java provides automatic memory management
60
Purpose of GC
delete objects which can't be reached
61
Only the JVM
decides when to run GC, you can only suggest it
62
Object must be considered "eligible"
before they can be garbage collected
63
An object is eligible for GC
when no live thread can reach it.
64
To reach a thread
you must have a live, reachable reference to that object.
65
Islands of objects
can be GCed, even though they refer to each other
66
Class Object
has a finalize() method
67
The finalize() method
is guaranteed to run once and only once before the GC deletes an object
68
GC makes no guarantees
finalize() may never run
69
You can uneligibilize an object for th GC
within finalize()
70
Primitive Data Types
Be careful bears shouldn't ingest large furry dogs. Boolean, char, byte, short, int, long, float double 8,16,32,64,32,64
71
Roses are red,, violets are blue
extend only one, but implement two
72
Instance variables are assigned a default value
even if you don't explicitly assign one. The default values are 0/0.0/false for primitives, and null for references.
73
Roses are red, violets are blue
Your parents come first, way before you... The superclass parts of an object must be fully formed before the new subclass object can exist.
74
A final
``` variable means you can't change it's value, method means you can't override the method, class means you can't extend the class ```