Chapter 3 - Object interaction Flashcards
The result can never be higher than the right operand
what is the maximum value a modulo expression can evaluate to
what is a
class type
this is a non-primitive data type that is defined by a class
remember
Variables can hold objects. in this case when we declare the variable then its type will be the class of the object
- These will show the classes in the program and the relationship between them.
- This view is static since all classes and their relationships are defined in the source code and will be part of the compiled program
describe a
class diagram
describe
modularization
this breaks the problem into its fundamental parts. from here we may look closely at there details and may even perform even further modularization
example
(car can be modularized to wheels, engine, body. the engine may be further modularized into pistons, spark plugs, etc)
in two steps how can we
solve a problem domain
- break the problem down into its components (abstraction)
- solve the details of those components (modularization)
- this will show the objects and their relationships.
- This is a dynamic view since objects can be created, destroyed and modified during runtime
- and so we can only ever catch a snapshot of the view
describe an
object diagram
describe the meaning of
name overloading
this is where we have used the same variable name twice and in such a way that they conflict, In general when this occurs the definition from the closest enclosing block is used
what two things does the keyword
new
do
this will
1.It creates a new object of the named class
2.It calls the constructor of that class
- symbol: &&
- function: A && B - if A AND B are true the result is true
describe the java boolean operator
AND
this can be used in situations where we have a name conflict known as name overload
Example:
Field
String a;
Constructor
Public constructor (string a)
{
a = a
}
// we are setting the formal parameter a to the formal parameter a
This.a = a
// we are setting the field a to the formal parameter a
in what situation would the use of the
**this keyword **
be useful
- symbol: %
- function: It has two operands and its result is the remainder after the left operand is divided by the right operand
- examples
15 % 4 = 3 because 4 goes into 15 3 times with a remainder of 3
4 % 15 = 4 because 4 cannot be divided by 15 and so 4 is the remainder
describe the java
modulo
operator
describe an
object diagram
- this will show the objects and their relationships.
- This is a dynamic view since objects can be created, destroyed and modified during runtime
- and so we can only ever catch a snapshot of the view
This is when a method of an object is called from outside the object and will use a qualified name to make the call
describe an
external method call
used to make external method calls and consists of simple names separated by dots (dot notation)
what is a
qualified name
desribe the technicality of the java modulo operator
Technically the java modulo operator is a remainder operator.
usually this does not matter but in the case of negative numbers it does (this will vary between programming languages)
- Remainder operator (java) - the result is negative only if the dividend is negative (the thing being divided I.e the left operand)
- Traditional modulo - the result has the same sign as the divisor (thing dividing by I.e the left operand)
name a situation where use of the
modulo operator
would be desired
This is useful to use in situations where we wish to roll over a number that has a limit instead of using conditions
describe the java
modulo
operator
- symbol: %
- function: It has two operands and its result is the remainder after the left operand is divided by the right operand
- examples
15 % 4 = 3 because 4 goes into 15 3 times with a remainder of 3
4 % 15 = 4 because 4 cannot be divided by 15 and so 4 is the remainder
what is the
syntax for the keyword new
Syntax
New ClassName(parameters)
describe an
“anonymous” object
this is an object that we have lost all references to
example:
Var1 = object1 // var1 holds a reference to object 1
Var2 = object2 // var2 holds a reference to object 2
Var1 = var2 // var1 is assigned the value of var2
Var1 = object2 // and so var1 holds a reference to object 2
Var2 = object2 // var2 maintains a reference to object 2
describe why
**String.equals() **
should be used over == when comparing strings
When comparing two strings this should be used this is because
1.The == operator will compare whether two object references are pointing to the same object
2.The string.equals() checks whether the contents or state of the object match
this breaks the problem into its fundamental parts. from here we may look closely at there details and may even perform even further modularization
example
(car can be modularized to wheels, engine, body. the engine may be further modularized into pistons, spark plugs, etc)
describe
modularization
what is a
simple name
used to make internal method calls and consists of a unique identifier
the syntax for this type of call is
methodName(parameters)
what is the
syntax for an internal method call
This is useful so that an object can be initialised in different ways or perhaps a method can carry out the same task but on different data types.
describe why
overloading is useful
describe the keyword
this
a keyword that is used as a self reference to the object it is being used in
describe
abstraction
this is the idea of ignoring the details of parts of the problem and look at them from a higher level
example
(a car engine is made up of thousands of parts but with abstraction we can ignore the details and say that we have an engine the details are not important for the higher level view)
describe the java boolean operator
OR
- symbol: ||
- function: A || B - if A OR B is true then the result is true
describe the java boolean operator
AND
- symbol: &&
- function: A && B - if A AND B are true the result is true
this is where we have used the same variable name twice and in such a way that they conflict, In general when this occurs the definition from the closest enclosing block is used
describe the meaning of
name overloading
describe the java boolean operator
NOT
- symbol: !
- function: !A - will flip the boolean A to its opposite
Syntax
New ClassName(parameters)
what is the
syntax for the keyword new
if this case occurs the compiler will match the signature of the call with the signature of the method or constructor
when the match is found it is then used
how does a compiler tell which overloaded constructor or method should be used
how does a compiler tell which overloaded constructor or method should be used
if this case occurs the compiler will match the signature of the call with the signature of the method or constructor
when the match is found it is then used
in what situation would the use of the
**this keyword **
be useful
this can be used in situations where we have a name conflict known as name overload
Example:
Field
String a;
Constructor
Public constructor (string a)
{
a = a
}
// we are setting the formal parameter a to the formal parameter a
This.a = a
// we are setting the field a to the formal parameter a
describe the java keyword
new
this is a keyword that is used to explicitly create objects
what is a
qualified name
used to make external method calls and consists of simple names separated by dots (dot notation)
this will
1.It creates a new object of the named class
2.It calls the constructor of that class
what two things does the keyword
new
do
When comparing two strings this should be used this is because
1.The == operator will compare whether two object references are pointing to the same object
2.The string.equals() checks whether the contents or state of the object match
describe why
**String.equals() **
should be used over == when comparing strings
what is the
syntax for an internal method call
the syntax for this type of call is
methodName(parameters)
describe
overloading
this is where a class contains a constructor or method name that is used more than once.
Technically the java modulo operator is a remainder operator.
usually this does not matter but in the case of negative numbers it does (this will vary between programming languages)
- Remainder operator (java) - the result is negative only if the dividend is negative (the thing being divided I.e the left operand)
- Traditional modulo - the result has the same sign as the divisor (thing dividing by I.e the left operand)
desribe the technicality of the java modulo operator
this is a non-primitive data type that is defined by a class
remember
Variables can hold objects. in this case when we declare the variable then its type will be the class of the object
what is a
class type
what is the maximum value a modulo expression can evaluate to
The result can never be higher than the right operand
this is an operator that works with boolean values and will produce a new boolean value depending upon the conditions
what is a
logical operator
the syntax for this type of call is:
Object.methodName(parameters)
describe the
synatx for an external method call
ignore
describe an
internal method call
This is when an object calls its own methods and will use a simple name to make the call
describe why
overloading is useful
This is useful so that an object can be initialised in different ways or perhaps a method can carry out the same task but on different data types.
This is useful to use in situations where we wish to roll over a number that has a limit instead of using conditions
name a situation where use of the
modulo operator
would be desired
- break the problem down into its components (abstraction)
- solve the details of those components (modularization)
in two steps how can we
solve a problem domain
what is a
logical operator
this is an operator that works with boolean values and will produce a new boolean value depending upon the conditions
describe the difference between
variables that hold primitive data types
VS
variables that hold class types
the difference here is that:
1. A variable that holds a primitive data type will always hold that actual value
2. A variable that holds a class type only ever holds a reference to the object. Not the actual object.
ignore
This is when an object calls its own methods and will use a simple name to make the call
describe an
internal method call
- symbol: ||
- function: A || B - if A OR B is true then the result is true
describe the java boolean operator
OR
describe an
external method call
This is when a method of an object is called from outside the object and will use a qualified name to make the call
this is where a class contains a constructor or method name that is used more than once.
describe
overloading
used to make internal method calls and consists of a unique identifier
what is a
simple name
describe a
class diagram
- These will show the classes in the program and the relationship between them.
- This view is static since all classes and their relationships are defined in the source code and will be part of the compiled program
describe the
synatx for an external method call
the syntax for this type of call is:
Object.methodName(parameters)
this is an object that we have lost all references to
example:
Var1 = object1 // var1 holds a reference to object 1
Var2 = object2 // var2 holds a reference to object 2
Var1 = var2 // var1 is assigned the value of var2
Var1 = object2 // and so var1 holds a reference to object 2
Var2 = object2 // var2 maintains a reference to object 2
describe an
“anonymous” object
the difference here is that:
1. A variable that holds a primitive data type will always hold that actual value
2. A variable that holds a class type only ever holds a reference to the object. Not the actual object.
describe the difference between
variables that hold primitive data types
VS
variables that hold class types
a keyword that is used as a self reference to the object it is being used in
describe the keyword
this
- symbol: !
- function: !A - will flip the boolean A to its opposite
describe the java boolean operator
NOT
this is the idea of ignoring the details of parts of the problem and look at them from a higher level
example
(a car engine is made up of thousands of parts but with abstraction we can ignore the details and say that we have an engine the details are not important for the higher level view)
describe
abstraction
this is a keyword that is used to explicitly create objects
describe the java keyword
new