1/12
Looks like no tags are added yet.
Class
Is the name for a type whose values are objects. Objects are entities that store data and take actions. The actions that an object can take are called methods.
String class
Strings in Java are immutable.
Some string manipulation in Java
str.charAt(3) Return character in 3rd position str.substring(2,4) Return substring from 2nd up to but not including 4th
str.length() Return the length of the string
str.indexOf('x') Find the first occurrence of x
str.split('\s') Split the string on whitespace into a list/array of strings
str.split(',') Split the string at ',' into a list/array of strings
str + str or str.concat(str) Concatenate two strings together str.trim()
Escape sequences
\'“ Double quote
\’ Single quote
\\ backslash
\n newline
\r carriage
\t tab
Javadoc
A program in Java that automatically extracts documentation from block comments in the classes you define as long as their opening has an extra asterisk /**
Class and private members of all objects of a class
Within the definition of a class, private members of any object of the class can be accessed, not just private members of the calling object.
Mutator methods can return a Boolean value
Have a mutator method return a Boolean value, and have the calling program handle the cases where the changes do not make sense. Used for validation checks and state change tracking.
Example of a boolean mutator method
public boolean setBalance(double newBalance){
if(newBalance>= 0){
this.balance = newBalance;
return true;
}
return false;
Preconditions and postconditions
A precondition of a method states what is assumed to be true when the method is called. The postcondition of a method states what will be true after the method is executed as long as the precondition holds.
Driver program
A program whose only purpose is to test a method. One method often invokes other methods so one way to do this is to first test all the methods invoked by that method and then test the method itself. This is called bottom up testing.
Stub
A simplified version of a method.
The fundamental rule for testing methods
Every method should be tested in a program in which every other method in the testing program has already been fully tested and debugged.