Object Oriented Programming 2 Flashcards
Rich API support
Doing / learning networking, parallelism, graphics, GUI, algorithms
Why is java platform independent
It runs in a virtual machine: JVM
Why learn Java?
Active development, many jobs, platform indep, tools (networking, …)
Java and Distributed Systems
Socket communication, thread management, object serialization, remote method invocations, servlets, applets
Java compilation
Programm compiled into bytecode, which the JVM executes at runtime
Object
Combines methods (behaviour) and data (state),
hide complexity, modularization, modelling of domain
How are objects defined
throught the keyword “class”
“volatile”
ensures visiblity accross threads, safe to use across threads
Interface
Defines a group of methods, classes implement them to provide functionailty, implementation enforced at compilation
static nested classes
no access to outer members, to hide access
Named constants
entirely in uppercase with underscore
Creation of Arrays:
anArray = new int[10];
float[] anArrayOfFloats;
int[] anArray = {
100, 200, 300,
400, 500, 600,
};
Casting
Cast allows access to specific object
methods
Defensive copies
gainst outside failures, ill-behaved clients, or attacks
also for getters
varargs
represent zero or
more arguments of a specified type
Parallelism (concurrency)
one computer that does multitasking, real (processors) or pseudo (threads)
Distributed system
Networked components, coordinated by messages
Server threads
within server process; handle concurrent user requests
Server processes
handle different types of access
(e.g., web, mail, file, …)
Remote Invocation
Client invocation and server result
RPC (remote procedure call) or RMI (remote method invocation)
Requires defined messaging protocoL
Server State:
Stateful (client tables)
Soft state (for given time)
Session state (for session)
Stateless
Thread-based Connection Abstraction
incoming request -> accepted by dispatcher thread
Threaded Server Design Patterns
Fix or dynamic number of threads
Re-usage of threads: thread pool (created at start), non active threads kept in pool
Thread per Request
dispatcher reveives request, for each a thread is created or assigned from pool
Worker thread: Read request
Process request
Answer request
End
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)
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
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
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
Interface Runnable
Alternative to using run on objects derived from Thread
Synchronization
shared data, execution order ofter hard to predict
without controls, we cannot predict thread switch
Synchronization methods are needed
data consistency (data correctness)
maintain parallelism
synchronized keyword
locks an object, if a thread encounters it and it is locked, thread is put to sleep
try to synchronize specific variables
End of Java Thread
join(): blocks until a thread ends
yield(): increase probability to switch to another thread
Inside synchronized
wait() → blocks a calling Object until it gets notified that it can resume
notify() → unblocks waiting caller
notifyAll() → unblocks all waiting callers
JavaFX
Stage: window
Scene: container to fill a stage
Observers in JavaFX
implements the interface EventHandler<ActionEvent></ActionEvent>
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
JavaFX Bindings
Mechanisms to couple properties -> Change of one property changes another property (uni or bidirectional)
JavaFX Collections
You can register observers to collections
They are notified on changes to the collection
Interfaces ObservableList, ObservableMap, ObservableSet
JavaFX Elements
“Node” is the basic element
Pane derives from Node and is basis for all container classes
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
JavaFX Interaction Elements
Control class derived from Node
Labels, Buttons, Lists, Pickers, Slider, Text Input
JavaFX Other functions
Automatization: Stylesheet support, UI definitions from FXML files
Multi-windows UIs
Web and media support