unit 2 apcsa

studied byStudied by 0 people
0.0(0)
get a hint
hint

int length() method

1 / 61

Tags & Description

Studying Progress

New cards
62
Still learning
0
Almost done
0
Mastered
0
62 Terms
0
New cards

int length() method

returns the number of characters in the string, including spaces and special characters like punctuation.

New cards
1
New cards

String substring(int from, int to) method

returns a new string with the characters in the current string starting with the character at the from index and ending at the character before the to index (if the to index is specified, and if not specified it will contain the rest of the string).

New cards
2
New cards

int indexOf(String str) method

searches for str in the current string and returns the index of the first occurrence of str; returns -1 if not found

New cards
3
New cards

class

define a new data type of attributes and behaviors or a blueprint for objects

New cards
4
New cards

object or instance

variable from class or instance of a class, can create as many as you need

New cards
5
New cards

attributes or instance variable

object's properties, what it know about itself, written as instance variable

New cards
6
New cards

behavior or method

what an object does, written as methods

New cards
7
New cards

dot operator (.)

used to run methods, asking object to do something ex: object.method();

New cards
8
New cards

arguments

New cards
9
New cards

constructors

used to initialize the attributes in a newly created object, same name as class, doesnt take any parameter

New cards
10
New cards

overloading

when there is more than one constructor, when there are multiple methods with the same name but a different method signature, where it requires a different number or type of parameters

New cards
11
New cards

constructor signature

constructor name followed by the parameter which is a list of the types of the parameters and the variable names used to refer to them in the constructor

New cards
12
New cards

no argument constructor

a constructor that doesn't take any passed in values (arguments)

New cards
13
New cards

parameter list

the header of a constructor, is a list of the type of the value being passed and a variable name. These variables are called the formal parameters. ex: (int width, int height)

New cards
14
New cards

call by value

pass a value to a constructor or method it passes a copy of the value,

New cards
15
New cards

nonstatic method

one that must be called on an object of a class, works with object's attributes

New cards
16
New cards

static method

one that doesn't need to be called on an object of a class, can call by using ClassName.methodName() without creating an object, class name + dot operator + method name

New cards
17
New cards

procedural abstraction

allows a programmer to use a method and not worry about the details of how it exactly works

New cards
18
New cards

method signature or method header

method name followed by a parameter list

New cards
19
New cards

how do you call method from main or outside the class?

create an object and call object.method();

New cards
20
New cards

how do you call method from inside the class?

method();

New cards
21
New cards

NullPointerException

forgetting to create a new object followed by the class name and attributes, Trying to call a method like indexOf on a string reference that is null. ex: String dog = null; or String dog;

New cards
22
New cards

formal parameter

the variables in a method's definition that holds the arguments

New cards
23
New cards

arguments or actual parameters

the value of data passed to an object's method, plugs in actual values in the formal parameter

New cards
24
New cards

void

not returning anything

New cards
25
New cards

toString()

converts an object to a string

New cards
26
New cards

string

objects of the string class that holds sequences of characters, can declare a variable to be type string, is a class type

New cards
27
New cards

string literal

String word = "hello";

New cards
28
New cards

backslash escape sequence

put in a backslash in front of the quote to signal that we want just the character. ex: "Here is a backslash quote " " + " and a backslashed backslash (\) " + "Backslash n \n prints out a new line."

New cards
29
New cards

\n

creates a new line

New cards
30
New cards

\ "

"

New cards
31
New cards

null

object reference doesn't referred to any object yet

New cards
32
New cards

The first character in a string is at index - and the last characters is at -

0 and length -1

New cards
33
New cards

remember

substring(from,to) does not include the character at the to index! To return a single character at index i, use str.substring(index, index + 1)

New cards
34
New cards

compareTo

compares two strings character by character. If they are equal, it returns 0. If the first string is alphabetically ordered before the second string (which is the argument of compareTo), it returns a negative number. And if the first string is alphabetically ordered after the second string, it returns a positive number. (The actual number that it returns does not matter, but it is the distance in the first letter that is different, e.g. A is 7 letters away from H.)

New cards
35
New cards

Application Programming Interface (API)

a library of prewritten classes that simplify complex programming tasks for us

New cards
36
New cards

Strings are ---

immutable, meaning that they can't change. Anything that you do to modify a string (like creating a substring or appending strings) returns a new string

New cards
37
New cards

IndexOutOfBoundsException

trying to access part of a string that is not between index 0 and length -1

New cards
38
New cards

string == string

tests to see if they refer to the same object not to see if they are the same. you would use equals or compareTo to see if strings are equal

New cards
39
New cards

String(String str)

Constructs a new String object that represents the same sequence of characters as str.

New cards
40
New cards

int compareTo(String other)

returns a value < 0 if this is less than other; returns zero if this is equal to other; returns a value > 0 if this is greater than other.

New cards
41
New cards

boolean equals(String other)

returns true if this (the calling object) is equal to other; returns false otherwise.

New cards
42
New cards

underflow

returning the maximum integer value if you try to subtract one from the minimum value

New cards
43
New cards

overflow

returns the minimum integer value if you try to add one to the maximum

New cards
44
New cards

autoboxing

the automatic conversion that the Java compiler makes between primitive types and their corresponding object wrapper classes

New cards
45
New cards

unboxing

the automatic conversion that the Java compiler makes from the wrapper class to the primitive type

New cards
46
New cards

Double(double value)

constructs a new Double object that represents the specified double value.

New cards
47
New cards

double doubleValue()

returns the value of this Double as a double

New cards
48
New cards

The Java compiler applies unboxing when a wrapper class object is:

  • passed as a parameter to a method that expects a value of the corresponding primitive type.

  • assigned to a variable of the corresponding primitive type.

New cards
49
New cards

The Java compiler applies autoboxing when a primitive value is:

  • Passed as a parameter to a method that expects an object of the corresponding wrapper class.

  • Assigned to a variable of the corresponding wrapper class

New cards
50
New cards

int intValue()

returns the value of this Integer as an int

New cards
51
New cards

integer(value)

constructs a new Integer object that represents the specified int value

New cards
52
New cards

wrapper classes

integer class and double class that create objects from primitive types

New cards
53
New cards

Math.random()

returns a random number between 0.0-0.99

New cards
54
New cards

moves the random number into a range starting from a minimum number

(int)(Math.random()*range) + min

New cards
55
New cards

the range

(max number - min number + 1)

New cards
56
New cards

Math.pow(number,exponent)

ex: Math.pow(10,2) which means 10 to the power of 2. If you start listing all the permutations possible, you can tell that there are 102 or 100 possible permutations for a 2 dial lock from 0-9.

New cards
57
New cards

int abs(int)

returns the absolute value of an int value (which means no negatives)

New cards
58
New cards

double abs(double)

returns the absolute value of a double value

New cards
59
New cards

double pow(double, double)

Returns the value of the first parameter raised to the power of the second parameter.

New cards
60
New cards

double sqrt(double)

Returns the positive square root of a double value.

New cards
61
New cards

double random()

Returns a double value greater than or equal to 0.0 and less than 1.0 (not including 1.0)

New cards

Explore top notes

note Note
studied byStudied by 5 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 30 people
Updated ... ago
4.5 Stars(4)
note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(3)
note Note
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 80 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 20 people
Updated ... ago
4.0 Stars(1)

Explore top flashcards

flashcards Flashcard40 terms
studied byStudied by 132 people
Updated ... ago
4.3 Stars(7)
flashcards Flashcard30 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(4)
flashcards Flashcard94 terms
studied byStudied by 160 people
Updated ... ago
5.0 Stars(2)