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)
- import java.util.Scanner;import java.io.File;import java.io.IOException;public class test2{public static void main(String [] args)throws IOException{File database = new File ("flights.txt");Scanner fileReader = new Scanner( database );Scanner input = new Scanner(System.in);// Displays the welcome screenint menuCheck = 0;String city = "";float oneWayCost = 0f;float roundTripCost = 0f;int numberOfSeats = 0;float total = 0f;while (menuCheck == 0){System.out.println("Welcome TO MEjia AIRLINES.");System.out.println("Please select a choice below [1-5]");System.out.println(" 1. Add flight");System.out.println(" 2. View trip");System.out.println(" 3. Manage Trip");System.out.println(" 4. Checkout");System.out.println(" 5. Exit Mejia airlines");int userInput = input.nextInt();if (userInput == 5){System.out.println("Thank You for using Mejia airlines");System.out.println("Stay safe! Stay Hrydrated! Happy Coding!");menuCheck = -5;}else if (userInput == 1){menuCheck = 1;}else if (userInput ==…arrow_forwardimport java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Scanner;class MyException extends Exception{public MyException(String NegativeArraySizeException){System.out.println("The integer must be in between 1 and 20");}}public class arrayTwo {public static void main(String[]args){Scanner keyboard = new Scanner(System.in);System.out.println("How many integers do you have? (Max 20)");int[] num = new int[keyboard.nextInt()];if(num.length<=0 || num.length>20) {System.out.println("You must enter a number in between 1 and 20");}elsefor (int i = 0; i < num.length; i++) {System.out.println("Enter element for subscript " + i);num[i] = keyboard.nextInt();}System.out.println("Here are all of those numbers");for (int i = 0; i < num.length; i++) {System.out.println(num[i]);}}} attempted to use this code to fix the exception when a negative number is entered by the user, but it still gives back the exception. I would like to know how to…arrow_forwardI need help with fixing this java program as described in the image below: import 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); // Read the file name from the user String fileName = scnr.nextLine(); // Open the CSV file try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) { while (fileScanner.hasNextLine()) { // Read each line from the CSV file String line = fileScanner.nextLine(); // Split the line into showtime, title, and rating String[] movieData = line.split(","); // Extract showtime, title, and rating String showtime = movieData[0]; String title = movieData[1].length() > 44 ? movieData[1].substring(0, 44) : movieData[1]; String rating = movieData[2]; // Print the…arrow_forward
- please help with this code. Code so far: import java.util.Scanner;import java.io.File; Class Authenicator {private final int SIZE = 100;private User() users = new User[SIZE];public Authenticator (String fileName) throws Exception; Scanner sc = new Scanner(new File(fileName));int i = 0;While(sc.hasNext() && i < SIZE) {users[i] = Users.read(sc);i++}} public void authenticate(String username, String password) throws Exception{try {User u = null;for(User X : users) {if(x.getUsername().equals(username) && x.verifyPassword(password){ return ; TASK Implement the following class name Authenticator: State An array of type User (use a capacity of 100 — I would recommend using a class constant the way I did in the 06-Array class of Lecture 2). An integer size Behavior A constructor accepting a file name, that opens a Scanner on the file and reads in User objects A method named authenticate that accepts a username and password and attempts to authenticate them against the…arrow_forward// Program describes two files // tells you which one is newer and which one is larger import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1"); Path file2 = Paths.get("/root/sandbox/DebugDataOne2.txt"); try { BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class); System.out.println("File: " + file1getFileName()); System.out.println("Creation time " + attr1.creationTime()); System.out.println("Last modified time " + attr1lastModifiedTime()); System.out.println("Size " + attr1.size()); BasicFileAttributes attr2 = Files.readAttributes(file2, BasicFileAttributes.class); System.out.println("\nFile: " + file2.getFileName); System.out.println("Creation time " +…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
- 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_forwardCorrect the code: 1. import java.io.File; // Import the File classimport java.io.IOException; // Import the IOException class to handle errorspublic class CreateFile {public static void main(String[] args) {try {File myObj = File("filename.txt");if (myObj.createNewFile() {System.out.println("File created: " + getName());} else {System.out.println("File already exists.");}} catch (IOException) {System.out.println("An error occurred.");}}}Output:File created: filename.txt 2. import java.io.File; // Import the File classimport java.io.FileNotFoundException; // Import this class to handle errorsimport java.util.Scanner; // Import the Scanner class to read text filespublic class ReadFile {public static void main(String[] args) {myObj = new File("filename.txt");Scanner myReader = Scanner(myObj);while (myReader.hasNextLine()) {String data =nextLine();System.out.println(data); 4}myReader.close();catch (e) {System.out.println("An error occurred.");e.printStackTrace();}}}Output:Files in…arrow_forwardPlease verify that the file was created along with the content package pwriter2; import java.util.Scanner; import java.io.*; public class Pwriter2 { public static void main(String[] args) throws IOException { PrintWriter tofile2 = new PrintWriter( "tooutfile2.txt" ); int i = 0; while (i < 10){ tofile2.println( i ); i = i + 1; } tofile2.close(); } }arrow_forward
- package pwriter2; import java.util.Scanner; import java.io.*; public class Pwriter2 { public static void main(String[] args) throws IOException { PrintWriter tofile2 = new PrintWriter( "tooutfile2.txt" ); int i = 0; while (i < 10){ tofile2.println( i ); i = i + 1; } tofile2.close(); } } What is the output?arrow_forwardpackage 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_forwardpublic static void doSomething(String str) { System.out.println(str); } public static void main(String[] args) { try { Scanner fileHandler = new Scanner(new File("file.txt")); while(fileHandler.hasNext()) { doSomething(fileHandler.nextLine()); } }catch(IOException io) { // what happens if the file is not there?? } } Contents of file.txt are: Hello CS 1 I hope you are enjoying, yourself!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