Queue queue = new PriorityQueue<>() creates new priority queue. .add(E e) adds e to front of queue. .remove() removes last element from queue.
Optionals We can also reduce without an identity element, returning an Optional:
.poll() retrieves and removes head of queue, returns null if empty. .peek() retrieves head of queue, returns null if empty.
.isPresent() returns whether object is present. .get() returns value if present, else throws exception.
Deques Deque deque = new ArrayDeque<>() queue.
.orElse(T alternative) returns value if present, else alternative.
creates
new
.reduce(f). Now if steam is empty, an empty Optional is returned.
double-ended
1.8
Can use methods above at first or last element. E.g. pollFirst() and pollLast().
Random
Random generator = new Random() creates new Random object.
Can use stack methods push(E e), pop() and peek().
.nextInt(n) returns random int in range [0..n).
2
2
Object-Oriented Programming in Java
2.1
Apparent and Actual Types Consider Shape circle = new Circle(). Has apparent type Shape but actual type Circle. Only methods and fields from apparent type (Shape) are available, but methods are implimented by actual type (Circle).
Types
Definition Creation Initialisation Usage Content
Primitive Types
Reference Types
built-in literals default (e.g. 0) operators (e.g. +, *) value
class definition new null or constructor methods pointer to an object
2.4
Inheritance
1. A subclass (extends a superclass) inherits all fields and methods from it’s superclass, can also override / add additional functionality. 2. protected visibility in superclass allows access to its fields / methods from a subclass (also accessible anywhere within package). super
Should try to make objects immutable as much as possible - using the keyword final.
2.2
1. Can call superclass constructur using super() (called implicitly if no other constructor provided). 2. Can call superclass method method from subclass using super.method().
Classes
Contain fields, constructor, methods.
abstract 1. Used to define class which cannot be instantiated.
Fields
2. abstract methods have no body, needs to be overriden by subclass.
1. Constants: should be final (cannot change) and static (one per class, not one per object). Typically public (accessible from anywhere).
3. Style: usually a class extends an abstract class (with constructor and fields) which implements an interface (caters for case where abstract class is too specific).
2. Non-constants: should be private (accessible only from within class).
final Methods public methods should provide service to class users. private methods support methods in the class.
1. Methods which are final cannot be overriden. 2. Classes which are final cannot be extended.
2.3
Interfaces
2.5
Casting
1. Can define method signatures (implicity public): describe required capabilities of a class that implements the interface.
1. Upcasting: cast from subclass to superclass. Done automatically, cannot fail.
2. Can define default methods in interface (can be overriden in implementing classes).
2. Downcasting: cast from superclass to subclass. E.g. for Shape shape, define Circle circle = (Circle)shape. Narrow apparent class so you can call certain methods / access certain fields. 3. Downcasting can lead to a ClassCastException. We can avoid this by using the instanceOf keyword to determine the actual type.
3. Can define constant fields. Implementing Interfaces Use notation: @Override when a class method implements an interface method.
4. Style: instanceOf can indicate poor design. Often better to use subclass methods. 3
2.6
Object Equality
2.8
Object implements equals based on identity. Often we want it to compare field contents:
Functional Interfaces
1. Annotated by @FunctionalInterface.
1. We @Override the method public boolean equals(Object other).
2. Declares exactly one (abstract) method. E.g. Comparator {int compare(T o1, T o2);}.
2. Start by handling standard object equality cases (== and null).
3. Sort list using void .sort(Comparator c).
3. Check incoming object appropriate type, then downcast.
4. Means we can write strings.sort((a, b) -> a.compareTo(b)) since this provides the single method required by Comparator.
4. Compare fields. We must also override public int hashCode().
2.9
Singleton Pattern
1. Must return same value when equals returns true.
Only allows one instance to be created:
2. Should tend to return different values for objects which are not equal.
public class OnlyOne { private static OnlyOne instance ; private onlyOne () {} public static OnlyOne getInstance () { if ( instance == null ) { instance = new OnlyOne (); } return instance ; } }
Reference Sheet for CO120.2 Programming II - GitHub
Implementing Interfaces Use notation: @Override when a class method im- ... Style: usually a class extends an abstract class (with constructor and fields).
GBB. B dËrief en enum type thât represents flâgs for renderingF. B. B iââ¢h Ëit represents â different flâgF â¦se Ëitwise ând. B to â¢heâ¢k if â flâg is setF. BG enum renderâ¢flâg {. GBB âhe âmËient flâg @Ëit HAF BG
Connected: there is a path joining any two nodes. .... and merge two components .... Merge sort can be parallelised by executing recursive calls in parallel. 2.
will shut down, requiring a cool-down period before it ... 10 Fuel Scoop ... V2 & Creative Commons License: BY - NC - SA 3.0 Oolite Website: http:/www. ..... A discontinued fighter design finding a new life in the professional racing circuit.
Free Variable Variable which is not bound (this includes variables which do not appear in A!). Sentence Formula with no free variables. ... domain of M, dom (M).
Page 1 ... We might be able to make a considerable simplification by considering max- terms (0s) instead of minterms. ⢠Don't cares (X) can ... Noise Margin. Fan out The number of inputs to which the output of a gate is connected. ⢠Since 1. R.
create table actor_cars ( .... Table. Relational Expression. Views. Tuple. Row. Attribute. Column. Domain .... end of free space, location and size of each record.
Stops execution and displays error message. 9 Types and Common ... multiple times or to clean up code. ... You should spend time planning your answer (on ...
Products For arbitrary sets A and B: 1. Ordered ... Identity idA = {ãx, yã â A2|x = y}. Composition .... Identity: The function idA : A â A is defined as idA (a) = a. 3.
General Technique: For any P ⊆ Z and any m : Z: P (m) ∧ ∀k ≥ m. [P (k) → P (k + 1)] → ∀n ≥ m.P (n). 1.2 Strong Induction. P (0) ∧ ∀k : N. [∀j ∈ {0..k} .
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Location ...
new: test: added a bunch of test around user usability of feature X. fix: typo in spelling my name in comment. !minor. By Delqvs cheatography.com/delqvs/. Published 14th August, 2017. Last updated 14th August, 2017. Page 1 of 1. Sponsored by ApolloPa
for data that couldn't be stored in TCP send buffer ... packet (wasting packets during slow start!) â overhead of TLS header & HTTP frame becomes bigger. 5 ...
for the simulation of the electron cloud buildup in particle accelerators. 1 Input files .... points of the longitudinal beam profile of sec- ondary beams.
To monitor various informations of your NetBSD box you ... ifconfig_if assigns an IP or other on that network in- ... pkg_admin fetch-pkg-vulnerabilities download.
Jan 16, 2018 - The second you can only catch by thorough testing (see the HW). 5. Don't use magic numbers. 6. Use meaningful names. Don't do this: data("ChickWeight") out = lm(weight~Time+Chick+Diet, data=ChickWeight). 7. Comment things that aren't c
get lost in the middle way of the derivation process. This cheat sheet ... 3. 2.2. A brief review of probability theory . . . . 3. 2.2.1. Basic concepts . . . . . . . . . . . . . . 3 ...... pdf of standard normal Ï ... call it classifier) or a decis
application. After installing the icestorm tools, you can .... The SwapForth shell is a Python program that runs on the host PC. It has a number of advantages over ...
If the UART is enabled, it causes a data frame to start transmitting with the parameters indicated in the. UARTLCRH register. Data continues to be transmitted ...
Word, or RTF documents; html or pdf based slides ... stop render when errors occur (FALSE) (default = FALSE) .... colortheme. Beamer color theme to use. X css.
Jan 27, 2012 - 171 is perfect for mobile wireless applications such as asset monitoring ... development of your application. ... sensor data to a web server.