Week 10 Flashcards

1
Q

What is networking in Java?

A

Java provides a framework for communication between machines using:

TCP (Transmission Control Protocol): Reliable, connection-based

UDP (User Datagram Protocol): Unreliable, connectionless

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

What are sockets in networking?

A

A socket is a connection endpoint for sending and receiving data between two machines

Sockets are bound to a specific port on a server to listen for client requests

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

What are the differences between TCP and UDP?

A

TCP:

Connection-based

Guarantees data delivery and order

Error-checked and reliable

Example applications: HTTP, FTP

UDP:

Connectionless

No guarantee of delivery or order

Lightweight and faster due to minimal overhead

Example applications: Streaming, DNS

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

What are ports in networking?

A

A port is a 16-bit number used to direct data to specific applications on a machine

Well-known ports: 0-1023 (e.g., port 80 for HTTP)

Used in both TCP and UDP communication

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

What is required for socket communication?

A

Server:

Runs on a specific machine (IP address) and listens on a port

Accepts client connections and creates a new socket for communication

Client:

Knows the server’s hostname and port

Opens a connection to the server’s socket

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

How do you read/write data using sockets in Java?

A
  1. Open a socket
  2. Open input/output streams to the socket
  3. Read and write data using the streams
  4. Close the streams
  5. Close the socket
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Java classes for TCP and UDP communication?

A

TCP:

Socket and ServerSocket: For client-server communication

URL and URLConnection: For HTTP connections

UDP:

DatagramPacket: Represents a UDP packet

DatagramSocket: For sending and receiving packets

MulticastSocket: For group communication

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

How is data sent and received with UDP?

A

Data is sent as independent packets (datagrams)

No dedicated channel is established

The receiver must handle missing or out-of-order packets

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

What are client-server pairs in Java?

A

Server:

Creates a ServerSocket to listen for incoming connections

Accepts a client connection and communicates via a new Socket

Client:

Creates a Socket to connect to the server’s IP and port

Exchanges data with the server through streams

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

What are common uses of TCP and UDP?

A

TCP:

Reliable communication for web services, file transfers

UDP:

Fast communication for streaming, gaming, or broadcasting

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

What are the key advantages of using TCP over UDP?

A

Ensures data integrity and order

Better for applications where reliability is critical

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

What are the advantages of UDP over TCP?

A

Lower latency

Suitable for real-time applications where minor data loss is acceptable

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

What is Java RMI?

A

A framework allowing objects in one JVM to invoke methods on objects in another JVM

Facilitates remote communication between Java programs on different machines

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

What are the basic components of RMI?

A

Registry: Maps names to remote objects using bind and rebind

Server: Registers remote objects with the RMI registry and waits for client invocations

Client: Looks up remote objects in the registry and invokes methods on them

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

What is required for an object to be remote?

A

The object must implement an interface extending java.rmi.Remote

Methods in the interface must declare throws java.rmi.RemoteException

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

What are the steps to create an RMI service?

A
  1. Define a remote interface
  2. Implement the interface in a concrete class (remote implementation)
  3. Use the Java compiler to generate stubs and skeletons
  4. Start the RMI registry
  5. Start the remote service
17
Q

What is the role of the RMI registry?

A

A server-side process that allows clients to look up and obtain references to remote objects by name

18
Q

What are stubs and skeletons in RMI?

A

Stub: Client-side helper that communicates with the server’s remote object

Skeleton: Server-side helper that dispatches client requests to the appropriate method on the remote object (deprecated in modern Java)

19
Q

How is security managed in RMI?

A

Permissions are set using security policies defined in .policy files

Security settings control access to local and remote resources

20
Q

What is the java.rmi.RemoteException?

A

A checked exception that must be declared by methods in remote interfaces

Indicates errors during remote communication

21
Q

What is the Compute Engine example?

A

Demonstrates a server executing arbitrary tasks sent by clients

The server does not need to know the task definitions beforehand

22
Q

What are the key RMI runtime settings?

A

-Djava.rmi.server.codebase: Specifies the location of the remote class definitions

-Djava.security.policy: Specifies the security policy file

23
Q

What are some common RMI methods?

A

Server-side:

bind(String name, Remote obj)

rebind(String name, Remote obj)

Client-side:

lookup(String name)

24
Q

What are the limitations of RMI?

A

Limited to Java applications

Performance overhead due to serialization and deserialization

Requires careful handling of security and network configurations