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
Q

What is a constructor

A

A special method that creates an object and assigns initial value to data

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

What is required for the constructor (in relation to the class)

A

The constructor has the same name as the class

27
Q

What is an arg list

A

The argument list is a comma separated list of initial values to assign to the object data

28
Q

What are accessor methods used for

A

Return the current values of object data

29
Q

What are mutator methods used for

A

Change the values of object data

30
Q

Describe Method Return Values

A

Can be a primitive data type, class type or void

31
Q

What is value-returning methods

A

The method returns a value
Thus the method call is used in an expression
When the expression is evaluated, the return value

32
Q

Describe methods with a void return type

A

Do not return a value

Method call is a complete statement

33
Q

What is the definition of argument

A

Any expression that evaluates to the specific data type

34
Q

What is a common error made with methods

A

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
Q

What is an object references

A

An object reference point to the memory location of object data. An object can have multiple object references pointing to it

36
Q

What occurs if an object has no object references pointing to it

A

The garbage collector will go and free the objects memory

37
Q

What is a null object reference

A

If an object reference points to no object then the value is null

38
Q

What is the other instance when an object reference can have the value null

A

Object references can have the value null when they have been declared but have not been used to instantiate an object

39
Q

How are classes grouped

A

Into packages according to functionality

40
Q

What does the string class represent

A

A sequence of characters

41
Q

What are common errors associated with a string

A

When a negative start index or a start index past the last character of the String will create an error

42
Q

What does parsing a string generally mean

A

Parsing a string generally means using several of the String methods together

43
Q

What are the DecimalFortmat and NumberFormat class used for

A

They allow you to specific the number of digits for printing and to add dollar signs and percent signs to your output

44
Q

Whats the random class used for

A

Generates a pseudorandom number

45
Q

What is the nextInt method used for

A

The nextInt method is used to generate a random integer between 1 and 6

46
Q

What does input using the scanner class allow you to do

A

Provides methods for reading byte, short, int, long, float, double, and String data types from the java console and other sources

47
Q

What is the function of the scanner class

A

Scanner parses (separates) input into sequences of characters

48
Q

What is a character sequence generally called in code

A

a token

49
Q

How are tokens usually separated

A

By standard white space characters

50
Q

What is the function of Scanner Constructor (ex: Scanner (input stream source)

A

Creates a scanner object for reading from source

51
Q

What is the difference between the next and nextline method

A

The next method will read only one word of String input whereas the next line method reads the whole line

52
Q

What is the other name for static methods

A

Static methods are also called class methods

53
Q

Can static methods be called without instantiating an object?

A

Yes, static methods can be called without having to instantiate an object

54
Q

When you call a static method, what is the general syntax used with it

A

It is important to use the dot syntax with the class name instead of the object reference

55
Q

What does implicitly mean in the context of programming

A

It is done automatically

56
Q

What are the two static constants of the Math Class

A

PI and E

57
Q

What is the PI constant used for in the Math Class

A

Pi is the value of pi

58
Q

What is the E constant used for in the Math Class

A

E is the base of the natural logarithm

59
Q

What are the rules imposed by the math round method

A

Any fractional part

60
Q

What is the wrapper class used for

A

It wraps the value of a primitive data type into an object.

61
Q

When is the wrapper class most useful

A

The wrapper class is most useful when methods require an object argument or to convert strings to an int or a double

62
Q

What is autoboxing

A

An automatic conversion between a primitive type and a wrapper object when a primitive type is used where an object is expected.

63
Q

What is unboxing

A

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
Q

What is the methods of the character class used for

A

The charter class includes methods to test is a single character is a digit, a letter, upper