Head First Java Chapter 05 Notes

Head First Java Chapter 05

This is the fifth Chapter learning of Head First Java by Kathy Sierra and Bert Bates,
This markdown file is my notes for the fifth chapter, not sure if any copyright issues are there.

Developing a Class.

  • Figure out what the class is supposed to do.
  • List the instance variables and methods.
  • Write prepcode for the methods.
  • Write test code for the methods.
  • Implement the class.
  • Test the methods.
  • Debug and reimplement as needed

for Loops.

Regular (non-enhanced) for loops.

for(int i =0; i < 100; i++)
Part One: initialization.
int i =0;
Part two: boolean test.
i < 100;
Part three: iteration expression
i++;

The enhanced for loop

for(String name : nameArray){}
Part One: iteration variable declaration.
String name
Part two: The Actual collection
nameArray

Bullet Points

  • Your java program should start with a high level design.
  • Typically you’ll write three things when you create a new class:
  • prepcode
  • testcode
  • real(java) code.
  • Prepcode should descibe what to do, not how to do it. Implementation comes later.
  • Use the prepcode to help design the test code.
  • Write test code before you implement the methods.
  • Choose for loops over while loops when you know how many times you want to repeat the loop code.
  • Use the pre/post increment operator to add 1 to a variable (x++)
  • Use the pre/post decrement operator to subtract 1 from a variable (x–).
  • Use Integer.parseInt() to get the int value of a string.
  • Integer.parseInt() works only if the String represents a digit (“0″,”1”, etc).
  • Use break to leave a loop early.
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s