Chapter 2: Using Objects Flashcards
What are objects?
the “building blocks” of java, which can be manipulated, and have their own behavior
What does a method consist of
a sequence of instructions that can access the internal data of an object
What is NOT important for a programmer to understand
HOW an object gets its work done
What does a class allow a programmer to do?
apply the same method to multiple objects
what are variables used for?
to store data
What is this code an example of:
int width = 20;
a variable
What are the two syntaxes for a variable
typeName variableName = value;
OR
typeName variableName;
Write a variable that stores: Hello, Dave!
String greeting = “Hello, Dave!”;
What is a variable?
a storage location in a computer program
What do you usually specify when declaring a variable?
an initial value
What must you specify when declaring a variable
a type
What is the type for whole numbers?
intiger (int)
What type of number includes a fraction?
floating-point number
What is this an example of?
double milesPerGallon = 22;
declaring a variable that holds a floating-point number
What type is used for floating-point numbers?
double
How do you combine numbers?
through arithmetic operators such as +, -, *, /
What does a type specify
the operations that can be carried out with its values
What should a name explain?
its purpose
What are the name rules?
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
What is this an example of?
milesPerGallon
camelcase
What are these an example of?
double, class
reserved words
How, by convention, should you name your names
should start with a lowercase letter
What are comments
explanations for human readers of you code
What is this an example of?
double milesPerGallon = 33.8; //The Average fuel efficiency of new US cars in 2011
a comment
What is the delimiter for short comments
//
What is the delimiters for large comments?
/*
comment
**/
What do you use the assignment operator for?
to change the value of a variable
What is the assignment error
=
Is it an error to use a variable that has never had a value assigned to it?
yes
What does the assignment operator NOT do?
denote mathematical quality
All objects of a given class share what?
the same methods
What method counts the number of characters in a string?
length
What method creates another String object that contains the characters of the original string, with lowercase letters converted to uppercase
toUpperCase
What is held in the numberOfCharacters variable?
String greeting = “Hello, World!”;
int numberOfCharacters = greeting.length();
13
What is held in the bigRiver variable?
String river = “Mississippi”;
String bigRiver = river.toUpperCase;
“MISSISSIPPI”
What does the public interface of a class specify?
what you can do with its objects
What does the private (hidden) implementation describe?
how actions in a method are carried out
What is an argument?
a value that is supplied in a method call
What is greeting in the following code?
System.out.println(greeting);
an argument
What is the return value of a method?
a result that the method has computed
What method carries out a search-and-replace operation
replace
How many arguments does a replace method require?
2
What does a method declaration specify?
the types of the arguments and the return value
What is the return type when a method returns no value?
void
Fill in the blank:
public ____ println(String output)
void
What is over-loading?
when a name refers to more than one method
What do you need to specify to create a new rectangle
x, y, width, height
What is construction?
the process of creating a new object
What is an assessor method
a method that accesses an object and returns some information about it, without changing the object
What does API stand for?
Application Programming Interface
What does the API documentation list?
the classes and method of the java library
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
What are classes in the standard library organized into?
packages
What is a package?
a collection of classes with a related purpose
What package does the rectangle class belong to?
java.awt
What does a test program do?
verifies that method behave as expected
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
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
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
What does an object reference do?
describe the location of an object
T/F: Multiple object variables can contain references to the same object
True
What do number variables store?
numbers
What do object variables store?
references