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: Brief Version (11th Global Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Database Concepts (8th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Degarmo's Materials And Processes In Manufacturing
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
- 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_forwardplease 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_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
- In Java please,arrow_forwardI 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_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_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_forwardOutput??arrow_forward
- Run this program and show the outputarrow_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_forwardJAVA Program ASAP Combine these two program into one so it will the passes the test cases. Converttext.java import java.io.*;import java.util.Scanner;public class ConvertText { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); System.out.println("Please enter the file name or type QUIT to exit:"); while (true) { String input = sc.next(); if (input.equalsIgnoreCase("QUIT")) { break; // Exit the program } else { String filePath = new File("").getAbsolutePath() + "/" + input; File file = new File(filePath); if (file.exists() && !file.isDirectory()) { try (BufferedReader br = new BufferedReader(new FileReader(file))) { String st; StringBuilder formattedText = new StringBuilder(); while ((st = br.readLine()) != null) {…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