Chapter 3 PDF Flashcards

1
Q

What is the function of class

A

Classes combine data and the methods (code) to manipulate the data. Classes are a template used to create specific objects

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

What is a requirement for all java programs in relation to classes

A

All java programs consists of at least one class

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

What are the two types of classes

A

Application classes and

Service classes

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

Why are classes used

A

Classes allow us to separate the data for each object, while using common code to manipulate each object

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

Describe the data for a student class (example)

A

name, year, grade point average

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

Describe the methods for a student class (example)

A

store/get the value of the data, promote to next year etc

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

What is an object reference

A

An identifier of the object

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

How do you instantiating an object

A

Creating an object of a class; assigns initial values to the object data

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

What is the requirement for objects before being used

A

Objects need to be instantiated before being used

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

What is the instance of a class

A

An object after instantiation

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

What is the member of a class

A

The classes fields and methods

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

What are two types of fields

A

instance variables and static variables

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

What is an instance variable

A

Variables defined in the class and given a value in each object

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

What can fields be

A

Any primitive data type and objects of the same or another class

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

What are methods

A

Code to manipulate object data

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

What occurs when you declare an instance variable to be private

A

They cannot be accessed directly outside of the class. Can only reference the private data of an object by calling methods of the class

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

What is function of methods in relation to data

A

It encapsulates the data and provides a protective shell around it

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

What is the benefit to methods

A

The classes methods can ensure that the object data is always valid

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

What is the naming convention for class names

A

Start with a capital letter

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

What is the naming convention for object references

A

Start with a lowercase letter

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

What is the benefit of reusing code

A

Class code is already written and tested. New applications can be built faster. The applications will be more reliable

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

What is the purpose of API

A

Application programming interface

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

What information does the API tell us

A

How to create objects
What methods are available
How to call the methods

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

What does the object reference do

A

The object reference holds the address of the object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is a constructor
A special method that creates an object and assigns initial value to data
26
What is required for the constructor (in relation to the class)
The constructor has the same name as the class
27
What is an arg list
The argument list is a comma separated list of initial values to assign to the object data
28
What are accessor methods used for
Return the current values of object data
29
What are mutator methods used for
Change the values of object data
30
Describe Method Return Values
Can be a primitive data type, class type or void
31
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
32
Describe methods with a void return type
Do not return a value | Method call is a complete statement
33
What is the definition of argument
Any expression that evaluates to the specific data type
34
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.
35
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
36
What occurs if an object has no object references pointing to it
The garbage collector will go and free the objects memory
37
What is a null object reference
If an object reference points to no object then the value is null
38
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
39
How are classes grouped
Into packages according to functionality
40
What does the string class represent
A sequence of characters
41
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
42
What does parsing a string generally mean
Parsing a string generally means using several of the String methods together
43
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
44
Whats the random class used for
Generates a pseudorandom number
45
What is the nextInt method used for
The nextInt method is used to generate a random integer between 1 and 6
46
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
47
What is the function of the scanner class
Scanner parses (separates) input into sequences of characters
48
What is a character sequence generally called in code
a token
49
How are tokens usually separated
By standard white space characters
50
What is the function of Scanner Constructor (ex: Scanner (input stream source)
Creates a scanner object for reading from source
51
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
52
What is the other name for static methods
Static methods are also called class methods
53
Can static methods be called without instantiating an object?
Yes, static methods can be called without having to instantiate an object
54
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
55
What does implicitly mean in the context of programming
It is done automatically
56
What are the two static constants of the Math Class
PI and E
57
What is the PI constant used for in the Math Class
Pi is the value of pi
58
What is the E constant used for in the Math Class
E is the base of the natural logarithm
59
What are the rules imposed by the math round method
Any fractional part
60
What is the wrapper class used for
It wraps the value of a primitive data type into an object.
61
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
62
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.
63
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
64
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