Chapter 2 - Understanding class definitions Flashcards

1
Q

notes:
1. usually used to hold temporary data
2. if a this has the same name as a field it will prevent access to the field

A

give two notes regarding
local variables

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

the syntax for this is:
System.out.print(value);

A

print to the console or standard output but do not start a new line

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

describe the 2 steps that
create a usable variable

A

steps include:
1. declaration - here we give the variable a type and name
2. initialisation - this is giving the variable a value for the first time

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

these are names that are given to
1. class name
2. variable name
3. method name
4. package name
5. constant name
6. and more

A

what are
identifiers

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

what is the syntax for a java
if else statement

A

syntax for this is:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}

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

whats the syntax for the string method that
returns the number of characters in the string

A

syntax is:
String.length();

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

a constructor must share the same name as its class whereas a method can be given any unique name

A

regarding methods and constructors
how are they named

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

a
method containing a return type
in the header will always consist of what inside the body

A

this will always have a return statement that returns data of the same type specified in the method header

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

what are the three types of variables in java

A

these include:
1.instance variables (Fields)
2.Formal parameters
3.Local variables

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

describe a
declaration
within a method

A

this is a local variable used to create additional and temporary variable space

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

what is a
arithmetic expression

A

an expression that will evaluate to a numerical value

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

if an instance variable is set to this then it cannot be directly accessed from outside its class

A

what does it mean if an
instance variable (field) is defined as private

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

Also known as the argument is the external value that is passed to the method or constructors formal parameter

A

describe an
actual parameter

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

within this there can be:
1. declarations
2. statements

A

what can be present
within the methodsbody/block

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

this is done by the java compiler and it checks that variables hold values that match there type

A

what is
static type checking

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

this is as follows:
access_modifier return_type method_name(parameters):
{
body
}

A

what is the
syntax of a java method

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

what is
static type checking

A

this is done by the java compiler and it checks that variables hold values that match there type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. Can be declared within a method or constructor
  2. are not given a default value, so you must initialise them before trying to use them.
A

how are
local variables initialised

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

a value that can be used with an operator

A

what is an
operand

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

what 4 names may an
accessor
be called

A

this may be called
1.Accessor methods
2.Accessors
3.Get methods
4.getter

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

describe the two operations of the
plus (+) opertaor

A
  1. Adds two operands together (if they are numbers)
    2.Concatenates strings, and concatenates strings with other types (the other types are converted to string)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

describe a
statement
within a method

A

within a method this is used to describe and carry out operations

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

these are methods that retrieve information from the objects fields and returns the information to the caller

A

what is an
accessor

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

give 3 points about java
Keywords/reserved words

A
  1. in java there are about 50 of these
  2. these are always written in lower case
  3. these can only be used by the language, a user cannot use these when setting identifiers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

within a method this is used to describe and carry out operations

A

describe a
statement
within a method

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

this is specifying the type and name of the variable

A

describe the process of
declaring a variable

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

these are operators that have two operands. Examples would be subtract or add

A

what is a
binary operator

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

A constructor’s header does not declare a return type, whereas a method’s header does.

A

regarding methods and constructors
which contain a return type in their header

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q
  1. declared within the class but outside of a constructor or method
  2. if it is not initialised it will be given a default value (best practice is to always initialise these using the constructor)
A

describe the
initialisation of instance variables (fields)

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

how are
local variables initialised

A
  1. Can be declared within a method or constructor
  2. are not given a default value, so you must initialise them before trying to use them.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

is simply a class header followed by a pair of empty braces

A

what is a
class wrapper

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

this is where we give a variable a value to hold
this can occur:
1. at intitalisation
2. after initialisation

A

what is an
assignment statement

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

name 3 properties of
accessors

A

properties include:
1.Always has a return type
2.Always has a return method
3.The method name can be prefixed with get to highlight that its role

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

regarding methods and constructors
how are they named

A

a constructor must share the same name as its class whereas a method can be given any unique name

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

syntax is:
String.length();

A

whats the syntax for the string method that
returns the number of characters in the string

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

what 3 componets make up an
assignment statement

A

compnents of this are:
1. variable
2. assignment operator
3. an expression or value

example:
value += 1

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

what is the
syntax of a java method

A

this is as follows:
access_modifier return_type method_name(parameters):
{
body
}

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

1.Defined in the header of a constructor or method
2. receive there values externally based on arguments received when a method or constructor is called.

A

describe the initialisation of
formal parameters

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

this component of a class comes before the braces and its main role is to supply a name for the class

A

describe the
header
of a class

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

ignore

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

this may be called
1.Accessor methods
2.Accessors
3.Get methods
4.getter

A

what 4 names may an
accessor
be called

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

This is also called the parameter and is the declaration of a parameter that is part of the method or constructors header

A

describe a
formal parameter

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

these have a scope of the body of their class and so can be accessed from anywhere in the class

A

what is the scope of
instance variables (fields)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q
  1. in java there are about 50 of these
  2. these are always written in lower case
  3. these can only be used by the language, a user cannot use these when setting identifiers
