chapter 3
how do you format a parameter in a uml?
( name : type)
in a UML, if the instance variable private, you put a...
- (minus)
what are all the primitive types?
Boolean, byte, char, short, int, long, float, and double.
explain what is going on in this statement Gradebook myGradeBook = new GradeBook(); go left to right
Gradebook declares what type of variable myGradeBook will be, myGradeBook names the variable, "=" initializes myGradeBook with the result of the class instance creation expression of new GradeBook(), new creates a new object of the class specified, and the () are just there for now.
each parameter must specify...
a type and variable name.
keyword "public" is an...
access modifier
private is a...
access modifier
variables or methods declared with access modifier private are....
accessible only to methods of the class in which they're declared.
main methods are...
always called on by the JVM when program is exe.d
a client of an object is..
any class that calls the objects methods
the parameter list may contain....
any number of parameters.
what are reference types?
anything that not a primitive type. classes which specify the types of objects
why is java known as a extensible language?
because each new class you make becomes a new type that can be used to declare variables and create objects.
even though a constructor is a method, why can't it even have void?
because it can never be able to return values.
a constructor must have the ____ ____ as the class.
same name
classes often provide public methods to allow clients to ____ or ____ private instance variables.
set; get
float represents... (digits too)
single-precision floating-point numbers and can represent up to seven significant digits
return type (provide an example)
specifies the type of data the method gives back to it's caller after performing it's task. VOID
what does method setCourseName do in the gradebook?
stores a course name in a gradebook
the empty parentheses after the method name indicate what?
that it is a method and that it doesn't need any extra info to complete its task.
the parentheses after the method name indicate what?
that it is a method.
return type void means....
that method will perform a task but will not return (give back) any info to its calling method. It instead gives it to the program for use.
no parameters indicate...
the method doesn't need any parameters at all
do the argument and parameters names always have to match?
the name has to match
%.2f means...
the number of decimal places (in this case 2) that should output to the right of the decimal point in the floating point number. it rounds if it needs to
the number of decimal places that should output to the right of the decimal point in the floating point number.
the numbers precision
you put : String after the () in a UML when...
the return type is a string
what does "+" mean in a UML?
the the operation is a public operation. basically, additional info
a client of an object call the class's public methods...
to manipulate the private fields of an object of the class.
arguments
values that are supplied by a method call for each of the method's parameters.
in a class declaration, attributes are represented as....
variables
local variables
variables declared in the body of a particular method
what is a field
variables declared inside a class but outside methods.
What do we do to test classes without a main method?
we make a driver class, one that has a main method
when is a case where you don't have to declare the variable?
when it is the instance variable of the class
when can you not create a Gradebook object with new Gradebook()? why? (hint class GradeBook has a constructor)
when you've declared any constructors for a class. because now there is no default to go to any more; since you've declared a constructor, one have to enter in a name yoursel.
how do you put a construct with it's class, type, and name of that type in a uml?
«constructor» Account( typename : type )
what should a parameter list look like?
comma separated list inside the parentheses.
declaring instance variables with access modifier private is known as...
data hiding or information hiding.
what two primitive types store floating point numbers?
float and double
decimal numbers in source code are known as...
floating-point literals
%f is for...
floats and doubles
when you put a constructor in a uml, you put ____ around it.
guillemets « »
where do constructors go in a uml diagram?
in the third box, at the top
primitive-type instance variables are.... (initialization)
initialized by default
local variable are not... (initialization)
initialized by default.
public means...
it can be called from methods of other classes
what are some properties of local variables?
it can only be used in the method it is declared in, when the method terminates, the local variable terminates
what does it mean for a displayMessage to have a empty parameter? ()
it does not require any additional information to perform it's task
Method nextLine reads characters typed by the user until....
it encounters the newline character, then returns a String containing the characters up to, but not including, the new line. Newline is discarded.
double is preferred because....
it is more accurate
what does method getCourseName do in the gradebook?
it obtains the course name
in public String getCourseName() { return courseName; } what does "String" represent?
it's return type
parameter
its value helps the car to determine how fast to accelerate
how do you use a Scanner without importing?
java.util.Scanner input = new java.util.Scanner( System.in );
encapsulating is basically...
making something private.
myGradeBook.displayMessage(); is an example of a...
method call
String courseName = input.nextLine(); what does next do?
next reads individual words.
floating-point number
number w/ decimal point
one meaning of get.
obtain values of
what does a UML class diagram look like and what are the different slots for?
one big rect. with 3 smaller rects in it. the top has class name, middle has attributes, and bottom has methods.
a methods can require... (something about parameters)
one or more parameters that rep. additional info it needs to perform its task.
a primitive-type variable can store exactly...
one value of its declared type at a time
Java's types are divided into ________ and _________.
primitive types; reference types.
most instance-variable declarations are preceded with the keyword...
privatE
how do you declare an instance variable?
private String Name; put it outside of any method statement bodies.
if you want to add a custom initialization to an object you create, you must...
provide a special method called a constructor.
the access modifier of a constructor is normally...
public
When you use an object of another class, a ______ to the object is required to ____ (call) its methods.
reference; invoke
what are reference types normally called?
references
1. Programs use variables of reference types to... 2.Such a variable is said to...
1. store the locations of objects in the computers memory. 2.refer to an object in the program.
how do you write a constructor?
[access modifier] [class name]( [type] [variable] )
how do you initialize objects with multiple data items? (constructor)
[access modifier] [object name]( [type 1] [name], [type 2] [name] )
the constructor of an object with custom initialization needs to have...
a parameter with it's type.
one meaning of set.
assign values to
fields are (variables)
attributes that are represented as variables in a class declaration. however they are outside the bodies of the class's method declarations.
how do double and float differ?
double can store larger values than float, and also with finer detail (more digits to right of decimal)
double represents.... (amt of memory and digits)
double-precision floating-point numbers and they need twice the amount of memory that floats and provide up to 15 digits
a call to the constructor is indicated by the....
parentheses after the class name during object declaration
in order to initialize the name the objects of the class, you must specify it in the....
parentheses after the class name during the declaration of the object ex. GradeBook myGradeBook = new GradeBook( "INSET NAME HERE")