1/42
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Object
An instance of a class that contains variables (data) and behaviors (methods).
Object-Oriented Programming (OOP)
A programming style where programs are organized around objects that contain data and behaviors.
Variable
A piece of data attached to an object that helps define the object's state or characteristics.
Behavior (Method)
An action associated with an object; methods are used to make an object do something.
Example of variables in an object
A Fraction object could have a numerator and denominator as variables.
Abstraction
Hiding the details of how something works because the user does not need to know those details to use it.
Example of abstraction
A driver does not need to know exactly how a car's engine works in order to drive the car.
Math Class
A Java class containing static methods that perform common mathematical operations.
Static
A keyword indicating that a method belongs to the class itself and can be called without creating an object of that class.
Math.abs()
Returns the absolute value of a number.
Math.abs(int num)
Returns the absolute value of an integer.
Math.abs(double num)
Returns the absolute value of a double.
Math.pow()
Raises a number to a specified power.
Math.pow(2, 3)
Returns 8.0 because 23=8.
Math.random()
Returns a random double greater than or equal to 0.0 and less than 1.0.
Math.sqrt()
Returns the square root of a number.
Math.sqrt(25)
Returns 5.0 because 25=5.
Math.pow(double num, double power)
Returns num raised to the given power.
Math class method syntax
Math.methodName(parameters)
Absolute value
The distance of a number from zero; it is always nonnegative.
pow
Short for power; used to raise a number to an exponent.
random
Used to generate a random decimal number from 0.0 up to, but not including, 1.0.
sqrt
Short for square root; returns the square root of a number.
String object
An object that stores a sequence of characters.
String.indexOf(String str)
Returns the first position (index) where the specified string occurs; returns −1 if it is not found.
word.indexOf("E") for word = "COMPUTER"
Returns 6.
word.indexOf("P") for word = "COMPUTER"
Returns 3.
word.indexOf("U") for word = "COMPUTER"
Returns 4.
word.indexOf("Y") when "Y" is not present in word
Returns −1.
Index of the first character in a String
0
Indexing of String characters
Starts at 0 and increases by 1 for each character.
String.length()
Returns the length (number of characters) in the String.
String.substring(int from, int to)
Returns a substring starting at the from index and ending before the to index.
String.substring(int from)
Returns a substring starting at the from index and continuing to the end of the String.
boolean equals(String str)
Checks whether two Strings are equal.
int compareTo(String str)
Compares two Strings lexicographically.
Syntax for creating a String object
String variableName = new String("text");
Example of creating a String object
String joMama = new String("is so fat");
Syntax for calling a String method
object.methodName(parameters)
Example of calling substring on an object
String big = joMama.substring(6);
Printing output in Java
System.out.println(...);
substring(1, 3) for "COMPUTER"
"OM"
substring(6) for "COMPUTER"
"ER"