A

give 3 points about java
Keywords/reserved words

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

these have a scope within the body of their method or constructor.

A

what is the scope of
formal parameters

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

what is an
accessor

A

these are methods that retrieve information from the objects fields and returns the information to the caller

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

this is a name of a part of the program, such as:
1. class name
2. method name
3. variable name

A

what is an
identifier

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

describe the initialisation of
formal parameters

A

1.Defined in the header of a constructor or method
2. receive there values externally based on arguments received when a method or constructor is called.

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

what is a
boolean expression

A

this is an expression that will evaluate to either true or false

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

is a symbol that represents an operation that it can perform on either one or more operands

A

what is an
operator

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

describe the
initialisation of instance variables (fields)

A
  1. declared within the class but outside of a constructor or method
  2. if it is not initialised it will be given a default value (best practice is to always initialise these using the constructor)
52
Q

these are methods that change the state of an object. If this method has a statement that directly changes an objects field then we may call it a setter

A

describe a
mutator

53
Q

print to the console or standard output but do not start a new line

A

the syntax for this is:
System.out.print(value);

54
Q

these are operators that perform two actions usually
1. an operation
2. and then an assignment

examples:
j += 3; //same as j = j + 3;
j -= 2; //same as j = j – 2;
j++; //same as j = j + 1;

A

what is a
compound assignment operator

55
Q

what is an
identifier

A

this is a name of a part of the program, such as:
1. class name
2. method name
3. variable name

56
Q

this is an expression that will evaluate to either true or false

A

what is a
boolean expression

57
Q

what are
identifiers

A

these are names that are given to
1. class name
2. variable name
3. method name
4. package name
5. constant name
6. and more

58
Q

properties include:
1.Usually does not return any data
2.May be prefixed with the word “set” to highlight its role

A

name 2
properties of a mutator

59
Q

what is
dynamic type checking

A

this is carried out at run time by java and checks on the compatiblity of types (ie adding a string to a boolean)

60
Q

what is the scope of
formal parameters

A

these have a scope within the body of their method or constructor.

61
Q

what is the scope of
instance variables (fields)

A

these have a scope of the body of their class and so can be accessed from anywhere in the class

62
Q

compnents of this are:
1. variable
2. assignment operator
3. an expression or value

example:
value += 1

A

what 3 componets make up an
assignment statement

63
Q

the syntax for this is:
System.out.println(value);

A

print to the console or standard output and start a new line

64
Q

constructors cannot contain a return statement wheras a method can

A

regarding methods and constructors
which can have a return statement

65
Q

what can be present
within the methodsbody/block

A

within this there can be:
1. declarations
2. statements

66
Q

a constructor can only be called during the creation of an object whereas a method can be called at any point during an objects lifetime

A

regarding constructors and methods
when can they be used

67
Q

lifetime begins when its method is called and it lasts until the method’s execution ends.

A

what is the lifetime of
formal parameters

68
Q

describe a
method

A

define the behaviour of an object and perform some kind of functionality

69
Q

this component of a class is contained within the braces and contains the classes:
* fields
* constructor
* methods

A

describe the
body
of a class

70
Q

an expression that will evaluate to a numerical value

A

what is a
arithmetic expression

71
Q

name the 3 components that make up the syntax for a field

A

these include
1. access modifier (always defined as private, if mutation needed we use mutator methods)
2. type name
3. field name

syntax
Access_ modifier(private) type_name field_name;

72
Q

called only on the creation of an object and ensures an object is set up correctly when created

A

describe a
constructor

73
Q

describe a
formal parameter

A

This is also called the parameter and is the declaration of a parameter that is part of the method or constructors header

74
Q

what is the lifetime of
formal parameters

A

lifetime begins when its method is called and it lasts until the method’s execution ends.

75
Q

describe a
mutator

A

these are methods that change the state of an object. If this method has a statement that directly changes an objects field then we may call it a setter

76
Q

how will a skeleton class look

A

a skeleton of this is as follows:
Public class ClassName
{
Fields
Constructors
methods
}

77
Q

these include
1.Header
2.Body

A

what are the two components of a
class

78
Q

this is giving a variable a value for the first time

A

describe the process of
initialising a variable

79
Q

regarding constructors and methods
when can they be used

A

a constructor can only be called during the creation of an object whereas a method can be called at any point during an objects lifetime

80
Q

what is a
class wrapper

A

is simply a class header followed by a pair of empty braces

81
Q

regarding methods and constructors
which can have a return statement

A

constructors cannot contain a return statement wheras a method can

82
Q

these include:
1.Mutator method
2.Set method
3.Mutator
4.Setter

A

give 4 names that a
mutator
may be called

83
Q

a skeleton of this is as follows:
Public class ClassName
{
Fields
Constructors
methods
}

A

how will a skeleton class look

84
Q

the lifetime begins when its object is created and it lasts until its object is destroyed.

A

what is the
lifetime of instance variables (fields)

85
Q

what is the
scope of a local variable

A

have a scope from where they are declared until the end of their enclosing block of code.

86
Q

