Head First Java Chapter 3
-
Upload
tom-henricksen -
Category
Software
-
view
171 -
download
0
Transcript of Head First Java Chapter 3
Head First Java Chapter 3Tom Henricksen
Variables● Type
● Name
● Primitive types
○ byte, short, int, long, float, double
○ boolean
○ char
Variables● Spilling over (byte -> int)
● Assignment
○ literal x = 3;
○ Variable x = y;
○ Expression x = t + 56;
Variable names● Start with a letter, _, or $
● Reserved words
○ boolean
○ else
○ try
Reference Variables● Holds reference to the object
○ Dog d = new Dog();
○ d.bark();
● Declare Dog myDog;
● Create new Dog();
● Link myDog = new Dog();
Garbage collection● Eligible for collection
○ Unused a = c;
○ Set to null a = null;
Arrays● Declare int[] nums;
● Create nums = new int[8];
● Always an object!
● Array of dogs
○ Dog[] dogs = new Dog[7];
Create your own dog
Variable review● Two types
● Need a name and type
● Variable is the value for...
● Represents the object on the heap
Variable review● Reference is like a remote control
● Use dot operator
● Unused or null
● Arrays are always
Be the compiler
● Exercise A
● Exercise B