head first java chapter 3

Post on 20-Jan-2017

172 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

top related