Exam Preparation Elliot Flashcards

1
Q

Benefits of AWT

A

Good for background system specific code

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

Benefits of Swing

A

Lightweight, pure java, subclass of AWT Frame

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

What is a JOptionPane

A

Popup box with Y, N, and Cancel

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

What is the general structure of. JMenuBar

A

JMenuBar(JMenu(JMenuItem))

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

Was is JFrame a subclass of, and what is it not a component of

A

AWT.frame, JFrame is not a Component

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

What is a general overview of MVC

A

View passes input to Controller, Controller updates the View

Controller changes the state of the Model

ModelChanged by the Model updates the values in the view

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

What parts are in the event dispatch thread

A

Event Queue, Event Loop, Event handler (click > data received > refresh the gui), GUI components

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

What part is in the helper thread and where does it send its data

A

Long task processing, this will add to the event queue

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

What is an event source

A

A component generating an event (“fires”)

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

What is an event

A

A user interaction

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

What is an eventListener

A

An object implementing a handler to react to an complete a task (listeners need to be registered to a source)

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

What is the general form of a listener

A

JObject created
name.addActionListener(new actionListener() {
override ActionPerformed(actionEvent e) {
name.method();
}
});
add the object to the panel

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

What is the mouse listener called

A

MouseMotionListener

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

What is the difference between Adaptors and Listeners

A

Listeners are interfaces, Adaptors are abstract classes

Adaptors only require implementation of the required events

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

What is the general form of an adaptor

A
panel.add(new MouseAdaptor() {
    override the MouseMoved(MouseEvent arg0) {
        doStuff...
    }
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the Event dispatch thread do

A

Executes GUI code

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

What are the three reasons to have the Event dispatch thread

A

Responsive, long computations won’t lock up the GUI

ThreadSafe, only the EDT can access the GUI

Swing can use SwingWorker to deal with computational tasks

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

How to use SwingUtilities, what will this ensure

A

Use invokeLater on runnable as a parameter to start the GUI, this will ensure GUI is on the EDT

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

What is the general form of SwingUtilities

A
SwingUtilities.invokeLater(new Runnable() {
    public void run() {}
});
20
Q

What is the general form of SwingWorker

A
SwingWorker worker = new SW() {
    override doInBackground()
21
Q

What are the four main regex methods

A

compareTo(), substring(), indexOf(), matches()

22
Q

How does compareTo() function

A
  • if value alphabetically before, + if alphabetically behind, 0 is match
23
Q

File I/O text

A

Format with Formatter(format), BufferedWriter

Scan with Scanner and scanner methods hasNext(), nextLine(), next(), BufferedReader

24
Q

Binary file I/O class and methods

A

DataInput/OutputStream; read/write Byte, Int, Double

25
Q

Steps to be able to serialize

A

Class has to implement Serializable
Wrap non serialisable by overriding read/writeObject
Unserializable fields will need to catch IOExc

26
Q

Why use threads

A

Efficient, responsive, allows for task separation

27
Q

Compare processes and threads

A

Processes spawn threads, have a call stack, PC, and their own memory

Threads have a class stack and a PC and share the memory of their parent process

28
Q

Why can threads be faster

A

Threads can be separated onto multicore systems

29
Q

What are the six main thread states

A
waiting
timed
waiting
blocked
terminated
ready
running
30
Q

What does the OS control in regards to threads

A

Switching between ready and running

31
Q

Thread waiting methods

A

wait(), notifyAll(), sleep()

32
Q

Thread Blocking methods

A

enter/exitSync()

33
Q

Compare threads and runnable

A

Both need a run() method

Extend thread, implement runnable

You can extend another class with runnable

Runnable has a lower overhead due to a single runnable instance

34
Q

What are Daemon threads

A

Service, background threads, will auto terminate once main has terminated

35
Q

What is ExecutorService

A

A means of reusing threads

36
Q

What are the types of thread pools

A

newFixedThreadPool(int), newCachedThreadPool()

37
Q

What are the main ExecutorService methods

A

execute(runnable)

shutdown(), orderly kill sequence

shutdownNow(), kill and halt, return a list of shutdown threads, no guarantees

awaitTermination(), block invocation until everything is complete

38
Q

What does synchronised do

A

Creates a lock on method declaration, only one tread can access the method at one time (Instance monitor lock) note that unsynchronised methods with be accessible

39
Q

How can we avoid producer/consumer issues

A

Use synchronised and implement checks before allowing method/value access

40
Q

What is the BlockingQueue

A

It is an array(int) which stores pending operations

41
Q

What are the main BlockingQueue methods

A

add (illegalStateExc)
put (will wait if no space in queue)
remove (returns the head, NoSuchElementExc)
poll (return the head)

note BlockingQueue ignores FIFO

42
Q

What is Callable and what does its method return

A

An interface with a single call() method returning the result of a threads task, an exception if task incomplete

43
Q

What is the general format of Callable

A
public class SimpleCall implements Callable {
    override String call() throws Exception {
        return String datarow = "A bunch of values";
    }
} // Asynchronous result
44
Q

What is the Future object

A

Obj represents a result of an asynchronous computation

45
Q

What are the main Future methods

A

cancel(boolean interrupt) throws InterruptedException

isCancelled() return true of task sent and interruptedException

isDone() return true if task is complete

get(optional timeout) wait for completion and return result

46
Q

What are the Future exceptions

A

Cancellation, computation canceled

Execution, computation threw an exc

Interrupted, thread interrupted while waiting

47
Q

How to use FutureTask

A

Implement the future interface

call the get method of callable