head first java chapter 5

Post on 17-Feb-2017

297 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Head First Java Chapter 5Tom Henricksen

Game program● Design

● Develop

○ Variables and Methods

○ Prepcode and Tests

○ Implement and Debug

XP Programming● Small frequent releases

● Iteration cycles

● Code to spec

● Write test first

● Refactor

Let’s pair

SimpleDotComTestDrive

SimpleDotCom

Review● Increment x++

● Decrement x--

● Integer.parseInt()

● break;

Let’s pair again

Regular for loop● Initialize

● boolean test

● Iteration

● for(int i = 0;i < 100;i++) {}

Increment/decrement operators● Post increment/decrement

○ x++; x = x + 1;

● Pre increment/decrement

○ Int x = ++z;

Enhanced for loopfor (String name : nameArray) {}

● Iteration variable

● Actual collection

Casting PrimitivesLong y = 42;

Int x = y; // won’t compile

Int x = (int) y; // will compile

Casting primitives (cont.)long y = 40002;

short x = (short) y; // x now -25534;

float f = 3.14f;

int x = (int) f; // x is now 3!

Static (Bonus)● Static

● Belongs to the class

● Not an instance

● Shared

Be the compiler

● Exercise

top related