Chapter 2 - Understanding class definitions Flashcards
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
give two notes regarding
local variables
the syntax for this is:
System.out.print(value);
print to the console or standard output but do not start a new line
describe the 2 steps that
create a usable variable
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
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
what are
identifiers
what is the syntax for a java
if else statement
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
}
whats the syntax for the string method that
returns the number of characters in the string
syntax is:
String.length();
a constructor must share the same name as its class whereas a method can be given any unique name
regarding methods and constructors
how are they named
a
method containing a return type
in the header will always consist of what inside the body
this will always have a return statement that returns data of the same type specified in the method header
what are the three types of variables in java
these include:
1.instance variables (Fields)
2.Formal parameters
3.Local variables
describe a
declaration
within a method
this is a local variable used to create additional and temporary variable space
what is a
arithmetic expression
an expression that will evaluate to a numerical value
if an instance variable is set to this then it cannot be directly accessed from outside its class
what does it mean if an
instance variable (field) is defined as private
Also known as the argument is the external value that is passed to the method or constructors formal parameter
describe an
actual parameter
within this there can be:
1. declarations
2. statements
what can be present
within the methodsbody/block
this is done by the java compiler and it checks that variables hold values that match there type
what is
static type checking
this is as follows:
access_modifier return_type method_name(parameters):
{
body
}
what is the
syntax of a java method
what is
static type checking
this is done by the java compiler and it checks that variables hold values that match there type
- Can be declared within a method or constructor
- are not given a default value, so you must initialise them before trying to use them.
how are
local variables initialised
a value that can be used with an operator
what is an
operand
what 4 names may an
accessor
be called
this may be called
1.Accessor methods
2.Accessors
3.Get methods
4.getter
describe the two operations of the
plus (+) opertaor
- 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 a
statement
within a method
within a method this is used to describe and carry out operations
these are methods that retrieve information from the objects fields and returns the information to the caller
what is an
accessor
give 3 points about java
Keywords/reserved words
- in java there are about 50 of these
- these are always written in lower case
- these can only be used by the language, a user cannot use these when setting identifiers
within a method this is used to describe and carry out operations
describe a
statement
within a method
this is specifying the type and name of the variable
describe the process of
declaring a variable
these are operators that have two operands. Examples would be subtract or add
what is a
binary operator
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
- declared within the class but outside of a constructor or method
- 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)
how are
local variables initialised
- Can be declared within a method or constructor
- are not given a default value, so you must initialise them before trying to use them.
is simply a class header followed by a pair of empty braces
what is a
class wrapper
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
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
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
syntax is:
String.length();
whats the syntax for the string method that
returns the number of characters in the string
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
what is the
syntax of a java method
this is as follows:
access_modifier return_type method_name(parameters):
{
body
}
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
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
this may be called
1.Accessor methods
2.Accessors
3.Get methods
4.getter
what 4 names may an
accessor
be called
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
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)
- in java there are about 50 of these
- these are always written in lower case
- these can only be used by the language, a user cannot use these when setting identifiers
give 3 points about java
Keywords/reserved words
these have a scope within the body of their method or constructor.
what is the scope of
formal parameters
what is an
accessor
these are methods that retrieve information from the objects fields and returns the information to the caller
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
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.
what is a
boolean expression
this is an expression that will evaluate to either true or false
is a symbol that represents an operation that it can perform on either one or more operands
what is an
operator
describe the
initialisation of instance variables (fields)
- declared within the class but outside of a constructor or method
- if it is not initialised it will be given a default value (best practice is to always initialise these using the constructor)
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
print to the console or standard output but do not start a new line
the syntax for this is:
System.out.print(value);
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
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
this is an expression that will evaluate to either true or false
what is a
boolean expression
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
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
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)
what is the scope of
formal parameters
these have a scope within the body of their method or constructor.
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
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
the syntax for this is:
System.out.println(value);
print to the console or standard output and start a new line
constructors cannot contain a return statement wheras a method can
regarding methods and constructors
which can have a return statement
what can be present
within the methodsbody/block
within this there can be:
1. declarations
2. statements
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
lifetime begins when its method is called and it lasts until the method’s execution ends.
what is the lifetime of
formal parameters
describe a
method
define the behaviour of an object and perform some kind of functionality
this component of a class is contained within the braces and contains the classes:
* fields
* constructor
* methods
describe the
body
of a class
an expression that will evaluate to a numerical value
what is a
arithmetic expression
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;
called only on the creation of an object and ensures an object is set up correctly when created
describe a
constructor
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
what is the lifetime of
formal parameters
lifetime begins when its method is called and it lasts until the method’s execution ends.
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
how will a skeleton class look
a skeleton of this is as follows:
Public class ClassName
{
Fields
Constructors
methods
}
these include
1.Header
2.Body
what are the two components of a
class
this is giving a variable a value for the first time
describe the process of
initialising a variable
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
what is a
class wrapper
is simply a class header followed by a pair of empty braces
regarding methods and constructors
which can have a return statement
constructors cannot contain a return statement wheras a method can
these include:
1.Mutator method
2.Set method
3.Mutator
4.Setter
give 4 names that a
mutator
may be called
a skeleton of this is as follows:
Public class ClassName
{
Fields
Constructors
methods
}
how will a skeleton class look
the lifetime begins when its object is created and it lasts until its object is destroyed.
what is the
lifetime of instance variables (fields)
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.
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
these include:
1.instance variables (Fields)
2.Formal parameters
3.Local variables
what are the three types of variables in java
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
describe a
constructor
called only on the creation of an object and ensures an object is set up correctly when created
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);
what is the
lifetime of instance variables (fields)
the lifetime begins when its object is created and it lasts until its object is destroyed.
give 4 names that a
mutator
may be called
these include:
1.Mutator method
2.Set method
3.Mutator
4.Setter
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
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
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
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
describe an
actual parameter
Also known as the argument is the external value that is passed to the method or constructors formal parameter
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
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;
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
- 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
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
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
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
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
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
describe the
body
of a class
this component of a class is contained within the braces and contains the classes:
* fields
* constructor
* methods
this is a local variable used to create additional and temporary variable space
describe a
declaration
within a method
what are the two components of a
class
these include
1.Header
2.Body
what is an
operand
a value that can be used with an operator
what is a
binary operator
these are operators that have two operands. Examples would be subtract or add
define the behaviour of an object and perform some kind of functionality
describe a
method
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
these are operators that have only one operand. Exampless include ++ and – which increment or decrement their operands by one
what is a
unary operator
describe the process of
declaring a variable
this is specifying the type and name of the variable
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.
this asseses a condition and then takes one of two actions depending on the outcome of the condition
what is a
conditional statement
print to the console or standard output and start a new line
the syntax for this is:
System.out.println(value);
what is a
conditional statement
this asseses a condition and then takes one of two actions depending on the outcome of the condition
what is a
unary operator
these are operators that have only one operand. Exampless include ++ and – which increment or decrement their operands by one
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
ignore
what is an
operator
is a symbol that represents an operation that it can perform on either one or more operands
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
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.
describe the process of
initialising a variable
this is giving a variable a value for the first time