You are on page 1of 2

DUE DATE:

MONDAY 1st, April, 2019

INSTRUCTION(S):
i) Complete all the questions and hand in the CAT to the Class Rep.
ii) DO NOT send to my email.

Advanced Programming
CAT 2 (30 Marks)
a) Differentiate between byte-based and character-based streams. (4 Marks)

In Java, Byte Stream helps to perform input and output operations of 8-bit bytes while the
Character Stream helps to perform input and output operations of 16-bit Unicode.

b) Explain using code snippets the purpose of the Connection, Statement and Resultset objects
in relation to Java database connectivity (6 Marks)
A Connection object controls the connection to the database. An application can alter the behavior of a
connection by invoking the methods associated with this object. An application uses the connection
object to create statements.

Statement object is used for executing SQL statements. The statement can be executed multiple
times with different parameter values specified for each execution.

A ResultSet object contains the results of a query. A ResultSet is returned to an application when
a SQL query is executed by a statement object. The ResultSet object provides methods for
iterating through the results of the query.
c) Write a simple program in java programming language that demonstrates the concept of
network programming with sockets. (10 Marks)

d) Write a simple program in java programming language that demonstrates the concept of
multithreading. (10 Marks)

class MultithreadingDemo extends Thread


{
public void run()
{
try
{
// Displaying the thread that is running
System.out.println ("Thread " +
Thread.currentThread().getId() +
" is running");

}
catch (Exception e)
{
// Throwing an exception
System.out.println ("Exception is caught");
}
}
}

// Main Class
public class Multithread
{
public static void main(String[] args)
{
int n = 8; // Number of threads
for (int i=0; i<8; i++)
{
MultithreadingDemo object = new MultithreadingDemo();
object.start();
}
}
}

Output :

Thread 8 is running
Thread 9 is running
Thread 10 is running
Thread 11 is running
Thread 12 is running
Thread 13 is running
Thread 14 is running
Thread 15 is running

You might also like