Object Oriented Programming 2 Flashcards

1
Q

Rich API support

A

Doing / learning networking, parallelism, graphics, GUI, algorithms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is java platform independent

A

It runs in a virtual machine: JVM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why learn Java?

A

Active development, many jobs, platform indep, tools (networking, …)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Java and Distributed Systems

A

Socket communication, thread management, object serialization, remote method invocations, servlets, applets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Java compilation

A

Programm compiled into bytecode, which the JVM executes at runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Object

A

Combines methods (behaviour) and data (state),
hide complexity, modularization, modelling of domain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are objects defined

A

throught the keyword “class”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“volatile”

A

ensures visiblity accross threads, safe to use across threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Interface

A

Defines a group of methods, classes implement them to provide functionailty, implementation enforced at compilation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

static nested classes

A

no access to outer members, to hide access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Named constants

A

entirely in uppercase with underscore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Creation of Arrays:

A

anArray = new int[10];
float[] anArrayOfFloats;
int[] anArray = {
100, 200, 300,
400, 500, 600,
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Casting

A

Cast allows access to specific object
methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Defensive copies

A

gainst outside failures, ill-behaved clients, or attacks
also for getters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

varargs

A

represent zero or
more arguments of a specified type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Parallelism (concurrency)

A

one computer that does multitasking, real (processors) or pseudo (threads)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Distributed system

A

Networked components, coordinated by messages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Server threads

A

within server process; handle concurrent user requests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Server processes

A

handle different types of access
(e.g., web, mail, file, …)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Remote Invocation

A

Client invocation and server result
RPC (remote procedure call) or RMI (remote method invocation)
Requires defined messaging protocoL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Server State:

A

 Stateful (client tables)
 Soft state (for given time)
 Session state (for session)
 Stateless

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Thread-based Connection Abstraction

A

incoming request -> accepted by dispatcher thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Threaded Server Design Patterns

A

Fix or dynamic number of threads
Re-usage of threads: thread pool (created at start), non active threads kept in pool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Thread per Request

A

dispatcher reveives request, for each a thread is created or assigned from pool
Worker thread:  Read request
 Process request
 Answer request
 End

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Thread per Connection
Dispatcher Thread assigns client to thread Worker thread  Read request  Process request  Answer request  Wait for next assignment or return to pool (if client closes connection)
26
Thread per Service-Object
Each service-object provides  An own thread  An own queue Dispatcher assigns request to service object queue Service object thread reads from queue and processes -> queue serialization
27
Java Threads
JVM runs as a process on the operating system JVM runs several threads (garbage collector, ...) Java.lang.Thread objects are placed into own threads "run()" must be overridden
28
DON’T use Thread.sleep() for synchronization
Exact time when thread will be resumed is difficult to predict: sequence and duration of thread execution varies, and may vary for different runs
29
Interface Runnable
Alternative to using run on objects derived from Thread
30
Synchronization
shared data, execution order ofter hard to predict without controls, we cannot predict thread switch
31
Synchronization methods are needed
data consistency (data correctness) maintain parallelism
32
synchronized keyword
locks an object, if a thread encounters it and it is locked, thread is put to sleep try to synchronize specific variables
33
End of Java Thread
join(): blocks until a thread ends yield(): increase probability to switch to another thread
34
Inside synchronized
wait() → blocks a calling Object until it gets notified that it can resume notify() → unblocks waiting caller notifyAll() → unblocks all waiting callers
35
JavaFX
Stage: window Scene: container to fill a stage
36
Observers in JavaFX
implements the interface EventHandler
37
Properties in JavaFX
Classes which implement the observer model They can be observed contains: values, methods to register observers, methods to update and read the observed value Informs all registered observers
38
JavaFX Bindings
Mechanisms to couple properties -> Change of one property changes another property (uni or bidirectional)
39
JavaFX Collections
You can register observers to collections They are notified on changes to the collection Interfaces ObservableList, ObservableMap, ObservableSet
40
JavaFX Elements
"Node" is the basic element Pane derives from Node and is basis for all container classes
41
Container Classes derived from Pane
* VBox: Vertical layout * HBox: Horizontal layout * FlowPane: Line by line layout * BorderPane: top/bottom/left/right/center * StackPane: on top layout * TilePane: uniform grid layout * GridPane: variable grid layout * AnchorPane: anchor to border
42
JavaFX Interaction Elements
Control class derived from Node Labels, Buttons, Lists, Pickers, Slider, Text Input
43
JavaFX Other functions
Automatization: Stylesheet support, UI definitions from FXML files Multi-windows UIs Web and media support
44
JavaFX MVP
Model  Application logic (data and methods)  Independent of GUI View  GUI component creation and manipulation  Different views may represent parts of the model Presenter  Flow control  Triggered by UI interaction and using/manipulating model
45
JavaFX Problems in Event Processing
Certain action on an Event may take long time. No other events are processed during this time, so no window update happens. Solution: Aim for short duration in event handling, use Threading for event handling Submit the update to the event queue of the JavaFX Application thread using Platform.runLater()
46
Interface Worker
 Observe state  Possibility to cancel
47
Class Task
Implement a single long running task * message (ReadOnlyStringProperty) * title (ReadOnlyStringProperty) * value (ReadonlyObjectProperty) * workDone (ReadOnlyDoubleProperty) * State (ReadonlyObjectProperty)
48
class Service
Implement repeating tasks
49
Class ScheduledService
Schedule of repeating tasks, coordination via properties
50
8 Golden Rules GUI/Application Design (Ben Shneiderman)
1. Strive for consistency. 2. Enable frequent users to use shortcuts. 3. Offer informative feedback. 4. Design dialog to yield closure. 5. Offer simple error handling. 6. Permit easy reversal of actions. 7. Support internal locus of control. 8. Reduce short-term memory load.
51
Wired Network types:
* PAN: Personal Area Network (USB) * LAN: Local Area Network (Ethernet) * MAN: Metropolitan Area Network (DSL) * WAN: Wide Area Network (IP Routing)
52
Wireless Network types:
* WPAN (Bluetooth) * WLAN (Wifi (IEEE 802.11)) * WMAN (WiMAX (IEEE 802.16)) * WWAN (GSM; UMTS; LTE, 5G)
53
Circuit Switching:
“plain old” telephone system
54
Packet Switching
compute shortest path, longer messages partitioned into packets
55
Virtual Circuit (Frame Relay):
determine routing path during setup
56
Broadcasting (e. g. WLAN):
No switching, all messages delivered to all nodes, receivers must make sense of messages, collision detection mechanisms are needed.
57
Routing
Distributed Algorithm Routers work cooperatively Aim to compute the shortest paths Required routing protocol
58
Congestion Control
Avoid overload Trade-off latency vs. throughput
59
Internetwork
Integration of heterogeneous sub-nets Unified protocol (e.g., Internet Protocol IP)
60
ISO-OSI 7 Layer Model
All People Seem To Need Data Protection * Application * Presentation * Session * Transport * Network * Datalink * Physical NOT used in practise
61
Internet Protocol IP
Virtual Network, Allows routing through multiple networks
62
TCP/IP (Transmission Control Protocol/Internet Protocol)
Only contains 4 of the 7 OSI Layers. DataLink and Physical layer are combined to Host-to-Network layer (LAN) Network layer → IP Transport layer → TCP (or UDP) Application layer → FTP, DNS, SMTP
63
Ports
for distinguishing two connections on a host.
64
TCP/UDP Protocol
TCP is connection-oriented, handles order, loss, duplicate packets, Bi-directional, has to be connected to IP UDP is connectionless, only for short messages, unidirectional, IP given in message
65
UDP/TCP Realization in Java
Packages java.net java.io InetAddress – represents an Internet host by IP address and name DatagramPacket and DatagramSocket – used to communicate with UDP – send one packet at a time Socket und ServerSocket – to establish TCP connection – send data using InputStream and OutputStream
66
Broadcasting
Target are all nodes in the network
67
Multicasting
Receiver can select if it is a member of the group or not multicast IP address range Sender does not know who are the receivers
68
java.io
InputStream, OutputStream  Byte-oriented streams Reader, Writer  Character-oriented streams
69
Semaphores
used to limit the access to critical sections of code (data), not only among threads, it is also used among different processes by OS Counter to limit number of parallel accesses
70
Reader/Writer Problem
Write access must be exclusive while read access can be shared Prioritize writers if updates are frequent Prioritize readers if high read throughput and rare updates
71
synchronization in Java
synchronized; wait/notify semaphore implementations custom data structures
72
Transactions
Abstraction of set of operations (e.g., of a client) into atomic unit All-or-nothing execution No interference from other concurrent transactions or server/client crashes (other process cancels transaction)
73
ACID Properties for Transactions
Atomicity  Transaction executed all or nothing Consistency  Transactions transform objects from one consistent state to another Isolation  Transactions performed without interference of other transactions Durability  Result of successful transaction is permanently stored
74
Serial Equivalence for Transactions
Serial execution (with immediate, permanent write) gives correct state two conflicting operations have to operate on same objects in the same order locking, optimistic control, timestamp ordering, nested transactions
75
Locking
is pessimistic Exclusive locks Read/write locks (read shared, write exlcusive) Two-phase locking
76
deadlock
If two transactions wait for each other to release a lock it can end in a deadlock, as both are waiting and can’t proceed.
77
Deadlock prevention
Acquire all locks at beginning of transaction lock need may not be known in advance at beginning
78
Deadlock detection
Maintain wait-for-graph Test for cycles on each operation, or periodically
79
Optimistic Concurrency Control
Assume conflicts are sparse Working phase, validation phase, update phase
80
Stream Terminal Processing
Traverse (forEach) Search (allMatch, anyMatch) Reduce (count, sum, average) Collect (toArray)
81
Indirect Communication
Temporal/spacial decoupling (async, hide identity) communication middleware Persistent communication distributed systems: frequent changes, nodes (dis)connect frequently, nodes unknown
82
Transient Communication
Transient async: A sends and continues, message can only be sent if B runs Transient receiver oriented: A continues only upon message reveival is acknowledgedment (issued immediately)
83
Persistent Communication
Persistent asynchronous store on sender side Persistent synchronous store on receiver side
84
Push Notifications
Distributed systems often need updates on local object changes (events) Useful to connect heterogeneous systems Efficient notification via multicast
85
IP multicast
eliver IP packets to multiple destinations Minimize number of packets sent Packets do not delay each other
86
Implementations for Group Communication
* Integrity of message content * Guarantee of delivery to each client * Receiving order * Interface to add/remove clients, update list * Monitoring of recipient status, remove inactive recipients
87
JGroups
Reliable group communication in Java Has a Protocol Stack with underlying communication protocols Channels with basic functionality for joining, leaving, sending, receiving (send via reliable multicast)
88
Message Queues
Reliable point-to-point communication persistent storage of messages Decoupling of space and time Sender sends messages to waiting queue destined for a recipient FIFO or priority
89
Publish-Subscribe
sends (publishes) structured events to an event service (broker) Clients subscribe topics, get notified when event available Event characterized by type and attributes One-to-many communication Publishers und subscribers typically do not know each other (space uncoupling)
90
Publish-Subscribe Type of delivery
 Direct: Point to point, Multicast  Indirect: Message Queue, Server
91
Publish-Subscribe Subscription Models
* By Channel * By Topic * By Content * By Type
92
Distributed Shared Memory
Parallel computing architectures → Multiprocessor shared memory Compute-intensive operations on data partitions Avoids explicit messaging Needs memory protection: Use locks and semaphores
93
Tuplespaces
Distributed Shared Memory = Distributed Random Access Memory Tuple Space = Distributed Associative Memory (content-adressable memory)  Asynchronous publish-subscibe system Tuple = Message with ordered and typed attributes  Tuplespace = temporary database of tuples Data producers that publish and subs that consume based on a pattern ()
94
Explicit messaging
No communication transparency Explicit marshalling Explicit send/receive of messages Explicit exception handling
95
RPC / RMI
Middleware connects caller and remote procedure No explicit marshalling required No explicit send/receive required Exception handling
96
JAVA RMI
Middleware service which allows access to remote JAVA objects (other PC on network, localhost) Client-server communication without need to use sockets Modular development Load balancing
97
Stubs and Skeletons
Stub code provides object access to the client who uses a remote object (“Remote control” to remote object ) Skeleton code manages object requests by the object server
98
RMI Registry Usage
Server side: bind / rebind / unbind (name, e.g. "Counter") Client: lookup Registry runs objects in own threads Can create multiple stubs for parallel access to server objects
99
Pass as Value / as Reference
by value: safe from outside manipulation, store a copy by reference: callbacks to passed object (side effects), provided by stub
100
RMI Design patterns
indirect communication mechanisms (tuple spaces, queues, ...) distributed MVP applications (with RMI interface)
101
Object Migration with RMI
process of moving objects between RMI servers Pass object using call-by-value copy placed on the server copy is exported Applications: load balancing, object validation, persistent storage Clients may use derived classes > server needs to reload, client needs to publish via codebase server
102
Web-based Application Programming
integration of code with the existing client/server infrastructure Document-oriented (sync: html, forms or async: dom) or webservice-oriented
103
How to Process HTTP Interaction Requests on the Server Side?
Java servlets
104
Java Servlets
Handling client requests Derive a Servlet class from HttpServlet Overwrite the methods doGet and/or doPost Create HTML code or Java Server Faces in servlet and deliver
105
Execution of Servlets
Typically, web servers serve requests multithreaded, d, but create only one object for each Servlet Requires synchronization of Servlet access Servlets can share information via Servlet context run long-lasting Servlet jobs asynchronously (startAsync, AsyncContext)
106
Identification of Servlet clients
getRemoteAddr() (not reliable, due to use of proxies and NAT) getSession() creates session ID (cookie) to identify returning client
107
Java Server Faces (JSF)
Use external HTML code templates defined in XHTML Embed input/output fields in the XHTML page using Expression Language (EL) statements Fields linked to objects
108
AJAX
Asynchronous JavaScript and XML Embed JavaScript (JS) code in webpages, run by browser code sends the data to the Servlet receives a reply and updates an element of the webpage Programmatic updates to webpages via DOM
109
Webservices
provide services based on HTTP protocol which may exchange data SOAP (Simple Object Access Protocol) REST (representational state transfer) e.g. JSON (JavaScript Object Notation)