ap comp sci unit 2 test Flashcards
state/attributes
instance variables in java
behavior
methods in Java
Class
Blueprint for objects
Overloading
Having many constructors with same name but different constructor signatures (parameters)
non static methids
objectName.method();
NullPointerException
Creating a non static method on a null object = error
name.concat(“value”)
Returns a new String with “value” appended to the end of name
name.replace(“a”, “p”)
Returns a new STring will all instances of “a” replaced with “p”
Strings are immutable
They cannot be changed but we can reassign it
"
Allows for quotation marks
““\monkey/””
\
Includes a backlash
At the end
Ex: Includes a backlash\
\n
“This creates \na line break
This creates
a line break
\t
“This adds a \ttab space”
“This adds a tab st[ace
name.length
Returns the number of characters in a String object ( returns an int)
name.substring(4)
Returns the substring beginning at index 4 and ending at the last index
name.subString(2,6)
Returns the substring at index 2 and ends at 5
name.equals(“Hello”)
Returns trye if name is equal to Hello
Returns false otherwise
name.CompareTo(“Hello”)
Returns a value < 0 if name is less than Hello
Returns 0 if name is equal to Hello
Returns a value > - if name is greater than Hello
numerical value
Starts from A is 65, Z is 90, ends at 126. 6 spaces between “Z’ and “a’
name.IndexOf(“d”)
Returns the index of the first occurence of d (returns an int)
Returns -1 if not found
Primitive
Most basic type in java, primitive variables store primitive values, don’t have associated methods
Reference
Instantiable classes made by programmers that often use primitive types, reference variables store the address of the value, has associated methods
Ex of primtive types
boolean, char, int double (anythign lowercase)
ex of reference types
Interger, Double (anythign with uppercase)