AP CSC Unit 2

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/44

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

45 Terms

1
New cards
Java is an…
object-oriented programming language (organized in terms of objects)
2
New cards
What are objects?
A value that combines data and the code operating on that data into a single unit (specific instances of classes with defined attributes)
3
New cards
How do you define an object?
You write a class
4
New cards
What is a class?
A classification that defines a new data type that formally implements (the blueprint) the attributes and behaviors of the objects of that class
5
New cards
What does a class do?
classes define new data types that are like blueprints
6
New cards
What are attributes? (instances variable)
The properties or what each object knows about itself
7
New cards
What are behaviors? (methods)
What each object can do
8
New cards

What is a method signature? Give an example.

The method name followed by the param list that gives the name and type for each param. E.g. - public void inviteFriend ():

9
New cards

What is a NullPointerException?

Happens when you try to call an object method on an object variable with a null value. Usually means the oject was created without the new operator followed by the class name and ().

10
New cards

What is a static/class method? How is it different from a non-static/object method?

A static method is one that doesn’t need to be called on an object of a class. Object methods need to be called on an object of a class.

11
New cards

What operator do you use to run an object’s method?

The dot operator (.), the object, method name, and ending parenthesis. Eg. - yertle.forward()

12
New cards

What is procedural abstraction?

Allows a programmer to use a method by knowing generally what it does. Like how you can drive a car without knowing how the breaks work

13
New cards
What are arguments?
Data you can run into an object’s method
14
New cards
What are constructors?
Methods within each class used to initialize attributes in a newly created object (they have the same name as the class)
15
New cards
How do you create a new object?
Use the keyword “new” followed by the class name (Eg. new World()). When it runs, it will create a new object (instance) of that class and call a constructor that has the same name of the class (Eg. new World() creates and initializes a new object of the World class).
16
New cards
What is a no-argument constructor?
A constructor that doesn’t take any passed in values.
17
New cards
What is overloading (NOT AN ERROR)?
When there is more than one constructor defined in a class (E.g. World world1 = new World(); which calls it with default parameters, and World world2 = new World(width, height);). The parameter lists must differ in either number, order, or type of parameters to overload.
18
New cards
What does mixing up parameters do?
Cause an error (not the type of data expected, E.g. turtle parameters must always go x, y ,world)
19
New cards
What does null mean?
It says a variable has not been assigned a reference yet (no object to go find in memory). While Turtle t1 = new Turtle(20,20, world); declares that t1 is a turtle instance in Turtle, Turtle t1 = null; or Turtle t1; says that no value has been assigned yet.
20
New cards
What are constructor signatures (or headers)?
A constructor’s name and list of parameters. Can be used to overload a constructor.
21
New cards
What are parameters?
Things that allow values to be passed to the constructor to initialize the newly created object’s attributes
22
New cards
What is the difference between formal and actual parameters?
Formal parameters are in the constructor’s signature, while actual parameters are values passed into the constructor.
23
New cards
What does call by value mean?
When you pass a value to a constructor or method it passes a copy of the value
24
New cards

What do void methods return?

Nothing; the point of calling it is to have an effect (do things)

25
New cards

What do non-void methods do?

They return a value the code carrying the method call can use; the value returned tells us about the object’s internal state (produce values)

26
New cards

What is an accessor (getters)?

A method that accesses a value in an object, takes no arguments, and has a non-void return type (almost always starts with get, like getWidth)

27
New cards

What is a return statement (in a method)?

It returns the value output from the method, and must match the declared return type of the method. The calling method then uses that value.

28
New cards

What is a package?

The parent class of a class (For the String class, its in the java.lang package). Every class knows its parent class (superclass)

29
New cards

How do you cause implicit conversion of values to string values?

You concatenate them with a string object (“String” + nowAString + “String”)

30
New cards

List the escape sequences and what they do.

Within quotations, \” prints a quote, \\ prints a backslash, and \n prints a new line

31
New cards

What is an index?

A number associated with a string’s position. It begins at 0. One less than the length of a string (length starts at 1)

32
New cards

int length()

the number of characters in a string

33
New cards

String substring(int from, int up to but not including)

a new string that is a part of another string with 0 to all characters copied from the original string

34
New cards

immutable

doesn't change index the position of a character in a string

35
New cards

int indexOf(String str)

Returns the position of one string in another or -1

36
New cards

int compareTo(String other)

Returns a number to indicate if one string is less than (-difference), equal to (0), or greater than another (positive difference) (draw a greater or less than to find out)

37
New cards

Boolean equals(String other)

Returns true if the characters are the same, false otherwise

38
New cards

toString

Returns a string representing the object that is passed to this method

39
New cards

equals

Returns true if the characters in two strings are the same

40
New cards

Math.random() returns a random number between…

0.0-0.99.

41
New cards

What formula moves the random number into a range starting from a minimum number?

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

42
New cards

How do you find the range?

max number - min number + 1

43
New cards

(int)(Math.random() * (max - min)) + min
write the permutation code

44
New cards
45
New cards