Comp sci: Classes and String class

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

13 Terms

1
New cards

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.

2
New cards

String class

Strings in Java are immutable.

3
New cards

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()

4
New cards

Escape sequences

\'“ Double quote

\’ Single quote

\\ backslash

\n newline

\r carriage

\t tab

5
New cards

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 /**

6
New cards

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.

7
New cards

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.

8
New cards

Example of a boolean mutator method

public boolean setBalance(double newBalance){

if(newBalance>= 0){

this.balance = newBalance;

return true;

}

return false;

9
New cards

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.

10
New cards

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.

11
New cards

Stub

A simplified version of a method.

12
New cards

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.

13
New cards