Unit 2 Us objects Strings and class types Escape Sequences and String Concatenation String Methods Classes and Objects Using Constructors Using Methods Math Functions
Primitive data types
Hold only one piece of data at a time
Boolean, int, double
stored as an actual value
Reference data type (class)
hold more than one piece of data type
Int, double, String, Scanner
have built-in tools - tools which you can use to work with an manipulate data
memory address that points to the place where info is stored (don’t site the actual value)
Strings are immutable
means you cannot change Strings without moving to a new memory location. Java will do this automatically.
null
Placeholder that means no reference
Order of operations
Rules that tell us the sequence in which the code is run
String memory
Each character of a String is stored individually
Each character is given an address that starts at 0
index
The address number of each character
.length() method
Tells us the length of the String
.equals() method
Tests if 2 strings are equal - If the same contents of both Strings heave the same characters in the same places
Will return the true or false (Boolean)
.substring(start, stop) method
Creates a subset of characters from the starting index up to but not including the stopping index
.substring (start)
Returns the subset of characters from the start to the end of the String
.toUpperCase() method
Returns the String changed to the uppercase letters
.toLowerCase()
Returns the string changed to the lowercase letters
.compareTo() method
Lets us compare 2 Strings alphabetically
.indexOf() method
Method that allows you to search through a String to find a particular character
Returns the index position as an int
Object
Specific instance of a class with defined attributes
Instance variables
Define true attributed for objects
Attributes
Store and represent data associated with objects whose behaviors are defined by the methods
Instance
Specific object that is created from the class
Constructing
The process of creating a new object
Constructor
Special method that creates a new object
Every class defines its own constructor
Doesn’t have a return type in Java
Parameter
Information we put in () and determines how we construct our new object
API
Application Programming Interface
It’s the way programmers share information or code with each other
State
Attributes of the object and their values (at a given time) that define what our object (ex: rectangle) looks like
setRadius() method
Characteristics of a circle: round, radius, diameter, circumference, pi
True for the Circe class
Void methods
Performs an action, but doesn’t return any information
Generally changes the state of an object
Non-void methods
Changes the state of an object and returns a value to us
Mostly used for pulling information for an object
Method overloading
By quantity (number of parameters)
By data type
By different order
Method Signature
Made up of methods name, number of parameters, and the data type of those parameters
Java determines which method to call based on parameter number and number and data types - the method signature
Signatures can only have the same name - those are overloaded methods - but they have to be different parameters
Wrapper class
Wraps a primitive data type into objects/class so we can apply methods to them
CompareTo() method
Compare 1 integer to another integer
Compares 1 double to another double
Autoboxing
Automatic conversion between primitive data types and their corresponding object wrapper classes
Unboxing
When java is given an Integer and expects an int, it automatically converts, or unboxes, the integer into a primitive int.
Math Class
Part of Java.lang package
We need to make sure it is imported to our program
Math.abs() method
Performs an absolute value calculation
int the as an input→ int as an output
double used → double returned
.pow(x,y) method
Performs exponent math
Accepts 2 parameters: the base and the exponent
Performs a calculation: base (x) raised to the exponent power (y)
.sqrt() method
Calculates the square root of the double we send it
Returns a double
math.random()
Returns a double from 0.0 to but not including 1.0
non-static methods
Specify the object, then the method to perform on the object
Static methods
Performed just by referencing the Class name