what does it mean if an
instance variable (field) is defined as private

A

if an instance variable is set to this then it cannot be directly accessed from outside its class

87
Q

these include:
1.instance variables (Fields)
2.Formal parameters
3.Local variables

A

what are the three types of variables in java

88
Q

name 2
properties of a mutator

A

properties include:
1.Usually does not return any data
2.May be prefixed with the word “set” to highlight its role

89
Q

describe a
constructor

A

called only on the creation of an object and ensures an object is set up correctly when created

90
Q

whats the syntax for the string method that
returns a new string from begin index to end index -1

A

syntax is:
String.substring(beginIndex, endIndex);

91
Q

what is the
lifetime of instance variables (fields)

A

the lifetime begins when its object is created and it lasts until its object is destroyed.

92
Q

give 4 names that a
mutator
may be called

A

these include:
1.Mutator method
2.Set method
3.Mutator
4.Setter

93
Q

if on operand is an integer and the other operand is a float what data type will the result be

A

in this case the result will be converted to a double

94
Q

describe the
header
of a class

A

this component of a class comes before the braces and its main role is to supply a name for the class

95
Q

properties include:
1.Always has a return type
2.Always has a return method
3.The method name can be prefixed with get to highlight that its role

A

name 3 properties of
accessors

96
Q

give two notes regarding
local variables

A

notes:
1. usually used to hold temporary data
2. if a this has the same name as a field it will prevent access to the field

97
Q

describe an
actual parameter

A

Also known as the argument is the external value that is passed to the method or constructors formal parameter

98
Q

this will always have a return statement that returns data of the same type specified in the method header

A

a
method containing a return type
in the header will always consist of what inside the body

99
Q

what is a
compound assignment operator

A

these are operators that perform two actions usually
1. an operation
2. and then an assignment

examples:
j += 3; //same as j = j + 3;
j -= 2; //same as j = j – 2;
j++; //same as j = j + 1;

100
Q

syntax is:
String.substring(beginIndex, endIndex);

A

whats the syntax for the string method that
returns a new string from begin index to end index -1

101
Q
  1. Adds two operands together (if they are numbers)
    2.Concatenates strings, and concatenates strings with other types (the other types are converted to string)
A

describe the two operations of the
plus (+) opertaor

102
Q

lifetime begins after its declaration is executed and it lasts until the program flow moves outside of the variable’s enclosing block of code.

A

what is the
lifetime of a local variable

103
Q

what is an
assignment statement

A

this is where we give a variable a value to hold
this can occur:
1. at intitalisation
2. after initialisation

104
Q

in this case the result will be converted to a double

A

if on operand is an integer and the other operand is a float what data type will the result be

105
Q

this is carried out at run time by java and checks on the compatiblity of types (ie adding a string to a boolean)

A

what is
dynamic type checking

106
Q

these include
1. access modifier (always defined as private, if mutation needed we use mutator methods)
2. type name
3. field name

syntax
Access_ modifier(private) type_name field_name;

A

name the 3 components that make up the syntax for a field

107
Q

describe the
body
of a class

A

this component of a class is contained within the braces and contains the classes:
* fields
* constructor
* methods

108
Q

this is a local variable used to create additional and temporary variable space

A

describe a
declaration
within a method

109
Q

what are the two components of a
class

A

these include
1.Header
2.Body

110
Q

what is an
operand

A

a value that can be used with an operator

111
Q

what is a
binary operator

A

these are operators that have two operands. Examples would be subtract or add

112
Q

define the behaviour of an object and perform some kind of functionality

A

describe a
method

113
Q

steps include:
1. declaration - here we give the variable a type and name
2. initialisation - this is giving the variable a value for the first time

A

describe the 3 steps that
create a usable variable

114
Q

these are operators that have only one operand. Exampless include ++ and – which increment or decrement their operands by one

A

what is a
unary operator

115
Q

describe the process of
declaring a variable

A

this is specifying the type and name of the variable

116
Q

what is the
lifetime of a local variable

A

lifetime begins after its declaration is executed and it lasts until the program flow moves outside of the variable’s enclosing block of code.

117
Q

this asseses a condition and then takes one of two actions depending on the outcome of the condition

A

what is a
conditional statement

118
Q

print to the console or standard output and start a new line

A

the syntax for this is:
System.out.println(value);

119
Q

what is a
conditional statement

A

this asseses a condition and then takes one of two actions depending on the outcome of the condition

120
Q

what is a
unary operator

A

these are operators that have only one operand. Exampless include ++ and – which increment or decrement their operands by one

121
Q

have a scope from where they are declared until the end of their enclosing block of code.

A

what is the
scope of a local variable

122
Q

ignore

123
Q

what is an
operator

A

is a symbol that represents an operation that it can perform on either one or more operands

124
Q

syntax for this is:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}

A

what is the syntax for a java
if else statement

125
Q

regarding methods and constructors
which contain a return type in their header

A

A constructor’s header does not declare a return type, whereas a method’s header does.

126
Q

describe the process of
initialising a variable

A

this is giving a variable a value for the first time