






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Ans. CODE : import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class AgeCalculator { private static Age calculateAge(Date birthDate)
//if month difference is in negative then reduce years by one //and calculate the number of months. if (months < 0) { years--; months = 12 - birthMonth + currMonth; if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) months--; } else if (months == 0 && now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) { years--; months = 11; } //Calculate the days if (now.get(Calendar.DATE) > birthDay.get(Calendar.DATE)) days = now.get(Calendar.DATE) - birthDay.get(Calendar.DATE); else if (now.get(Calendar.DATE) < birthDay.get(Calendar.DATE)) {
int today = now.get(Calendar.DAY_OF_MONTH); now.add(Calendar.MONTH, - 1); days = now.getActualMaximum(Calendar.DAY_OF_MONTH)
Server-side program: import java.io.; import java.net.; class ManagerServer { public static void main(String args[]) throws Exception { ServerSocket ss = new ServerSocket(1080); Socket s = ss.accept(); InetAddress IA = InetAddress.getByName("localhost");
File file = new File("Clienttext.java"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); OutputStream o = s.getOutputStream(); byte[] contents; long fileLength = file.length(); long current = 0; long start = System.nanoTime(); while(current!=fileLength) { int size = 10000; if(fileLength-current>=size) { current+=size; } else { size =(int)(fileLength-current); current = fileLength; } contents = new byte[size]; bis.read(contents,0,size); o.write(contents);
while((bytesread = is.read(contents))!=-1) { bos.write(contents,0,bytesread); } bos.flush(); s.close(); System.out.println("File saved successfully"); } } Output: