Extra-Strength Methods — Chapter 5
Developing a class includes few steps
- Figure out what the class is supposed to do.
- List the instance variables and methods.
- Write prep code for the methods.
- Write test code for the methods.
- Implement the class (real code).
- Test the methods
- Debug and reimplement as needed
Extreme Programming (XP)
- It is a newcomer to the software development methodology.
- Emerged in the late 90’s
- Adopted by many companies.
- It helps with quick adaptation.
- It is based on a set of proven practices that are all designed to work together.
- Some adopt only a portion of XP’s rules
Rules of XP
- Small but frequent releases
- Develop in iteration cycles
- No additions than the spec
- Write the test code first
- No killer schedules
- Work regular hours
- Refactor (improve the code) whenever and wherever you notice the opportunity.
- Don’t release anything until it passes all the tests.
- Set realistic schedules, based around small releases.
- Keep it simple.
- Program in pairs
- Move people around so that everybody knows pretty much everything.
Post-increments vs Pre-increments in Java
++a increments and then uses the variable.
a++ uses and then increments the variable.
a = 1;
System.out.println(a++); //You will see 1
//Now a is 2
System.out.println(++a); //You will see 3
int x = 5, y = 5;
System.out.println(++x); // outputs 6
System.out.println(x); // outputs 6
System.out.println(y++); // outputs 5
System.out.println(y); // outputs 6
This only matters when the ++x is part of some larger expression rather than just in a single statement.
int x = 0 ;
int z = ++x; //produces: x is 1, z is 1
But putting the ++ after the x give you a different result:
int x = 0;
int z = x++; //produces: x is 1, but z is 0
If the value of y was bigger then the maximum value of x, then what’s left will be a weird (but calculable) number that is assigned to x.
long y == 40002; //40002 exceeds the 16-bit limit of a short
short x =(short) y; //x now equals -25534! (short’s range is -32,768 to 32,767 (inclusive) so the value goes in a round when limit is exceeded)
- Integer.parselntO works only on Strings that represent the ASCII values for digits (0,1,2,3,4,5,6,7,8,9). Any other input will throw an exception.
- If you want a random number between 0 and 4 use,
int randomNum = (int) (Math.random() * 5);
- Multiple initializations and iteration expressions can be done on a for loop.
Thanks for reading. Until next time! 👋🏽