CSCI 2113 Final #2

0.0(0)
studied byStudied by 1 person
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards
GUIs
JFrame - windows, ActionListener - listens for actions from elements.  Polymorphism then provides the mechanism for allowing many implementations for that one click-reactor interface. Swing GUI components (like `JFrame`) automatically use at least two threads. Control layout through BorderLayout (North, West, South, etc). JPanel can hold multiple components
2
New cards
Java over C
Java is object oriented and Java is platform independent
3
New cards
Lambda - only works with single method
b.addActionListener((e) -> {

if (l.getText().equals("Hello")) {

l.setText("Goodbye");

}else {

l.setText("Hello");

}

});
4
New cards
Threading
Thread t = new Foo();

Public Class Foo extends Thread {

public void run() {}

}
5
New cards
Join Threads
Java provides another method called `join` that forces the thread it is called upon to wait (to finish) before allowing the other thread to continue. *What?*

For example, if you have the following code inside a `main` method as above:

t.start()

t.join(5000);
6
New cards
Race Conditions
In general, parallel programming is fraught with peril! If you’re not careful, you can end up with bugs whose occurrence or precise behavior depends on the exact order in which the instructions of each thread are executed relative to one another. This kind of bug is called a **race condition**.
7
New cards
Synchronization
public synchronized doSomething()

In this example, the doSomething() method is synchronized, which means that only one thread can execute this method at a time for a given object.
8
New cards
Socket Class
In Java, the `Socket` class is used as the **client** socket in a two-way communication with a **server**. Key to this idea is that the socket is *connected* to the server at a ipaddress/host and port. The main constructor you’ll use is

Socket(String host, int port)

Importantly, the `Socket` is to connect to the server, but communication with the server is a two-way procedure. So once we connect to the server, we can *both* read and write to the socket via the socket’s `InputStream` and `OutputStream`. And like with other I/O we can wrap those streams in other buffered readers/writers.
9
New cards
Server Socket Class
The server side of this works pretty much like the client side, except for an additional step of the server needing to *accept* an incoming connect. The key class is the `ServerSocket` which we initialize like so

new ServerSocket(portNumber)

serverSocket.accept()
10
New cards
Testing
Fault localization - find problem. Generally write test cases before writing code (Test Driven Development)

**verification** versus **validation**. The former checks that your implementation meets the requirements that were written, while the latter measures if the requirements themselves where what should have been written.

Unit Tests - per method, module/integration tests - how do they work together, system testing - highest level
11
New cards
Input Domain Partitioning
Using Input Domain Partitioning, developers partition the possible input space into some number of classes, and then *draw samples from those classes in all possible combinations with respect to classes*.
12
New cards
Junit
Java, like many/most other languages, has unit testing frameworks that make is easy for developers to define assertions and other behavior, and re-run automated test suites. `Junit` is such a unit testing framework for Java; recall, that unit testing is often meant to test specific methods and/or classes. The basic idea is to write *assertions* about what results are expected for certain inputs to specific methods. In Junit, this is all just java code; the test harness then knows what to consider a test case when the developer adds an `@Test` annotation to the top of any such method:
13
New cards
True/False
a.    The Socket class is used to set up a server that can send and receive messages to some client. FALSE

b.    The output stream of a socket is used to receive messages from some other machine. FALSE

c.     You can have a server and a client running on the same machine. TRUE
14
New cards
Threads
A.start()

B.start()

print c

\
Just means B must complete before C. A can come at any point