ap comp sci unit 2 test Flashcards

1
Q

state/attributes

A

instance variables in java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

behavior

A

methods in Java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Class

A

Blueprint for objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Overloading

A

Having many constructors with same name but different constructor signatures (parameters)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

non static methids

A

objectName.method();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

NullPointerException

A

Creating a non static method on a null object = error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

name.concat(“value”)

A

Returns a new String with “value” appended to the end of name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

name.replace(“a”, “p”)

A

Returns a new STring will all instances of “a” replaced with “p”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Strings are immutable

A

They cannot be changed but we can reassign it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

"

A

Allows for quotation marks
““\monkey/””

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

\

A

Includes a backlash
At the end
Ex: Includes a backlash\

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

\n

A

“This creates \na line break
This creates
a line break

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

\t

A

“This adds a \ttab space”
“This adds a tab st[ace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

name.length

A

Returns the number of characters in a String object ( returns an int)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

name.substring(4)

A

Returns the substring beginning at index 4 and ending at the last index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

name.subString(2,6)

A

Returns the substring at index 2 and ends at 5

17
Q

name.equals(“Hello”)

A

Returns trye if name is equal to Hello
Returns false otherwise

18
Q

name.CompareTo(“Hello”)

A

Returns a value < 0 if name is less than Hello
Returns 0 if name is equal to Hello
Returns a value > - if name is greater than Hello

19
Q

numerical value

A

Starts from A is 65, Z is 90, ends at 126. 6 spaces between “Z’ and “a’

20
Q

name.IndexOf(“d”)

A

Returns the index of the first occurence of d (returns an int)
Returns -1 if not found

21
Q

Primitive

A

Most basic type in java, primitive variables store primitive values, don’t have associated methods

22
Q

Reference

A

Instantiable classes made by programmers that often use primitive types, reference variables store the address of the value, has associated methods

23
Q

Ex of primtive types

A

boolean, char, int double (anythign lowercase)

24
Q

ex of reference types

A

Interger, Double (anythign with uppercase)

25
Q

Integer.intValue();

A

converts Integer into int value

26
Q

wrapping purpose

A

Double > double > int > Integer
(Java already knows how to change int into Integer)

27
Q

Autoboxing

A

Java knows how to
int > Integer
double > Double

28
Q

Unboxing

A

Integer > int
Double > double

29
Q

Unboxing and Autoboxing purpose

A

Allows objects to be ised interchangeably without having to perform any casting explicitly.

30
Q

Non static method

A

Needs to be called with an object
objectName.methodName();

31
Q

Instance method

A

public int getWidth()

32
Q

Static method

A

Doesn’t need any objects
Classname.methodName();

33
Q

General formula for generating any number from start to num

A

int rand = (int)(Math.random() * (range + 1)):

34
Q

If we are not starting from 0, we add numbers to the random

A

int rand = (int)(Math.random() * (range + 1) + start)