EX: NO.
1 DATE:
AIM:
Rational number class in Java
To develop a Rational number class in Java, using JavaDoc comments for documentation. The implementation should use efficient representation for a rational number, i.e. (500 / 1000) should be represented as (). ALGORITHM: Step 1: Start the program. Step 2: Define a class with two integer data fields numerator and denominator. Step 3: Define a constructor to initialize the rational number and to simplify it. Step 4: Define methods to perform the basic arithmetic operations such as addition, subtraction, multiplication, division and reciprocal. Step 5: Call the appropriate functions with the corresponding arguments and display the result. Step 6: Stop the program.
PROGRAM: import [Link].*; import [Link].*; public class TestRationalClass { private int num; private int den; public TestRationalClass(int numerator,int denominator) { if(denominator==0) { throw new RuntimeException("denominator is zero!"); } int g=gcd(numerator,denominator); num=numerator /g; den=denominator /g; } public String toString() { if(den==1) { return(num+" "); } else { return(" "+den); } } public TestRationalClass times(TestRationalClass b) { return new TestRationalClass([Link]*[Link],[Link]*[Link]); } public TestRationalClass plus(TestRationalClass b) { int numerator=([Link]*[Link])+([Link]*[Link]); int denominator=[Link]*[Link]; return new TestRationalClass(numerator,denominator);
} public TestRationalClass subtract(TestRationalClass b) { int numerator=([Link]*[Link])-([Link]*[Link]); int denominator=[Link]*[Link]; return new TestRationalClass(numerator,denominator); } public TestRationalClass reciprocal() { return new TestRationalClass(den,num); } public TestRationalClass divides(TestRationalClass b) { return [Link]([Link]()); } private static int gcd(int m,int n) { if(0==n) return m; else return(gcd(n,m%n)); } public static void main(String [] args) { TestRationalClass r1=new TestRationalClass(16,2); TestRationalClass r2=new TestRationalClass(12,3); [Link]("Rational numbers class"); [Link](r1 +" + "+r2+ " = "+[Link](r2)); [Link](r1 +" - "+r2+ " = "+[Link](r2)); [Link](r1 +" * "+r2+ " = "+[Link](r2)); [Link](r1 +" / "+r2+ " = "+[Link](r2)); } }
OUTPUT:
RESULT: Thus the program to develop a rational number class with methods to perform the basic arithmetic operations was executed and the output was verified successfully.
EX: NO. 2 DATE:
AIM:
Date class in Java
To develop Date class in Java similar to the one available in [Link] package. Use JavaDoc comments. ALGORITHM: Step 1: Start the program. Step 2: Define an object today to the Date class and store the current date in that object. Step 3: Change the Date Format to Short, Long and Medium and display the date. Step 4: Convert the Date to String and print it. Step 5: Stop the program.
PROGRAM: import [Link]; import [Link]; import [Link]; import [Link]; public class BasicDateFormatting { public static void main(String[] args)throws Exception { Date today=[Link]().getTime(); DateFormat shortFormatter= [Link]([Link]); DateFormat longFormatter= [Link]([Link]); DateFormat mediumFormatter= [Link]([Link],SimpleD [Link]); [Link]([Link](today)); [Link]([Link](today)); [Link]([Link](today)); String DateAsText=[Link](today); Date TextAsDate=[Link](DateAsText); [Link](TextAsDate); } }
OUTPUT:
RESULT: Thus the program to develop a Date class was executed and the output was verified successfully.
EX: NO. 3 DATE:
AIM:
Lisp-like list in Java
To implement Lisp-like list in Java. To perform the basic operations such as 'car', 'cdr', and 'cons'. ALGORITHM: Step 1: Start the program. Step 2: Create a class LispCommands with a list in it. Step 3: Define a function parse to write the elements into the list. Step 4: Define a function car to return the leading element of the list. Step 5: Define a function cdr to return the list starting from the second element. Step 6: Define a function cons which adds an element to the front of the list. Step 7: Call the respective functions with the appropriate arguments. Step 8: Stop the program.
PROGRAM: import [Link]; import [Link]; import [Link]; import [Link]; import [Link]; import [Link]; public class LispCommands { private String[] tokenList; private static Logger LOGGER = [Link]([Link]()); public LispCommands() { } private void car() { [Link](tokenList[0]); } private void cdr() { List<String> list = [Link](tokenList); ArrayList<String> slist = new ArrayList<String>(list); [Link](0); display(slist); } private void cons(String args) { List<String> arrayList = new ArrayList<String>([Link](tokenList)); [Link](args); [Link](arrayList); display(arrayList); } private void parse(String args) { ArrayList<String> tokenList = new ArrayList<String>(); if(args != null) {
StringTokenizer tokens = new StringTokenizer(args,"[]"); while ([Link]()) { StringTokenizer commaTokens = new StringTokenizer([Link](),","); while ([Link]()) { String token = [Link](); if(token != null && ![Link]().equals("")) [Link]([Link]()); } } } [Link] = [Link](new String[0]); } private void display(Object result) { [Link](); if(result instanceof String) [Link]([Link]()); else if([Link]().getName().equals("[Link]")) [Link]([Link]()); } public static void main(String[] args) { LispCommands L = new LispCommands(); [Link]("[3, 0, 2, 5]"); [Link](); [Link](); [Link]("7"); } }
10
OUTPUT:
RESULT: Thus the program to implement Lisp-like list in Java was executed and the output was verified successfully.
11
EX: NO. 4 DATE:
AIM:
Design a Java interface for ADT Stack
To design a Java interface for ADT Stack and to develop two different classes that implements this interface, one using array and the other using linked-list. ALGORITHM: Step 1: Start the program. Step 2: Design an interface for Stack ADT with functions push, pop and display. Step 3: Define a class to implement the stack using array. Step 4: Define the functions of the interface accordingly and handle the stack overflow and underflow exceptions. Step 5: Define a class to implement the stack using linked list. Step 6: Define the functions of the interface accordingly and handle the exceptions. Step 7: Stop the program.
12
PROGRAM: import [Link].*; import [Link].*; interface Mystack { public void pop(); public void push(); public void display(); } class Stack_array implements Mystack { final static int n=5; int stack[]=new int[n]; int top=-1; public void push() { try { BufferedReader br=new BufferedReader(new InputStreamReader([Link])); if(top==(n-1)) { [Link](" Stack Overflow"); return; } else { [Link]("Enter the element"); int ele=[Link]([Link]()); stack[++top]=ele; } } catch(IOException e) { [Link]("e"); } } public void pop() { if(top<0) { [Link]("Stack underflow"); return; } else
13
{ int popper=stack[top]; top--; [Link]("Popped element:" +popper); } } public void display() { if(top<0) { [Link]("Stack is empty"); return; } else { String str=" "; for(int i=0;i<=top;i++) str=str+" "+stack[i]+" <--"; [Link]("Elements are:"+str); } } } class Link { public int data; public Link nextLink; public Link(int d) { data= d; nextLink=null; } public void printLink() { [Link](" --> "+data); } } class Stack_List implements Mystack { private Link first; public Stack_List() { first = null; } public boolean isEmpty() {
14
return first == null; } public void push() { try { BufferedReader br=new BufferedReader(new InputStreamReader([Link])); [Link]("Enter the element"); int ele=[Link]([Link]()); Link link = new Link(ele); [Link] = first; first = link; } catch(IOException e) { [Link](e); } } public Link delete() { Link temp = first; try { first = [Link]; } catch(NullPointerException e) { throw e; } return temp; } public void pop() { try { Link deletedLink = delete(); [Link]("Popped: "+[Link]); } catch(NullPointerException e) { throw e; } } public void display() {
15
if(first==null) [Link]("Stack is empty"); else { Link currentLink = first; [Link]("Elements are: "); while(currentLink != null) { [Link](); currentLink = [Link]; } [Link](""); } } } class StackADT { public static void main(String arg[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader([Link])); [Link]("Implementation of Stack using Array"); Stack_array stk=new Stack_array(); int ch=0; do { [Link]("[Link] [Link] [Link]"); [Link]("Enter your choice:"); ch=[Link]([Link]()); switch(ch) { case 1: [Link](); break; case 2: [Link](); break; case 3: [Link](); break; } }while(ch<4); [Link]("Implementation of Stack using Linked List"); Stack_List stk1=new Stack_List(); ch=0; do
16
{ [Link]("[Link] [Link] [Link]"); [Link]("Enter your choice:"); ch=[Link]([Link]()); switch(ch) { case 1: [Link](); break; case 2: try { [Link](); } catch(NullPointerException e) { [Link]("Stack underflown"); } break; case 3: [Link](); break; } }while(ch<4); } }
17
OUTPUT:
RESULT: Thus the program to implement Stack ADT using array and linked list was executed and the output was verified successfully.
18
EX: NO. 5 DATE:
AIM:
Design a Vehicle class hierarchy in Java
To design a Vehicle class hierarchy in Java and to demonstrate polymorphism. ALGORITHM: Step 1: Start the program. Step 2: Define a class Vehicle with fields register no. and model. Step 3: Define a method display which displays all the data fields. Step 4: Define the classes namely Twowheeler, Threewheeler and Fourwheeler as subclasses of Vehicle class. Step 5: These subclasses defines a method named display that overrides the super class method. Step 6: Create objects for the subclasses and call the appropriate methods. Step 7: Stop the program.
19
PROGRAM: import [Link].*; class Vehicle { String regno; int model; Vehicle(String r, int m) { regno=r; model=m; } void display() { [Link]("Registration no: "+regno); [Link]("Model no: "+model); } } class Twowheeler extends Vehicle { int noofwheel; Twowheeler(String r,int m,int n) { super(r,m); noofwheel=n; } void display() { [Link]("Two wheeler tvs"); [Link](); [Link]("No. of wheel : " +noofwheel); } } class Threewheeler extends Vehicle { int noofleaf; Threewheeler(String r,int m,int n) { super(r,m); noofleaf=n; } void display() { [Link]("Three wheeler auto");
20
[Link](); [Link]("No. of leaf:" +noofleaf); } } class Fourwheeler extends Vehicle { int noofleaf; Fourwheeler(String r,int m,int n) { super(r,m); noofleaf=n; } void display() { [Link]("Four wheeler car"); [Link](); [Link]("No. of leaf:" +noofleaf); } } public class Vehicledemo { public static void main(String arg[]) { Twowheeler t1; Threewheeler th1; Fourwheeler f1; t1=new Twowheeler("TN74 12345", 1,2); th1=new Threewheeler("TN74 54321", 4,3); f1=new Fourwheeler("TN34 45677",5,4); [Link](); [Link](); [Link](); } }
21
OUTPUT:
RESULT: Thus the program to design vehicle class hierarchy and to demonstrate polymorphism was executed and the output was verified successfully.
22
EX: NO. 6 DATE:
AIM:
Random Generation of objects
. To design classes namely Currency, Rupee, and Dollar. To write a program that randomly generates Rupee and Dollar objects and writes them into a file using object serialization. To write another program to read that file, and to convert to Rupee if it reads a Dollar, while leave the value as it is if it reads a Rupee. ALGORITHM: Step 1: Start the programs. Step 2: Define a class Currency as an abstract class with abstract methods. Step 3: Define the classes Rupee and Dollar as subclasses of Currency. Step 4: Define the abstract methods of the super class accordingly in each subclass. Step 5: The dollar value is converted to equivalent rupee value within a method of Dollar class. Step 6: Define a class StoreCurrency that randomly generates objects of Rupee and Dollar classes. Step 7: These objects are written into a file named currency using object serialization. Step 8: Define a class ReadCurrency that reads the objects from the file currency, and displays them. Step 9: Stop the programs.
23
PROGRAM: [Link] import [Link]; public abstract class Currency implements Serializable { protected static final Double DOLLAR_RUPEE_EXCHAGERATE = 44.445D; public Currency(Double money) { super(); [Link] = money; } protected Double money; public abstract Double getValue (); public abstract String getPrintableValue(); } [Link] public class Rupee extends Currency { public Rupee(Double amount) { super(amount); } public Double getValue() { return [Link]; } public String getPrintableValue() { String strValue = "Object Name : Rupee \nINR : Rs " + getValue() + "\n------------------\n"; return strValue; } } [Link] public class Dollar extends Currency { public Dollar(Double money) { super(money); }
24
public Double getValue() { return ([Link] * DOLLAR_RUPEE_EXCHAGERATE); } public String getPrintableValue() { String strValue = "Object Name : Dollar \nUSD : $" + [Link] + " \nINR : Rs" + getValue() + "\n------------------\n"; return strValue; } } [Link] import [Link]; import [Link]; import [Link]; import [Link]; import [Link]; import [Link]; public class StoreCurrency { public static void main(String[] args) throws FileNotFoundException,IOException { Currency currency = null; ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File("[Link]"))); Random random = new Random(); for (int i = 0; i < 10; i++) { int decide = [Link](); Double value = ([Link]() *10); if ( (decide%2)==0 ) currency = new Rupee(value); else currency = new Dollar(value); [Link](currency); } [Link](null); [Link](); } }
25
[Link] import [Link]; import [Link]; import [Link]; import [Link]; public class ReadCurrency { public static void main(String[] args) throws IOException, ClassNotFoundException { Currency currency = null; ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File("[Link]"))); while ((currency = (Currency) [Link]()) != null) { [Link]([Link]()); } [Link](); } }
26
OUTPUT:
RESULT: Thus the program to generate objects randomly and to write them into a file using object serialization was executed. The file was read and the required rupee-dollar conversions were performed and the output was verified successfully.
27
EXP: No. 7 DATE:
AIM:
Calculator in Java
To design a calculator using event-driven programming paradigm of Java. ALGORITHM: Step 1: Start the program. Step 2: Create a frame for the calculator and include the swing components such as buttons and text field as required in it. Step 3: Layouts such as Border Layout and Grid Layout are used to align the components as per the requirements of the calculator. Step 4: Redefine the actionPerformed() method in the ActionListener interface to perform the appropriate operations when the buttons are pressed. Step 5: Provide mechanisms to handle the Number Format exceptions that may occur. Step 6: Stop the program.
28
PROGRAM: import [Link].*; import [Link].*; import [Link].*; import [Link].*; class Calculator extends JFrame { private static final Font BIGGER_FONT = new Font("monspaced", [Link], 20); private JTextField _displayField; private boolean _startNumber = true; private String _previousOp ="="; private CalcLogic _logic = new CalcLogic(); public static void main(String[] args) { try { [Link]([Link]()); } catch (Exception unused) { } Calculator window = new Calculator(); [Link](JFrame.EXIT_ON_CLOSE); [Link](true); } public Calculator() { _displayField = new JTextField("0", 12); _displayField.setHorizontalAlignment([Link]); _displayField.setFont(BIGGER_FONT); JButton clearButton = new JButton("Clear"); [Link](BIGGER_FONT); [Link](new ClearListener()); ActionListener numListener = new NumListener(); String buttonOrder = "789456123 0 "; JPanel buttonPanel = new JPanel(); [Link](new GridLayout(5, 3, 2, 2)); for (int i = 0; i < [Link](); i++) { String keyTop = [Link](i, i+1); JButton b = new JButton(keyTop); if ([Link](" ")) {
29
[Link](false); } else { [Link](numListener); [Link](BIGGER_FONT); } [Link](b); } ActionListener opListener = new OpListener(); JPanel opPanel = new JPanel(); [Link](new GridLayout(5, 1, 2, 2)); String[] opOrder = {"+", "-", "*", "/", "="}; for (int i = 0; i < [Link]; i++) { JButton b = new JButton(opOrder[i]); [Link](opListener); [Link](BIGGER_FONT); [Link](b); } JPanel clearPanel = new JPanel(); [Link](new FlowLayout()); [Link](clearButton); JPanel content = new JPanel(); [Link](new BorderLayout(5, 5)); [Link](_displayField,[Link] ); [Link](buttonPanel ,[Link]); [Link](opPanel ,[Link] ); [Link](clearPanel ,[Link] ); [Link]([Link](10,10,10,10)); [Link](content); [Link](); [Link]("Calculator"); [Link](false); } private void actionClear() { _startNumber = true; _displayField.setText("0"); _previousOp = "="; _logic.setTotal("0"); } class OpListener implements ActionListener { public void actionPerformed(ActionEvent e) {
30
if (_startNumber) { actionClear(); _displayField.setText("ERROR - No operator"); } else { _startNumber = true; try { String displayText = _displayField.getText(); if (_previousOp.equals("=")) _logic.setTotal(displayText); else if (_previousOp.equals("+")) _logic.add(displayText); else if (_previousOp.equals("-")) _logic.subtract(displayText); else if (_previousOp.equals("*")) _logic.multiply(displayText); else if (_previousOp.equals("/")) _logic.divide(displayText); _displayField.setText("" + _logic.getTotalString()); } catch (NumberFormatException ex) { actionClear(); _displayField.setText("Error"); } _previousOp = [Link](); } } } class NumListener implements ActionListener { public void actionPerformed(ActionEvent e) { String digit = [Link](); if (_startNumber) { _displayField.setText(digit); _startNumber = false; } else { _displayField.setText(_displayField.getText() + digit); }
31
} } class ClearListener implements ActionListener { public void actionPerformed(ActionEvent e) { actionClear(); } } } class CalcLogic { private int _currentTotal; public CalcLogic() { _currentTotal = 0; } public String getTotalString() { return "" + _currentTotal; } public void setTotal(String n) { _currentTotal = convertToNumber(n); } public void add(String n) { _currentTotal += convertToNumber(n); } public void subtract(String n) { _currentTotal -= convertToNumber(n); } public void multiply(String n) { _currentTotal *= convertToNumber(n); } public void divide(String n) { _currentTotal /= convertToNumber(n); } private int convertToNumber(String n) { return [Link](n); } }
32
OUTPUT:
RESULT: Thus the program to design a calculator was executed and the output was verified successfully.
33
EXP: NO. 8 DATE:
AIM:
Multithreading in Java
To write a program in Java that prints all the prime numbers in the Fibonacci series below 10000 using multithreading. ALGORITHM: Step 1: Start the program. Step 2: Create a thread called Prime Thread that stores all the prime numbers below 10000. Step 3: Create another thread called Fibonacci Thread that stores the elements of the Fibonacci series below 10000. Step 4: Prime Thread and Fibonacci Thread are assigned a higher priority than the main thread of the program. Step 5: The main thread reads the values stored by both the threads, checks for the common elements and prints them. Step 6: Stop the program.
34
PROGRAM: interface maxlimit { public static final int MAX_LIMIT=10000; } class prime extends Thread implements maxlimit { int num[]=new int[MAX_LIMIT]; prime(String n) { super(n); for(int i=0;i<MAX_LIMIT;i++) num[i]=-1; } public void run() { int k=0,flag; for(int i=2;i<=MAX_LIMIT;i++) { flag=0; for(int j=2;j<i;j++) { if(i%j==0) { flag=1; break; } } if(flag==0) { num[k]=i; k++; } } } } class fibonacci extends Thread implements maxlimit { int num[]=new int[MAX_LIMIT]; fibonacci(String n) { super(n); for(int i=0;i<MAX_LIMIT;i++) num[i]=-1; }
35
public void run() { int f1=-1,f2=1,f3=0,k=0; while(f3<=MAX_LIMIT) { f3=f1+f2; num[k]=f3; k++; f1=f2; f2=f3; } } } class primefibi { public static void main(String arg[]) { prime p=new prime("Prime Thread"); fibonacci f=new fibonacci("Fibonacci Thread"); [Link](9); [Link](9); [Link](); [Link](); [Link]("Prime numbers in fibonacci series"); for(int i=0;[Link][i]!=-1;i++) { for(int j=0;[Link][j]!=-1;j++) { if([Link][i]==[Link][j]) { [Link]([Link][i]); break; } } } } }
36
OUTPUT:
RESULT: Thus the program to print the prime numbers in the Fibonacci series using multithreading was executed and the output was verified successfully.
37
EXP: NO. 9 DATE:
AIM:
Simple OPAC system for library
To develop a simple OPAC system for library using event-driven and concurrent programming paradigms of Java. JDBC is used to connect to a back-end database. ALGORITHM: Step 1: Start the program. Step 2: Design the front end for the library system. Step 3: Connect the front end with the database at the backend using JDBC. Step 4: Design the front end such that it accepts the inputs from the user and inserts the records into the database. Step 5: Display the contents of the database at the front end. Step 6: Suspend the established connections. Step 7: Stop the program.
38
PROGRAM: [Link] import [Link].*; import [Link].*; import [Link].*; import [Link].*; public class Datas extends JFrame implements ActionListener { JTextField id; JTextField name; JButton next; JButton addnew; JPanel p; static ResultSet res; static Connection conn; static Statement stat; public Datas() { super("Our Application"); Container c = getContentPane(); [Link](new GridLayout(5,1)); id = new JTextField(20); name = new JTextField(20); next = new JButton("Next BOOK"); p = new JPanel(); [Link](new JLabel("ISBN",[Link])); [Link](id); [Link](new JLabel("Book Name",[Link])); [Link](name); [Link](p); [Link](next); [Link](this); pack(); setVisible(true); addWindowListener(new WIN()); } public static void main(String args[]) { Datas d = new Datas(); try { [Link]("[Link]"); conn = [Link]("jdbc:odbc:custo"); stat = [Link]();
39
res = [Link]("Select * from stu"); [Link](); } catch(Exception e) { [Link]("Error" +e); } [Link](res); } public void actionPerformed(ActionEvent e) { if([Link]() == next) { try { [Link](); } catch(Exception ee) { } showRecord(res); } } public void showRecord(ResultSet res) { try { [Link]([Link](2)); [Link]([Link](3)); } catch(Exception e) { } } class WIN extends WindowAdapter { public void windowClosing(WindowEvent w) { JOptionPane jop = new JOptionPane(); [Link](null,"Database","Thanks",JOptionPane.QUESTION_MESSAG E); } } }
40
[Link] import [Link].*; import [Link].*; class Ja { String bookid,bookname; int booksno; Connection con; Statement stmt; ResultSet rs; Ja() { try { [Link]("[Link]"); con=[Link]("jdbc:odbc:co"); } catch(Exception e) { [Link]("connection error"); } } void myput() { try { stmt=[Link](); rs=[Link]("SELECT * FROM opac"); while([Link]()) { booksno=[Link](1); bookid=[Link](2); bookname=[Link](3); [Link]("\n"+ booksno+"\t"+bookid+"\t"+bookname); } [Link](); [Link](); [Link](); } catch(SQLException e) { [Link]("sql error"); }
41
} } class prog1 { public static void main(String arg[]) { Ja j=new Ja(); [Link](); } } OUTPUT:
RESULT: Thus the program to design a simple OPAC system for library was executed and the output was verified successfully. 42
43
EXP: NO. 10 DATE:
AIM:
Multithreaded Echo Server and Client
To develop a multithreaded echo server and a corresponding client. ALGORITHM: Step 1: Start the program. Step 2: Create a Socket at the Server side. Step 3: Design the server such that it responds to each client using a separate thread. Step 4: The server receives the data sent by the client and echoes those data. Step 5: Provide the necessary exception handling mechanisms at the server. Step 6: Create a Socket at the client side. Step 7: Get the host name from the user. Step 8: Establish a connection between the server and the client. Step 9: Transmit the data from the client side to the server. Step 10: Provide the necessary exception handling mechanisms at the client. Step 11: Stop the program.
44
PROGRAM: [Link] import [Link].*; import [Link].*; public class EchoServer { ServerSocket m_ServerSocket; public EchoServer() { try { m_ServerSocket = new ServerSocket(12111); } catch(IOException ioe) { [Link]("Could not create server socket at 12111. Quitting."); [Link](-1); } [Link]("Listening for clients....."); int id = 0; while(true) { try { Socket clientSocket = m_ServerSocket.accept(); ClientServiceThread cliThread = new ClientServiceThread(clientSocket, id++); [Link](); } catch(IOException ioe) { [Link]("Exception encountered on accept. Ignoring. Stack Trace :"); [Link](); } } } public static void main (String[] args) { new EchoServer(); } class ClientServiceThread extends Thread {
45
Socket m_clientSocket; int m_clientID = -1; boolean m_bRunThread = true; ClientServiceThread(Socket s, int clientID) { m_clientSocket = s; m_clientID = clientID; } public void run() { BufferedReader in = null; PrintWriter out = null; [Link]("Accepted Client : ID - " + m_clientID + " : Address - " + m_clientSocket.getInetAddress().getHostName()); try { in = new BufferedReader(new InputStreamReader(m_clientSocket.getInputStream())); out = new PrintWriter(new OutputStreamWriter(m_clientSocket.getOutputStream())); while(m_bRunThread) { String clientCommand = [Link](); [Link]("Client Says :" + clientCommand); if([Link]("quit")) { m_bRunThread = false; [Link]("Stopping client thread for client : " + m_clientID); } else { [Link](clientCommand); [Link](); } } } catch(Exception e) { [Link](); } finally { try {
46
[Link](); [Link](); m_clientSocket.close(); [Link]("...Stopped"); } catch(IOException ioe) { [Link](); } } } } } [Link] import [Link].*; import [Link].*; public class EchoClient { public static void main(String[] args) { if([Link] == 0) { [Link]("Usage : EchoClient <serverName>"); return; } Socket s = null; try { s = new Socket(args[0], 12111); } catch(UnknownHostException uhe) { [Link]("Unknown Host :" + args[0]); s = null; } catch(IOException ioe) { [Link]("Cant connect to server at 12111. Make sure it is running."); s = null; } if(s == null) [Link](-1);
47
BufferedReader in = null; PrintWriter out = null; try { in = new BufferedReader(new InputStreamReader([Link]())); out = new PrintWriter(new OutputStreamWriter([Link]())); [Link]("Hello"); [Link](); [Link]("Server Says : " + [Link]()); [Link]("This"); [Link](); [Link]("Server Says : " + [Link]()); [Link]("is"); [Link](); [Link]("Server Says : " + [Link]()); [Link]("a"); [Link](); [Link]("Server Says : " + [Link]()); [Link]("Test"); [Link](); [Link]("Server Says : " + [Link]()); [Link]("Quit"); [Link](); } catch(IOException ioe) { [Link]("Exception during communication. Server probably closed connection."); } finally { try { [Link](); [Link](); [Link](); } catch(Exception e) { [Link](); } } } }
48
OUTPUT:
RESULT: Thus the program to develop a multithreaded echo server and client was executed and the output was verified successfully. 49