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
Q

What is the delimiter for short comments

A

//

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

What is the delimiters for large comments?

A

/*
comment
**/

27
Q

What do you use the assignment operator for?

A

to change the value of a variable

28
Q

What is the assignment error

A

=

29
Q

Is it an error to use a variable that has never had a value assigned to it?

A

yes

30
Q

What does the assignment operator NOT do?

A

denote mathematical quality

31
Q

All objects of a given class share what?

A

the same methods

32
Q

What method counts the number of characters in a string?

A

length

33
Q

What method creates another String object that contains the characters of the original string, with lowercase letters converted to uppercase

A

toUpperCase

34
Q

What is held in the numberOfCharacters variable?
String greeting = “Hello, World!”;
int numberOfCharacters = greeting.length();

A

13

35
Q

What is held in the bigRiver variable?
String river = “Mississippi”;
String bigRiver = river.toUpperCase;

A

“MISSISSIPPI”

36
Q

What does the public interface of a class specify?

A

what you can do with its objects

37
Q

What does the private (hidden) implementation describe?

A

how actions in a method are carried out

38
Q

What is an argument?

A

a value that is supplied in a method call

39
Q

What is greeting in the following code?
System.out.println(greeting);

A

an argument

40
Q

What is the return value of a method?

A

a result that the method has computed

41
Q

What method carries out a search-and-replace operation

A

replace

42
Q

How many arguments does a replace method require?

A

2

43
Q

What does a method declaration specify?

A

the types of the arguments and the return value

44
Q

What is the return type when a method returns no value?

A

void

45
Q

Fill in the blank:
public ____ println(String output)

A

void

46
Q

What is over-loading?

A

when a name refers to more than one method

47
Q

What do you need to specify to create a new rectangle

A

x, y, width, height

48
Q

What is construction?

A

the process of creating a new object

49
Q

What is an assessor method

A

a method that accesses an object and returns some information about it, without changing the object

50
Q

What does API stand for?

A

Application Programming Interface

51
Q

What does the API documentation list?

A

the classes and method of the java library

52
Q

What does the detailed description of a method in the API Documentation show?

A

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
Q

What are classes in the standard library organized into?

A

packages

54
Q

What is a package?

A

a collection of classes with a related purpose

55
Q

What package does the rectangle class belong to?

A

java.awt

56
Q

What does a test program do?

A

verifies that method behave as expected

57
Q

What are the steps of making a test program?

A

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
Q

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

A test program

59
Q

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

A

x:
20
Expected: 20

60
Q

What does an object reference do?

A

describe the location of an object

61
Q

T/F: Multiple object variables can contain references to the same object

A

True

62
Q

What do number variables store?

A

numbers

63
Q

What do object variables store?

A

references

64
Q
A