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
//