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
within a method this is used to describe and carry out operations
describe a **statement** within a method
26
this is specifying the type and name of the variable
describe the process of **declaring a variable**
27
these are operators that have two operands. Examples would be subtract or add
what is a **binary operator**
28
A constructor’s header does not declare a return type, whereas a method’s header does.
regarding methods and constructors which contain a return type in their header
29
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)
describe the **initialisation of instance variables (fields)**
30
how are **local variables initialised**
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.
31
is simply a class header followed by a pair of empty braces
what is a **class wrapper**
32
this is where we give a variable a value to hold this can occur: 1. at intitalisation 2. after initialisation
what is an **assignment statement**
33
name 3 properties of **accessors**
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
34
regarding methods and constructors how are they named
a constructor must share the same name as its class whereas a method can be given any unique name
35
syntax is: **String.length();**
whats the syntax for the string method that **returns the number of characters in the string**
36
what 3 componets make up an **assignment statement**
compnents of this are: 1. variable 2. assignment operator 3. an expression or value example: value += 1
37
what is the **syntax of a java method**
this is as follows: access_modifier return_type method_name(parameters): { body }
38
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.
describe the initialisation of **formal parameters**
39
this component of a class comes before the braces and its main role is to supply a name for the class
describe the **header** of a class
40
[chapter 2 quiz](https://learn2.open.ac.uk/mod/quiz/view.php?id=2014890)
ignore
41
this may be called 1.Accessor methods 2.Accessors 3.Get methods 4.getter
what 4 names may an **accessor** be called
42
This is also called the parameter and is the declaration of a parameter that is part of the method or constructors header
describe a **formal parameter**
43
these have a scope of the body of their class and so can be accessed from anywhere in the class
what is the scope of **instance variables (fields)**
44
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
give 3 points about java **Keywords/reserved words**
45
these have a scope within the body of their method or constructor.
what is the scope of **formal parameters**
46
what is an **accessor**
these are methods that retrieve information from the objects fields and returns the information to the caller
47
this is a name of a part of the program, such as: 1. class name 2. method name 3. variable name
what is an **identifier**
48
describe the initialisation of **formal parameters**
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.
49
what is a **boolean expression**
this is an expression that will evaluate to either true or false
50
is a symbol that represents an operation that it can perform on either one or more operands
what is an **operator**
51
describe the **initialisation of instance variables (fields)**
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
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
describe a **mutator**
53
print to the console or standard output but do not start a new line
the syntax for this is: System.out.print(value);
54
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;
what is a **compound assignment operator**
55
what is an **identifier**
this is a name of a part of the program, such as: 1. class name 2. method name 3. variable name
56
this is an expression that will evaluate to either true or false
what is a **boolean expression**
57
what are **identifiers**
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
properties include: 1.Usually does not return any data 2.May be prefixed with the word "set" to highlight its role
name 2 **properties of a mutator**
59
what is **dynamic type checking**
this is carried out at run time by java and checks on the compatiblity of types (ie adding a string to a boolean)
60
what is the scope of **formal parameters**
these have a scope within the body of their method or constructor.
61
what is the scope of **instance variables (fields)**
these have a scope of the body of their class and so can be accessed from anywhere in the class
62
compnents of this are: 1. variable 2. assignment operator 3. an expression or value example: value += 1
what 3 componets make up an **assignment statement**
63
the syntax for this is: System.out.println(value);
print to the console or standard output and start a new line
64
constructors cannot contain a return statement wheras a method can
regarding methods and constructors which can have a return statement
65
what can be present **within the methodsbody/block**
within this there can be: 1. declarations 2. statements
66
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
regarding constructors and methods when can they be used
67
lifetime begins when its method is called and it lasts until the method’s execution ends.
what is the lifetime of **formal parameters**
68
describe a **method**
define the behaviour of an object and perform some kind of functionality
69
this component of a class is contained within the braces and contains the classes: * fields * constructor * methods
describe the **body** of a class
70
an expression that will evaluate to a numerical value
what is a **arithmetic expression**
71
name the 3 components that make up the syntax for a field
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
called only on the creation of an object and ensures an object is set up correctly when created
describe a **constructor**
73
describe a **formal parameter**
This is also called the parameter and is the declaration of a parameter that is part of the method or constructors header
74
what is the lifetime of **formal parameters**
lifetime begins when its method is called and it lasts until the method’s execution ends.
75
describe a **mutator**
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
how will a skeleton class look
a skeleton of this is as follows: Public class ClassName { Fields Constructors methods }
77
these include 1.**Header** 2.**Body**
what are the two components of a **class**
78
this is giving a variable a value for the first time
describe the process of **initialising a variable**
79
regarding constructors and methods when can they be used
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
what is a **class wrapper**
is simply a class header followed by a pair of empty braces
81
regarding methods and constructors which can have a return statement
constructors cannot contain a return statement wheras a method can
82
these include: 1.Mutator method 2.Set method 3.Mutator 4.Setter
give 4 names that a **mutator** may be called
83
a skeleton of this is as follows: Public class ClassName { Fields Constructors methods }
how will a skeleton class look
84
the lifetime begins when its object is created and it lasts until its object is destroyed.
what is the **lifetime of instance variables (fields)**
85
what is the **scope of a local variable**
have a scope from where they are declared until the end of their enclosing block of code.
86
what does it mean if an **instance variable (field) is defined as private**
if an instance variable is set to this then it cannot be directly accessed from outside its class
87
these include: 1.instance variables (Fields) 2.Formal parameters 3.Local variables
what are the three types of variables in java
88
name 2 **properties of a mutator**
properties include: 1.Usually does not return any data 2.May be prefixed with the word "set" to highlight its role
89
describe a **constructor**
called only on the creation of an object and ensures an object is set up correctly when created
90
whats the syntax for the string method that **returns a new string from begin index to end index -1**
syntax is: **String.substring(beginIndex, endIndex);**
91
what is the **lifetime of instance variables (fields)**
the lifetime begins when its object is created and it lasts until its object is destroyed.
92
give 4 names that a **mutator** may be called
these include: 1.Mutator method 2.Set method 3.Mutator 4.Setter
93
if on operand is an integer and the other operand is a float what data type will the result be
in this case the result will be converted to a double
94
describe the **header** of a class
this component of a class comes before the braces and its main role is to supply a name for the class
95
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
name 3 properties of **accessors**
96
give two notes regarding **local variables**
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
describe an **actual parameter**
Also known as the argument is the external value that is passed to the method or constructors formal parameter
98
this will always have a return statement that returns data of the same type specified in the method header
a **method containing a return type** in the header will always consist of what inside the body
99
what is a **compound assignment operator**
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
syntax is: **String.substring(beginIndex, endIndex);**
whats the syntax for the string method that **returns a new string from begin index to end index -1**
101
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)
describe the two operations of the **plus (+) opertaor**
102
lifetime begins after its declaration is executed and it lasts until the program flow moves outside of the variable’s enclosing block of code.
what is the **lifetime of a local variable**
103
what is an **assignment statement**
this is where we give a variable a value to hold this can occur: 1. at intitalisation 2. after initialisation
104
in this case the result will be converted to a double
if on operand is an integer and the other operand is a float what data type will the result be
105
this is carried out at run time by java and checks on the compatiblity of types (ie adding a string to a boolean)
what is **dynamic type checking**
106
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;
name the 3 components that make up the syntax for a field
107
describe the **body** of a class
this component of a class is contained within the braces and contains the classes: * fields * constructor * methods
108
this is a local variable used to create additional and temporary variable space
describe a **declaration** within a method
109
what are the two components of a **class**
these include 1.**Header** 2.**Body**
110
what is an **operand**
a value that can be used with an operator
111
what is a **binary operator**
these are operators that have two operands. Examples would be subtract or add
112
define the behaviour of an object and perform some kind of functionality
describe a **method**
113
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
describe the 3 steps that **create a usable variable**
114
these are operators that have only one operand. Exampless include ++ and -- which increment or decrement their operands by one
what is a **unary operator**
115
describe the process of **declaring a variable**
this is specifying the type and name of the variable
116
what is the **lifetime of a local variable**
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
this asseses a condition and then takes one of two actions depending on the outcome of the condition
what is a **conditional statement**
118
print to the console or standard output and start a new line
the syntax for this is: System.out.println(value);
119
what is a **conditional statement**
this asseses a condition and then takes one of two actions depending on the outcome of the condition
120
what is a **unary operator**
these are operators that have only one operand. Exampless include ++ and -- which increment or decrement their operands by one
121
have a scope from where they are declared until the end of their enclosing block of code.
what is the **scope of a local variable**
122
ignore
[chapter 2 quiz](https://learn2.open.ac.uk/mod/quiz/view.php?id=2014890)
123
what is an **operator**
is a symbol that represents an operation that it can perform on either one or more operands
124
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 }
what is the syntax for a java **if else statement**
125
regarding methods and constructors which contain a return type in their header
A constructor’s header does not declare a return type, whereas a method’s header does.
126
describe the process of **initialising a variable**
this is giving a variable a value for the first time