Most basic data type in Java. These do no have associated methods.
2
New cards
reference type
Instantiable classes made by programmers that often use primitive types. Reference variables store the address of the value. These do have associated methods.
3
New cards
State of an object
Data about that object.
4
New cards
Behavior of an object
Actions that can be performed on the object.
5
New cards
Class
A blueprint that defines an object's variables and methods.
6
New cards
Class skeleton
public class ClassName { }
7
New cards
Object
An instance of a class that contains both state and behavior.
8
New cards
Instance Variables
Storage for data in an instance of a class.
9
New cards
Constructor, signature
Allows us to create a new instance of a class, usually initializing instance variables.
10
New cards
Using constructor
Rectangle rect1 = new Rectangle(14,16);
11
New cards
Formal vs Actual Parameters
Formal parameters are found in the constructor of a class and used to link actual parameters to an object.
12
New cards
Overloading constructors
Addition of constructors to take different number, or type of parameters, allowing the user to set the values of different combinations of the instance variables when the object is created.
13
New cards
Methods
Procedures that allow us to control and define the behavior of an object.
14
New cards
Return type
The type of data a method gives back.
15
New cards
Instance variables in a class
Can be used across different methods.
16
New cards
Call a method
objectName.method()
17
New cards
Procedural abstraction
Making a procedure available for general use so that programmers do not have to worry about the details within the procedure's algorithm.
18
New cards
Instance method
Piece of code called on a specific instance (an object) of the class. Need an object to call.
19
New cards
Parameters
The formal names given to the data that gets passed into a method.
20
New cards
Parameter list
A list of the types and variable names for the arguments being passed to a method or constructor.
21
New cards
Overloading methods
Overloading methods enable a method to accept different parameters.
22
New cards
Void method
A method that does not return a value.
23
New cards
name.concat("value")
Returns a new String with "value" appended to the end of name.
24
New cards
name.replace("a", "p")
Returns a new String with all instances of "a" in name replaced with "p".
25
New cards
name.toUpperCase();
Returns name as Upper Case Letters.
26
New cards
\"
Double-quote (")
27
New cards
\\
Backslash (\)
28
New cards
\n
new line
29
New cards
\t
tab
30
New cards
name.length()
Returns the number of characters in a String object.
31
New cards
name.substring(2,6)
Returns the substring beginning at index 2 and ending at index 5.
32
New cards
name.indexOf(d)
Returns the index of the first occurrence of d; returns -1 if not found.
33
New cards
name.equals("karel")
Returns true if name is equal to Karel; returns false otherwise.
34
New cards
name.compareTo("karel")
Returns a value < 0 if name is less than Karel. Returns zero if name is equal to Karel. Returns a value > 0 if name is greater than Karel.
35
New cards
Printing an object without toString method
Will return the object's hashcode, not the values associated with it.
36
New cards
Library
A collection of packages and classes that are available for use in other programs.
37
New cards
Package
Generally made up of alike classes that address specific programming problems.
38
New cards
toString
Returns the value of a String object.
39
New cards
Wrapper class
A class which contains or "wraps" primitive data types as an object. Data types must match the Wrapper Class type. Characterize by starting with an UpperCase letter
40
New cards
Instantiating an Object of a Wrapper Class
Integer y = new Integer(17); Double z = new Double(3.14);
41
New cards
How do Wrapper Classes Help?
Wrapper classes contain special values and methods that are useful for converting between types.
42
New cards
Integer.MIN_VALUE
Returns the minimum possible int or Integer value
43
New cards
Integer.MAX_VALUE
Returns the maximum possible int or Integer value
44
New cards
objectName.intValue()
Allows us to extract the primitive value from the object Integer value.
45
New cards
objectName.doubleValue()
Allows us to extract the primitive value from the object Double value.
46
New cards
Autoboxing
Java automatically converts a primitive value into an object of the corresponding wrapper class. Integer myInt = 53;
47
New cards
Unboxing
Java automatically converts an object of a wrapper type to its corresponding primitive value. int myInt2 = myInt;
48
New cards
Autoboxing and Unboxing
Allows us to use primitive types and Wrapper class objects interchangeably without having to perform casting explicitly.
49
New cards
Math.abs(x)
Returns the absolute value of x.
50
New cards
Math.pow(base, exponent)
Returns the value of base raised to the power of exponent.
51
New cards
Math.sqrt(x)
Returns the positive square root of x.
52
New cards
Math.random()
Returns a double value greater than or equal to 0.0 and less than 1.0
53
New cards
How would you generate a random number between 0 and 9?
(int)(Math.random() * 10);
54
New cards
Random number from 0 - integer
(int)(Math.random() * (integer + 1));
55
New cards
The general formula for generating any range from (start to start+range).
(int)(Math.random() * (range + 1) + start);
56
New cards
Static method
Static methods are defined in an object but do not require instance data. Therefore, they can be called directly with the class name, such as Math.random().