1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
lambda calculus
the basis of functional programming languages
strategy pattern
passing a method into another method
lambda expressions
used with functional interfaces, replaces many uses of anonymous inner classes, and represents an anonymous method or function
lambda syntax
(parameters) → {statements}
void PrintHello() {
System.out.println(“Hello, World”); }
() → System.out.println(“Hello, World”)
double average (double x, double y, double z) { return(x+y+z)/3.0; }
(double x, double y, double z) → (x+y+z)/3.0
void UpdateIfOdd (int x) {
if (x%2≠0) {
y=10;
System.out.print(“y is now “ +y); }
x → { if (x%2≠0) y=10; System.out.print(“y is now “ +y); }
cilent
requests some information or action
server
performs action and responds to the cilent
connection-based service
a cilent and server form a connection and communicate back and forth until the connection is given up
connectionless service
a cilent and server communicate by sending individual packets back and forth
socket
a software construct that represents 1 endpoint of a connection
contains Java’s fundamental networking capabilities
package.java.net
URL stands for
uniform resource locator
class for wrapping up a URL and working with it (contains many get methods)
java.net.URL
stream sockets
TCP communication, used for connection-oriented communcation between a cilent and server
datagram sockets
UDP communication, used for connectionless communcation between programs
UDP
user datagram protocol, most common protocol for connectionless communication
TCP
transmission control protocol, most common protocol for connection-based transmission
SSH is
connection-oriented
port number
identifies the application on the host computer
queue length
max number of cilents that can connect to server
Server: create a ServerSocket object
ServerSocket serv=new ServerSocket (portNumber, queueLength);
Server: listen for a cilent connection
Socket connection=serv.accept();
Server: close the socket
connection.close();
Server: input and output streams
OutputStream os = connection.getOutputStream();
InputStream is = connection.getInputStream();
Cilent: create a socket to connect to the server
Socket connection = new Socket (serverAddress, port);
class DatagramSocket
used for creation of datagram sockets
creation of datagram sockets
DatagramSocket s1, s2;
s1 = new DatagramSocket(12345); // bind to port 12345
s2 = new DatagramSocket(); // bind to any available port on local host machine
class DatagramPacket
used to build packets of information to send over datagram sockets
create a packet for storing up to 500 bytes of data that will be used to receive a datagram packet
DatagramPacket p1, p2;
byte[] data1=new byte[500];
p1=new DatagramPacket(data1, data1.length);
send a packet
s2.send(p2);
receive a datagram packet
s1.receive(p1);
convert a string to a byte array and create a datagram packet of outgoing data (“Hello, World”), set the port number to 1234
String message=”Hello, World”;
byte[] data2=message.getBytes();
p2 = new DatagramPacket (data2, data2.length, InetAddress.getLocalHost(), 1234);