Sunteți pe pagina 1din 2

MID-TERM EXAM (SEMESTER I 2010/2011)

SECTION A: TRUE/FALSE (10 QUESTIONS, 10 MARKS)

1. It is always more advantageous to use TCP over UDP as a communication protocol


since it is reliable.
2. A class can have one and only one constructor.
3. Checked Exceptions are exceptions that occur at compile time.
4. A Java interface declares a set of methods and their signatures together with their
implementation.
5. Implementing the java.io.Serializable interface requires providing a
definition for the run() method defined in the interface.
6. The accept() system call used at the server end in TCP will block until a client
connects to it.
7. If the Java runtime determines that the only threads running in an application are
daemon threads (i.e., there are no user threads), the Java runtime closes down the
application.
8. The Thread.wait( ) method in Java causes the calling thread to wait until the
thread on which it is invoked dies.
9. The IP protocol is a packet-switched network protocol.
10. To prevent individual member variables of a class from being serialized, they can be
marked with the protected keyword.

SECTION B Short Answer Questions (5 QUESTIONS, 20 MARKS)


1. What is the difference between checked and unchecked exceptions in Java? Give
ONE (1) example of each of these types of exceptions.

2. What is the difference between a packet-switched network and a circuit-switched


network? Although IP is a connectionless, unreliable protocol, how does TCP which
runs over IP provide guaranteed delivery and connection-oriented semantics?

3. Java is an “ideal” language for network programming. Justify this statement in the
light of the following properties of the language:
a. The rich API that the language has.
b. The mechanism of data transfer it uses.
c. The platform-independence ability of the language.
d. The multi-threading support within the language.

4. Write the code snippets to do the following in Java.


a. Open an input stream to read raw bytes from a socket.
b. Filter the stream in (a) above to buffer and read data as text.
c. Open an output stream to write raw bytes to a file.
d. Print “Hello World” by filtering the stream in (c) above.

Page 1 of 2
Semester I 2010/2011 Networked Computing
5. What are the TWO ways in which we can do multithreading in Java? Support your
answer with code snippets.

SECTION C Long Answer Question (3 QUESTIONS, 20 MARKS)

1. Write a simple code in Java to send an Employee object from a client to a server. The
server modifies the object’s attributes and sends it back to the client who then
displays it on the screen.
(Hint : You will need to create three classes :
i. Employee Class : Assume that it has only two attributes : employee
number and name. This class must be serializable.
ii. Client Class : Creates a new employee object, connects to the server using
socket and writes the object onto the socket. Later the client reads the object
as returned by the server and displays it.
iii. Server Class : Reads the object sent by a client, modifies it and resends back
to the client).
[10 marks]

2. Write simple code snippets in Java to know the IP address and port number of the
client who is accessing your server machine using:
(i) DatagramSocket (as in UDP).
(ii) ServerSocket (as in TCP).
[4 marks]

3. Write the server and the client code in Java to implement a simple Chat Application
that lets one client talk to another through the common server.
[6 marks]

Page 2 of 2
Semester I 2010/2011 Networked Computing

S-ar putea să vă placă și