Week 3 Flashcards
Objects are defined by
classes rather than a primitive type. (variables can be used to store primitive types).
objects are created with the…
new operator and a variable that can then be assigned to reference the object.
an object variable is a…
reference variable. It doesn’t hold the object but rather the memory location where the object is.
creating an object is called
instantiation
an object is a(an) _________ of a particular class
instance
objects unlike primitives can have what?
methods.
- provide functionality – ex. The nextInt() method reads user input
- invoked using the dot operator
- a method may return a value int count = title.length()
- a method may accept parameters as input myScan.userDelimiter(“, “)
- may have both a return value and parameters
Assignment takes a …
copy of a value and stores it in a variable
two or more references are called what?
aliases
What happens when when an object no longer has any references to it?
it can’t be accessed and is called garbage.
immutable
String objects cannot be changed in memory once created.
the replace() method
returns a whole new String object
String title = title.replace(“s”, “S”);
String Indexes
- Characters are indexed starting at 0.
- you can get a particular character from a String using the charAt()
- Ex. String my String = “Hello”;
- Ex. Char myChar = myString.charAt(0); this would get the H
JCL
Java Class Library (JCL) is a set of classes that are part of the JDK and documented in the Java API. Classes are organized into packages (java.lang, java.applet, java.util, etc.)
the methods of the Math class are what?
static methods. They can be invoked using the class name rather than an object reference. (ex. Math.sqrt(delta))
DecimalFormat class
class can be used to format both floating point and integer values in various ways. The constructor takes a String that represents the pattern for formatting. The format method is called on the DecimalFormat object to return a String representing the value.