Please enable JavaScript.
Coggle requires JavaScript to display documents.
M250 - Coggle Diagram
M250
Random Ideas
A class should have:
- constructor
- setter methods
- getter methods
To declare a field, its when you first say that such a variable actually exists and is usually done first, at the start of a class.
To initialise a /fieldvariable mean to assign a value to it and is usually done in the constructor part of a class.
To go one directory up, use "../[filename]"
ERRORS
cost = item.discount() - "void cannot be converted to double" - The discount method was found to not return anything, it was a setter method and therefore had void return. Hence, setting a variable to have such a method results in a variable that has void.
ConcurrentModificationException - This happens if we try to remove an item from a collection while using a for-each loop
-
NULL
-
method calls cannot be made on variables that do not reference objects. Hence, on variables which reference null.
ANNONYMOUS OBJECT
An object without a name because if a variable name were given, it would not be used for much. The usage of the variable would be short lived.
E.g. Bid bid = lot.getHighestBid();
Person bidder = bid.getBidder();
String name = bidder.getName();
System.out.println(name);
Here you can see that the variable 'bid' is almost immediately used. And in this example, it won't be used again. So, to save time, chain method calls is better.
E.g. System.out.println(lot.getHighestBid().getBidder().getName());
CONVENTIONS
Boolean variables are usually named to reflect their true state. E.g. the variable 'isComplete' would be initialised to have a value of 'true' if the thing really is complete. The variable name and the value should make sense.
-
SOME SYNTAX
'boolean add(E o)' is used in documentation to indicate what elements can be added to an ArrayList. In this case, elements of type 'E' can be added. Real example: boolean add(String o) means elements of type String can be added.
E get(int index) is used in documentation to indicate which type of elements can be returned from an ArrayList. In this case 'E' elements can be returned. REal example: String get(int index) means that String will be returned.
Import Statements: 'import package-name.class-name' Real example: java.util.Random. In this example, java.util is the package name. Putting a '*' instead of a class-name will import all classes from that package.
-
CH3: Object Interaction
-
OBJECT DIAGRAMS
static view: shows classes (aka class diagram)
dynamic view: shows objects at runtime.
TYPES
PRIMITIVE
predefined by java, include int, boolean, etc
-
OBJECT
-
not stored in variable, instead reference to object is stored.
OPERATOR
De Morgan's Laws
In Java we can say that the following conditions are equivalent
- ! (A || B) is the same as ! A && ! B
- ! (A && B) is the same as ! A || ! B
-
-
-
METHOD CALLS
Internal method call
-
You can use "self.methodName" where self means this object. Or you can just name the method directly without "self"
-
-
-
-
PREQUEL
-
Object Technology
Procedural programming: step-by-step.
Has a main program that contains further, smaller programs like functions.
Problem can be that this method relies on data structures, which if changed, could result in a need to change all the functions of the entire program.
-
JAVA
Java Development Kit (JDK), Private. Will be used in this module.
-
-
Ch4: Grouping Objects
COLLECTIONS
A collection is a bunch of objects grouped together. OR
A data structure that allows us to store references to multiple objects and perform operations with them.
Like a group of students, the course one student is taking, etc.
Operations can be done to the collection, like sorting in some way, reducing it, etc.
-
LOOPS
-
-
while loop
-
-
More complex to code than a for each loop because you have to make your own counter, and each element in a list needs to be extracted.
-
Benefits: (1) does not need to run on a collection. (2) does not need to process every item in a collection.
-
Iterator
There is the Iterator class/interface, and there is the iterator (small 'i') method that belongs to the ArrayList class.
Using the iterator method on ArrayList will produce an Iterator object that has 4 methods, 2 of which are hasNext() and next(), both of which have non-void return types.
pseudo-code:
[FIRST, create the Iterator object]
Iterator<ElementType> it = myCollection.iterator();
[THEN, use a while loop to use it]
while(it.hasNext()) {
call it.next() to get the next element
do something with that element
}
-
Possible to remove items in the collection with this method. Only the last item retrieved from the Iterator's next method can be removed.
-
-