Chapter 3 PDF Flashcards
What is the function of class
Classes combine data and the methods (code) to manipulate the data. Classes are a template used to create specific objects
What is a requirement for all java programs in relation to classes
All java programs consists of at least one class
What are the two types of classes
Application classes and
Service classes
Why are classes used
Classes allow us to separate the data for each object, while using common code to manipulate each object
Describe the data for a student class (example)
name, year, grade point average
Describe the methods for a student class (example)
store/get the value of the data, promote to next year etc
What is an object reference
An identifier of the object
How do you instantiating an object
Creating an object of a class; assigns initial values to the object data
What is the requirement for objects before being used
Objects need to be instantiated before being used
What is the instance of a class
An object after instantiation
What is the member of a class
The classes fields and methods
What are two types of fields
instance variables and static variables
What is an instance variable
Variables defined in the class and given a value in each object
What can fields be
Any primitive data type and objects of the same or another class
What are methods
Code to manipulate object data
What occurs when you declare an instance variable to be private
They cannot be accessed directly outside of the class. Can only reference the private data of an object by calling methods of the class
What is function of methods in relation to data
It encapsulates the data and provides a protective shell around it
What is the benefit to methods
The classes methods can ensure that the object data is always valid
What is the naming convention for class names
Start with a capital letter
What is the naming convention for object references
Start with a lowercase letter
What is the benefit of reusing code
Class code is already written and tested. New applications can be built faster. The applications will be more reliable
What is the purpose of API
Application programming interface
What information does the API tell us
How to create objects
What methods are available
How to call the methods
What does the object reference do
The object reference holds the address of the object
What is a constructor
A special method that creates an object and assigns initial value to data
What is required for the constructor (in relation to the class)
The constructor has the same name as the class
What is an arg list
The argument list is a comma separated list of initial values to assign to the object data
What are accessor methods used for
Return the current values of object data
What are mutator methods used for
Change the values of object data
Describe Method Return Values
Can be a primitive data type, class type or void
What is value-returning methods
The method returns a value
Thus the method call is used in an expression
When the expression is evaluated, the return value
Describe methods with a void return type
Do not return a value
Method call is a complete statement
What is the definition of argument
Any expression that evaluates to the specific data type
What is a common error made with methods
When calling a method, include only expressions in your argument list. If you include data types in the argument list you will cause a compiler error.
What is an object references
An object reference point to the memory location of object data. An object can have multiple object references pointing to it
What occurs if an object has no object references pointing to it
The garbage collector will go and free the objects memory
What is a null object reference
If an object reference points to no object then the value is null
What is the other instance when an object reference can have the value null
Object references can have the value null when they have been declared but have not been used to instantiate an object
How are classes grouped
Into packages according to functionality
What does the string class represent
A sequence of characters
What are common errors associated with a string
When a negative start index or a start index past the last character of the String will create an error
What does parsing a string generally mean
Parsing a string generally means using several of the String methods together
What are the DecimalFortmat and NumberFormat class used for
They allow you to specific the number of digits for printing and to add dollar signs and percent signs to your output
Whats the random class used for
Generates a pseudorandom number
What is the nextInt method used for
The nextInt method is used to generate a random integer between 1 and 6
What does input using the scanner class allow you to do
Provides methods for reading byte, short, int, long, float, double, and String data types from the java console and other sources
What is the function of the scanner class
Scanner parses (separates) input into sequences of characters
What is a character sequence generally called in code
a token
How are tokens usually separated
By standard white space characters
What is the function of Scanner Constructor (ex: Scanner (input stream source)
Creates a scanner object for reading from source
What is the difference between the next and nextline method
The next method will read only one word of String input whereas the next line method reads the whole line
What is the other name for static methods
Static methods are also called class methods
Can static methods be called without instantiating an object?
Yes, static methods can be called without having to instantiate an object
When you call a static method, what is the general syntax used with it
It is important to use the dot syntax with the class name instead of the object reference
What does implicitly mean in the context of programming
It is done automatically
What are the two static constants of the Math Class
PI and E
What is the PI constant used for in the Math Class
Pi is the value of pi
What is the E constant used for in the Math Class
E is the base of the natural logarithm
What are the rules imposed by the math round method
Any fractional part
What is the wrapper class used for
It wraps the value of a primitive data type into an object.
When is the wrapper class most useful
The wrapper class is most useful when methods require an object argument or to convert strings to an int or a double
What is autoboxing
An automatic conversion between a primitive type and a wrapper object when a primitive type is used where an object is expected.
What is unboxing
An automatic conversion between a wrapper object and a primitive data type when a wrapper object is used where a primitive data type is expected
What is the methods of the character class used for
The charter class includes methods to test is a single character is a digit, a letter, upper