Chapter 2: Using Objects Flashcards

1
Q

What are objects?

A

the “building blocks” of java, which can be manipulated, and have their own behavior

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

What does a method consist of

A

a sequence of instructions that can access the internal data of an object

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

What is NOT important for a programmer to understand

A

HOW an object gets its work done

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

What does a class allow a programmer to do?

A

apply the same method to multiple objects

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

what are variables used for?

A

to store data

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

What is this code an example of:
int width = 20;

A

a variable

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

What are the two syntaxes for a variable

A

typeName variableName = value;
OR
typeName variableName;

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

Write a variable that stores: Hello, Dave!

A

String greeting = “Hello, Dave!”;

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

What is a variable?

A

a storage location in a computer program

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

What do you usually specify when declaring a variable?

A

an initial value

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

What must you specify when declaring a variable

A

a type

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

What is the type for whole numbers?

A

intiger (int)

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

What type of number includes a fraction?

A

floating-point number

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

What is this an example of?
double milesPerGallon = 22;

A

declaring a variable that holds a floating-point number

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

What type is used for floating-point numbers?

A

double

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

How do you combine numbers?

A

through arithmetic operators such as +, -, *, /

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

What does a type specify

A

the operations that can be carried out with its values

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

What should a name explain?

A

its purpose

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

What are the name rules?

A

1.) the first character must be a letter or underscore, the remaining characters must be letters, numbers, or underscores
2.) use camelcase, capitalization instead of space
3.) names are case sensitive
4.) you cannot use reserved words

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

What is this an example of?
milesPerGallon

A

camelcase

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

What are these an example of?
double, class

A

reserved words

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

How, by convention, should you name your names

A

should start with a lowercase letter

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

What are comments

A

explanations for human readers of you code

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

What is this an example of?
double milesPerGallon = 33.8; //The Average fuel efficiency of new US cars in 2011

A

a comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the delimiter for short comments
//
26
What is the delimiters for large comments?
/* comment **/
27
What do you use the assignment operator for?
to change the value of a variable
28
What is the assignment error
=
29
Is it an error to use a variable that has never had a value assigned to it?
yes
30
What does the assignment operator NOT do?
denote mathematical quality
31
All objects of a given class share what?
the same methods
32
What method counts the number of characters in a string?
length
33
What method creates another String object that contains the characters of the original string, with lowercase letters converted to uppercase
toUpperCase
34
What is held in the numberOfCharacters variable? String greeting = "Hello, World!"; int numberOfCharacters = greeting.length();
13
35
What is held in the bigRiver variable? String river = "Mississippi"; String bigRiver = river.toUpperCase;
"MISSISSIPPI"
36
What does the public interface of a class specify?
what you can do with its objects
37
What does the private (hidden) implementation describe?
how actions in a method are carried out
38
What is an argument?
a value that is supplied in a method call
39
What is greeting in the following code? System.out.println(greeting);
an argument
40
What is the return value of a method?
a result that the method has computed
41
What method carries out a search-and-replace operation
replace
42
How many arguments does a replace method require?
2
43
What does a method declaration specify?
the types of the arguments and the return value
44
What is the return type when a method returns no value?
void
45
Fill in the blank: public ____ println(String output)
void
46
What is over-loading?
when a name refers to more than one method
47
What do you need to specify to create a new rectangle
x, y, width, height
48
What is construction?
the process of creating a new object
49
What is an assessor method
a method that accesses an object and returns some information about it, without changing the object
50
What does API stand for?
Application Programming Interface
51
What does the API documentation list?
the classes and method of the java library
52
What does the detailed description of a method in the API Documentation show?
The action that the method carries out, the types and names of the parameter variables that receive the arguments when the method is called, and the value that it returns
53
What are classes in the standard library organized into?
packages
54
What is a package?
a collection of classes with a related purpose
55
What package does the rectangle class belong to?
java.awt
56
What does a test program do?
verifies that method behave as expected
57
What are the steps of making a test program?
1.) Provide a tester class 2.) Supply a main method 3.) Inside the main method, construct one or more objects 4.) Apply methods to the object 5.) Display the results of the method calls 6.) Display the values that you expect to get
58
What is this code an example of? Rectangle box = new Rectangle(5,10,20,30); //Move the Rectangle box.translate(15,25); //Print out information about the moved rectangle System.out.print("x: "); System.out.print("box.getX()); System.out.println("Expected: 20")
A test program
59
What is the result of this program? Rectangle box = new Rectangle(5,10,20,30); //Move the Rectangle box.translate(15,25); //Print out information about the moved rectangle System.out.print("x: "); System.out.print("box.getX()); System.out.println("Expected: 20")
x: 20 Expected: 20
60
What does an object reference do?
describe the location of an object
61
T/F: Multiple object variables can contain references to the same object
True
62
What do number variables store?
numbers
63
What do object variables store?
references
64