Question: Java (a) The code of a simple server is shown below. It offers the trivial service of accepting an integer value from a client and

Java

(a) The code of a simple server is shown below. It offers the trivial service of accepting an integer value from a client and returning twice the value received. Explain the weakness in the design of the server and re-write it in light of your critique. # mport java.util.*;import java.net.*; class DoubleServer{ private static int port = 1234; public static void main(String args[]){ try{ ServerSocket serversock = new ServerSocket(port); while(true){ Socket socket = serversock.accept(); new Thread(new Double(socket)).start(); } }catch(IOException e){} } } class Double implements Runnable{ Socket socket; public Double(Socket s){socket = s;} public void run(){ try{ DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); Page 4 of 4 int x = in.readInt(); out.write(2*x); socket.close(); } catch(IOException e){} } }

. (b) Write a Parallel stream java program to count all negative integers in an array of integers A[N]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!