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