What will happen when you attempt to run the following code?
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException {
try ( ObjectOutputStream output =
new ObjectOutputStream(new FileOutputStream(“object.dat”)); ) {
output.writeObject(new A());
}
}
}
class A implements Serializable {
B b = new B();
}
class B {
}
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Science: An Overview (12th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Problem Solving with C++ (9th Edition)
Problem Solving with C++ (10th Edition)
- How can I fix the error and complete my code? In Java. LeagueDriver.java: import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner; public class LeagueDriver {public static void main(String[] args) {Scanner sc = null;try {sc = new Scanner(new File("Players.txt"));} catch (FileNotFoundException e) {System.err.println("No such file");System.exit(-1);} League l = new League();while(sc.hasNext()) {String temp[] = sc.nextLine().split(", ");l.addPlayer(new Player(temp[0],temp[1],Integer.parseInt(temp[2])));}l.printLeague();System.out.println();l.printAverageScore();}} Player.java: public class Player {private String name,team;private int score;public Player(String n,String t,int s) {setName(n);setTeam(t);setScore(s);}/*** @return the name*/public String getName() {return name;}/*** @param name the name to set*/public void setName(String name) {this.name = name;}/*** @return the team*/public String getTeam() {return team;}/*** @param team the team to set*/public void…arrow_forwardThe code below gives the error : Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive at java.base/java.util.Random.nextInt at the line code (arr[i]=rand.nextInt(high-low+1)+low). How to fix this?? public static int[] generateIntArray(int size, int low, int high){ Random rand = new Random(); int[] arr=new int[size]; for(int i=0;i<size;i++){ arr[i]=rand.nextInt(high-low+1)+low; } return arr; } }arrow_forwardObserve the following code and answer the following questions. import java.io.*; import java.net.*; import java.util.Date; public class TimeServer{ public static void main(String args[]) throws Exception{ ServerSocket server = new ServerSocket(9876); while (true){ Socket client = server.accept(); //blocks until a client connects PrintStream ps = new PrintStream( client.getOutputStream() ); ps.println("Time from server:" + new Date()); client.close(); } } } What type of server this is? Is it single or multi-threaded? 2. What should be done according to you if the number of clients to this server increases? Modify the server code so that the increases number of clients can be handled by this server. 3. Explain where in your code you ensured that for every incoming request from a client, a new thread is…arrow_forward
- How to write this code to a Pseudo Code? from threading import Thread, Lockfrom datetime import datetimeimport time # 2shared_resource = ""lock = Lock() # 1modify_readers = Lock();n_readers = 0; # 3fifo_lock = Lock() def wait():time.sleep(2)### def acquire_reader():global n_readers, modify_readers, fifo_lockfifo_lock.acquire()modify_readers.acquire()fifo_lock.release() n_readers += 1;if(n_readers == 1): lock.acquire() modify_readers.release()### def release_reader():global n_readers, modify_readers, fifo_lockmodify_readers.acquire() n_readers -= 1;if(n_readers == 0): lock.release() modify_readers.release()### def write_normal():while True:global shared_resource, fifo_lock fifo_lock.acquire()lock.acquire()fifo_lock.release() print("Writing normal")shared_resource = datetime.now() lock.release()wait()### def write_reverse():while True:global shared_resource, fifo_lock fifo_lock.acquire()lock.acquire()fifo_lock.release() print("Writing reverse")shared_resource = str(datetime.now()…arrow_forwardWhat is the distinction between the static and extern storage classes? Give appropriate examples to back up your response.arrow_forwardWhat is the return type for the method readObject of the classObjectInputStream?arrow_forward
- stdout is not correct In some test cases: exception in thread "main" java.util.NoSuchElementException please fix this code and add a counter. The desired output is given in the picture. Also please add spaces where it belongs import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner; class Name {public Name(String last, String first) {this.last = last;this.first = first;} public Name(String first) {this("", first);} public String getFirst() {return first;} public String getLast() {return last;} public String getFormal() {return first + " " + last;} public String getOfficial() {return last + " " + first;} public String getInitials() {return first.charAt(0) + "_" + last.charAt(0) + "_";} public boolean equals(Name other) {return first.equals(other.first) && last.equals(other.last);} public String toString() {return first + " " + last;} public static Name read(Scanner scanner) {if (!scanner.hasNext())return null;String last =…arrow_forwardExamine the code and write - What is the content of the first 100 characters of text at the end of the program with output? import java.net.MalformedURLException; import java.net.URL;import java.net.URLConnection;import java.io.IOException;import java.util.Scanner;public class Question1 {@SuppressWarnings({ "resource", "unused" })public static void main(String[] args) throws IOException {URLConnection connection = null;try {connection = new URL("http://sun.com").openConnection();} catch (IOException e) {e.printStackTrace();}String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();}}arrow_forwardExamine the following code. import java.net.MalformedURLException; import java.net.URL;import java.net.URLConnection;import java.io.IOException;import java.util.Scanner;public class Question1 {@SuppressWarnings({ "resource", "unused" })public static void main(String[] args) throws IOException {URLConnection connection = null;try {connection = new URL("http://sun.com").openConnection();} catch (IOException e) {e.printStackTrace();}String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();}} What is the content of the first 100 characters of text at the end of the program?arrow_forward
- Examine the following code. import java.net.MalformedURLException; import java.net.URL;import java.net.URLConnection;import java.io.IOException;import java.util.Scanner;public class Question1 {@SuppressWarnings({ "resource", "unused" })public static void main(String[] args) throws IOException {URLConnection connection = null;try {connection = new URL("http://sun.com").openConnection();} catch (IOException e) {e.printStackTrace();}String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();}} a)Describe the data type of each part of the code in the last line of the program.b)What is the content of the first 100 characters of text at the end of the program?arrow_forwardin java Declare a FileOutputStream named outStream and a PrintWriter named dataFS. Ex: If the input is leek.txt 37.5, then leek.txt contains: 37.5 kilograms of leeks 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import java.io.IOException; public class LeekFileOutput { publicstaticvoidmain(String[] args) throwsIOException { Scannerscnr=newScanner(System.in); StringleekFileName; doubleleekQuantity; /* Additional variable declarations go here */ leekFileName=scnr.next(); outStream=newFileOutputStream(leekFileName); dataFS=newPrintWriter(outStream); leekQuantity=scnr.nextDouble(); dataFS.println(leekQuantity+" kilograms of leeks"); dataFS.close(); } }arrow_forwardWhich of the following are true? The Serializable interface has no methods. The Serializable method has been deprecated (fallen into disfavor) because it transmits data as a byte stream. All classes implement the Serializable interface by default. a and b are both true.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education