AP CSC Unit 2

studied byStudied by 1 person
0.0(0)
get a hint
hint

Java is an…

1 / 44

45 Terms

1

Java is an…

object-oriented programming language (organized in terms of objects)

New cards
2

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)

New cards
3

How do you define an object?

You write a class

New cards
4

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

New cards
5

What does a class do?

classes define new data types that are like blueprints

New cards
6

What are attributes? (instances variable)

The properties or what each object knows about itself

New cards
7

What are behaviors? (methods)

What each object can do

New cards
8

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 ():

New cards
9

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 ().

New cards
10

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.

New cards
11

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

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

New cards
12

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

New cards
13

What are arguments?

Data you can run into an object’s method

New cards
14

What are constructors?

Methods within each class used to initialize attributes in a newly created object (they have the same name as the class)

New cards
15

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).

New cards
16

What is a no-argument constructor?

A constructor that doesn’t take any passed in values.

New cards
17

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.

New cards
18

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)

New cards
19

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.

New cards
20

What are constructor signatures (or headers)?

A constructor’s name and list of parameters. Can be used to overload a constructor.

New cards
21

What are parameters?

Things that allow values to be passed to the constructor to initialize the newly created object’s attributes

New cards
22

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.

New cards
23

What does call by value mean?

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

New cards
24

What do void methods return?

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

New cards
25

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)

New cards
26

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)

New cards
27

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.

New cards
28

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)

New cards
29

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

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

New cards
30

List the escape sequences and what they do.

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

New cards
31

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)

New cards
32

int length()

the number of characters in a string

New cards
33

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

New cards
34

immutable

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

New cards
35

int indexOf(String str)

Returns the position of one string in another or -1

New cards
36

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)

New cards
37

Boolean equals(String other)

Returns true if the characters are the same, false otherwise

New cards
38

toString

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

New cards
39

equals

Returns true if the characters in two strings are the same

New cards
40

Math.random() returns a random number between…

0.0-0.99.

New cards
41

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

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

New cards
42

How do you find the range?

max number - min number + 1

New cards
43

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

New cards
44
New cards
45
New cards

Explore top notes

note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 481 people
Updated ... ago
4.8 Stars(19)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 23 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 2542 people
Updated ... ago
4.8 Stars(10)

Explore top flashcards

flashcards Flashcard52 terms
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard62 terms
studied byStudied by 15 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard62 terms
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard35 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard75 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard137 terms
studied byStudied by 18 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard60 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard101 terms
studied byStudied by 59 people
Updated ... ago
5.0 Stars(2)