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