Head first Java -Chapter 5

Niluxshikaganeshan
3 min readJul 17, 2022

--

This article will be the continuation of the Headfirst Java Book. Read the previous one to get a clear idea.

Developing Class

  1. Figure out what the class is supposed to do.
  2. List the instance variables and methods.
  3. Write prep code for the methods.
  4. Write test code for the methods.
  5. Test the methods.
  6. Implement the class.
  7. Debug and re-implement as needed.

perp code -A form of pseudocode, to help you focus on the logic without stressing about syntax.

test code -A class or method that will test the real code and validate that it’s doing the right thing.

real code -The actual implementation of the class. This is where we write real Java code.

For Loops

Initialization -Declare and set up any variable you want to utilize in the body of the loop in this section. This variable will most frequently be used as a counter. Actually, you may initialize many variables here, but we’ll cover that in a later chapter of the book.

Boolean Test -The conditional test is used here. Anything included there must resolve to a Boolean value( you know, true or false). A method that returns a Boolean can be called, or you can have a test like (i<100).

Iteration expression -Put one or more outcomes you want to occur on each looping journey in this section. Rember that this occurs at the conclusion of each loop.

Pre-increment and Post-increment

Pre-increment: Before a variable is utilized in an expression, its value is increased using a pre-increased in the Pre-increment before being utilized inside the expression

a = ++x;

Post-increment: Afer an expression using post increment has been fully executed, the value of the post-increased in the Post-increment.

a = x++;

Extreme Programming(XP)

A recent addition to the field of software development methodologies is called Extreme Programming(XP). Although many people pick and choose and accept only a subset of XP’s guidelines, XP is founded on a collection of tried-and-true methods that are all intended to function together. These practices consist of the following,

  1. Releases should be brief yet frequent.
  2. Iterative development cycles.
  3. No matter how tempted you are to provide features “for the future” refrain from adding anything that isn’t specified in the spec.
  4. Create the test code first.
  5. Work normal hours, no deadly scheduling.
  6. Anytime you see the chance to do so, refactor(improve the code)
  7. Release anything until all testing has been completed.
  8. Make plans that are based on small releases and realistic. Simple is best.
  9. Move individuals around while programming in pairs to ensure that everyone is familiar with the majority of the code.

Points

  • A high-level design should be the first step of your Java application.
  • When you create a new class, you usually write three things: Java prep, testing, and actual code.
  • Prep code should specify what to do rather than how to accomplish it. Implementation happens afterward.
  • Design the test code with the aid of the prep code.
  • Before putting the approaches into practice, write the code. Greetings from Ghost Town.
  • When you know how many times you want to repeat the loop code, choose for loops over while loops.
  • To add 1 to a variable, use the pre/post increment operator(x++;).
  • In order to decrease 1 from a variable, use the pre/post decrement (x — ;).
  • To determine the int value of a String use Integer.parseInt().
  • The function Integer.parseInt() only functions when the Strong is a digit(“0”, “1”, “2”, etc.)
  • Break the loop early by using this(i.e. even if the Boolean test condition is still true).

Reference

https://www.rcsdk12.org/cms/lib/NY01001156/Centricity/Domain/4951/Head_First_Java_Second_Edition.pdf

--

--