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)