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)
- I need help fixing this java program below: import java.util.Scanner;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.PrintWriter;import java.io.IOException; public class LabProgram { public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); String fileName; String[] lastNames, firstNames; int[] midterm1, midterm2, finalScores; // Read a file name from the user and read the tsv file fileName = scnr.next(); try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) { int numStudents = Integer.parseInt(fileScanner.nextLine()); lastNames = new String[numStudents]; firstNames = new String[numStudents]; midterm1 = new int[numStudents]; midterm2 = new int[numStudents]; finalScores = new int[numStudents]; for (int i = 0; i < numStudents; i++) { lastNames[i] =…arrow_forwardIn javaarrow_forwardimport java.util.Scanner;import java.io.FileInputStream;import java.io.IOException; public class LabProgram { public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); /* Type your code here. */ }}arrow_forward
- package Rayjack_Lab03;import java.util.Scanner;public class RayJack_Lab03 {public static void main(String []args) {Scanner sc= new Scanner(System.in); //System.in is a standard input stream.int firstNum,secondNum;System.out.print("enter first value: ");firstNum=sc.nextInt();System.out.print("enter second value: ");secondNum=sc.nextInt();if (firstNum>=secondNum)System.out.println("It is True to say that first value "+firstNum+" is larger or equal to Second value"+secondNum);elseSystem.out.println("It is False to say that first value "+firstNum+" is larger or equal to Second value "+secondNum);}}Q. Please guide on how to take decimal values in this proggram's output as well.arrow_forwardimport java.util.*;import java.io.FileWriter;import java.io.IOException;public class Main { public static void main(String[] args) throws IOException { //For taking inputs Scanner in = new Scanner(System.in); ArrayList<Integer> daysEntered = new ArrayList<Integer>(); // For storing dangerous reading value int dangerous; // Ask and input the reading that is considered dangerous System.out.print("Enter dangerous reading: "); dangerous = in.nextInt(); // To write in file FileWriter myWriter = new FileWriter("report.txt"); // To store day of the month int day = 1; // To store the three readings in a day int first_reading, second_reading, third_reading; // Loops until user input 0 as day while(day…arrow_forwardcan i have output pleaseimport java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class ScannerFromFileWithCatch { public static void main(String[] args) { try { Scanner in = new Scanner(new File("test.in")); // do somthing if no exception } catch (FileNotFoundException ex) { ex.printStackTrace(); // System.out.println("Hello Exception"); } finally { System.out.println("Thank You !"); } } }arrow_forward
- mport java.nio.file.*;import java.nio.file.attribute.*;import java.io.IOException;public class PathDemo5{ public static void main(String[] args) { Path myPath = Paths.get("C:\\Java\\Input.Output\\MyData.txt"); try { ---------Code here ---------- System.out.println("Creation time " + attr.creationTime()); System.out.println("Last modified time " + attr.lastModifiedTime()); System.out.println("Size " + attr.size()); } catch(IOException e) { System.out.println("IO Exception"); } }}Using the above code, create a statement on the indicated line that uses the readAttributes() method of the Files class that takes two arguments—the Path object created in the code and a BasicFileAttributes.class—and returns an instance of the BasicFileAttributes class named attr.arrow_forwardpackage filterSort;import java.io.File;import java.io.FileNotFoundException;import java.util.Arrays;import java.util.Scanner;import java.util.*; public class FilterSort { /*** Allocates and returns an integer array twice the size of the one* supplied as a parameter. The first half of the new array will* be a copy of the supplied array and the second half of the new* array will be zeros.** @param arr the array to be copied* @return array twice the size of <tt>arr</tt> with its initial* elements copied from <tt>arr</tt>* @throws NullPointerException if <tt>arr</tt> is null.*/public static int[] doubleArrayAndCopy(int[] arr) {int len = arr.length;int max = arr.length * 2;int[] copyArr = Arrays.copyOf(arr,max);int length = copyArr.length-1;Arrays.sort(copyArr, 0, length);return copyArr; } public static void main(String[] args) {int[] data = new int[8];try {File file = new File("data.txt");Scanner myReader = new Scanner(file);for(int i = 0;…arrow_forwardSolution question number 2arrow_forward
- import java.io.*; public class Test RandomAccessFile ( public static void main(String[] args) throws IOException ( try ( RandomAccessFile inout new RandomAccessFile("inout.dat", "rw"); inout.setLength (0); for (int i = 0; i < 200; i++) inout.writeInt(i); System.out.println("Current file length is " + inout.length()); inout. seek (0); System.out.println("The first number is " + inout.readInt ()); inout.seek (1 * 4); System.out.println("The second number is " + inout.readInt ()); inout.seek (9 * 4); System.out.println("The tenth number is " + inout.readInt ()); inout.writeInt (555); inout.seek (inout.length()); inout.write Int (999); System.out.println("The new length is " + inout.length()); inout. seek (10 * 4); System.out.println("The eleventh number is " + inout.readInt ()); Output:arrow_forwardimport java.util.Scanner;import java.util.InputMismatchException; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); /* Type your code here. */ }}arrow_forwardpackage encrypt1; import java.io.*;import java.util.*; public class Encrypt1 { public static void main(String[] args) { if(args.length!2) ERROR MESSAGE { System.out.println("Invalid number of argumentss. Usage:src target"); } try { BufferedInputStream in = new BufferedInputStream (new FileInputStream(args[0])); // Create BufferedOutputStream from bos BufferedOutputStream out = new BufferedOutputStream (new FileOutputStream(args[1])); // Declare the variable num int buffer; // Checks content in the variable num is not equal to -1 while ((buffer=in.read())!=-1) { // Call the function Write() out.write(buffer+5); } System.out.println("Encrypted file saved"); } catch(IOException ex) { ex.printStackTrace(); }}}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