Deck 7: Inputoutput and Exception Handling

ملء الشاشة (f)
exit full mode
سؤال
The PrintWriter class is an enhancement of the ____ class.

A) Scanner
B) ReadStream
C) PrintStream
D) File
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Consider the following code snippet.
File hoursFile = new File("hoursWorked.txt");
Your program must read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

A) Scanner in = new Scanner("hoursWorked.txt");
B) Scanner in = Scanner("hoursWorked.txt");
C) Scanner in = new Scanner(hoursFile);
D) Scanner in = Scanner.open(hoursFile);
سؤال
Under which condition will the Scanner constructor generate a FileNotFoundException?

A) If the input file cannot be opened due to a security error.
B) If the input file does not exist.
C) If the input file already exists, but has data in it.
D) If the input file already exists, but is empty.
سؤال
Consider the following code snippet:
PrintWriter out = new PrintWriter("output.txt");
Which of the following statements about the PrintWriter object is correct?

A) If a file named "output.txt" already exists, an exception will occur.
B) If a file named "output.txt" already exists, data will be added at the end of the file.
C) If a file named "output.txt" already exists, existing data will be deleted before data are added to the file.
D) If a file named "output.txt" already exists, a new file named "output_1.txt" will be created and used.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = _________________;
Scanner in = new Scanner(inputFile)
) . .
}

A) new File(inputFileName)
B) new File(outputFileName)
C) new File(inputFile)
D) new File(System.in)
سؤال
Which of the following statements reflects the textbook's recommendations about closing files?

A) Both the input and the output file do not need to be explicitly closed in the program.
B) Only the input file must be explicitly closed in the program.
C) Only the output file must be explicitly closed in the program.
D) Both the input and the output file should be explicitly closed in the program.
سؤال
Which of the following is the correct syntax for creating a File object?

A) File inFile = File("input.txt")
B) File inFile = new File("input.txt")
C) File inFile = File.open("input.txt")
D) File inFile = new File.open("input.txt")
سؤال
Under which condition will the PrintWriter constructor generate a FileNotFoundException?

A) If the output file cannot be opened or created due to a security error.
B) If the output file does not exist.
C) If the output file already exists, but has data in it.
D) If the output file already exists, but is empty.
سؤال
Which of the following statements about using the PrintWriter object is correct?

A) If the output file already exists, the new data will be appended to the end of the file.
B) If the output file does not exist, a FileNotFoundException will occur.
C) If the output file already exists, the existing data will be discarded before new data are written into the file.
D) If the output file does not exist, an IllegalArgumentException will occur.
سؤال
Which of the following objects should be used for reading from a text file?

A) Scanner
B) ReadStream
C) PrintStream
D) ReadFile
سؤال
Your program will read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?

A) public static void main(String[] args) throws FileMissingException
B) public static void main(String[] args) throws FileNotFoundException
C) public static void main(String[] args)
D) public static void main(String[] args) throws UnknownFileException
سؤال
Consider the following code snippet:
Public static void main(String[] args) throws IOException
Which of the following statements about this code is correct?

A) The main method is designed to catch and handle all types of exceptions.
B) The main method is designed to catch and handle the IOException.
C) The main method should simply terminate if the IOException occurs.
D) The main method will not terminate if any exception occurs.
سؤال
Consider the following code snippet:
File inputFile = new File("input.txt");
You wish to read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

A) Scanner in = Scanner ("input.txt")
B) Scanner in = new Scanner ("input.txt")
C) Scanner in = Scanner.open(inputFile)
D) Scanner in = new Scanner(inputFile)
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read an input file.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = new File(inputFileName);
Scanner in = _______________;
) . .
}

A) new Scanner(inputFileName)
B) new Scanner(outputFileName)
C) new Scanner(inputFile)
D) new Scanner(System.in)
سؤال
Which of the following statements about reading and writing text files is correct?

A) You use the Scanner class to read and write text files.
B) You use the PrintWriter class to read and write text files.
C) You use the Scanner class to read text files and the PrintWriter class to write text files.
D) You use the Scanner class to write text files and the PrintWriter class to read text files.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read a file and write to a file.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = _____________;
) . .
}

A) new PrintWriter(outputFileName)
B) new Scanner(outputFileName)
C) new PrintWriter(outputFile)
D) new Scanner(outputFile)
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = new File(inputFileName);
Scanner in = _________;
) . .
}

A) new File(inputFileName)
B) new File("dataIn.txt")
C) new Scanner(inputFile)
D) new Scanner("dataIn.txt")
سؤال
Which of the following statements about a PrintWriter object is true?

A) A PrintWriter will be automatically closed when the program exits.
B) Data loss may occur if a program fails to close a PrintWriter object before exiting.
C) No data loss will occur if the program fails to close a PrintWriter before exiting.
D) An exception will occur if the program fails to close a PrintWriter before exiting.
سؤال
Consider the following code snippet:
Public static void main(String[] args) throws FileNotFoundException
Which of the following statements about this code is correct?

A) The main method is designed to catch and handle all types of exceptions.
B) The main method is designed to catch and handle the FileNotFoundException.
C) The main method should simply terminate if the FileNotFoundException occurs.
D) The main method will not terminate if any exception occurs.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read an input file.
Public static void main(String[] args) __________________
{
String inputFileName = "dataIn.txt";
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
) . .
}

A) extends FileNotFoundException
B) throws FileNotFoundException
C) inherits FileNotFoundException
D) catches FileNotFoundException
سؤال
Which of the following statements about using a PrintWriter object is NOT true?

A) A PrintWriter will be automatically closed when the program exits.
B) Data loss may occur if a program fails to close a PrintWriter object before exiting.
C) PrintWriter is an enhancement of the PrintStream class.
D) A program can write to a PrintWriter using println.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt that resides in a folder named payroll on the C: drive of a Windows system.
Public static void main(String[] args) throws FileNotFoundException
{
File inputFile = ________;
Scanner in = new Scanner(inputFile);
) . .
}

A) new File(c:/payroll/"dataIn.txt")
B) new File(c://payroll//"dataIn.txt")
C) new File("c:\payroll\dataIn.txt")
D) new File("c:\\payroll\\dataIn.txt")
سؤال
Consider the following code snippet.
Scanner inputFile = new Scanner("hoursWorked.txt");
Which of the following statements is correct?

A) This code will treat the string "hoursWorked.txt" as an input value.
B) This code will create a new file named "hoursWorked.txt".
C) This code will open an existing file named "hoursWorked.txt" for reading.
D) This code will open a file named "hoursWorked.txt" for writing.
سؤال
Consider the following code snippet.
PrintWriter outFile = new PrintWriter("dataOut.txt");
Which of the following statements about the PrintWriter object is correct?

A) If a file named "dataOut.txt" already exists, an exception will occur.
B) If a file named "dataOut.txt" already exists, existing data will be deleted before new data is added to the file.
C) If a file named "dataOut.txt" already exists, new data will be added to the end of the file.
D) If a file named "dataOut.txt" already exists, a new file named "dataOut_1.txt" will be created and used.
سؤال
Your program wishes to open a file named C:\java\myProg\input.txt on a Windows system. Which of the following is the correct code to do this?

A) inputFile = new File("c:\java\myProg\input.txt");
B) inputFile = new File.open("c:\java\myProg\input.txt");
C) inputFile = new File("c:\\java\\myProg\\input.txt");
D) inputFile = new File.open("c:\\java\\myProg\\input.txt");
سؤال
Insert the missing code in the following code fragment. This fragment is intended to write an output file named dataOut.txt that resides in a folder named reports on the C: drive of a Windows system.
Public static void main(String[] args) throws IOException
{
PrintWriter outputFile = _______;
) . .
}

A) new PrintWriter("c:/reports/dataOut.txt")
B) new PrintWriter("c://reports//dataOut.txt")
C) new PrintWriter("c:\reports\dataOut.txt")
D) new PrintWriter("c:\\reports\\dataOut.txt")
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read an input file named hoursWorked.txt. You want the program to terminate if the file does not exist.
Public static void main(String[] args) ______________
{
File inputFile = new File("hoursWorked.txt");
Scanner in = new Scanner(inputFile);
) . .
}

A) catch FileMissingException
B) catch FileNotFoundException
C) throws FileMissingException
D) throws FileNotFoundException
سؤال
Your program must read in an existing text file. You want the program to terminate if any exception related to the file occurs. Which of the following indicates the correct code for the main method?

A) public static void main(String[] args) throws IOException
B) public static void main(String[] args) throws FileNotFoundException
C) public static void main(String[] args)
D) public static void main(String[] args) throws UnknownFileException
سؤال
Which method of the JFileChooser object will return the file object that describes the file chosen by the user at runtime?

A) getFile()
B) getSelectedFilePath()
C) getSelectedFile()
D) getFilePath()
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read binary data.
Public static void main(String[] args) throws IOException
{
String address = "http://horstmann.com/bigjava.gif";
URL imageLocation = _________;
InputStream in = imageLocation.openStream());
) . .
}

A) new Scanner("http://horstmann.com/bigjava.gif")
B) new Scanner(address)
C) new imageLocation.openStream
D) new URL(address)
سؤال
Which return value of the JFileChooser object's showOpenDialog method indicates that a file was chosen by the user at run time?

A) APPROVE_OPTION
B) CANCEL_OPTION
C) OK_OPTION
D) SELECTED_OPTION
سؤال
Consider the following code snippet.
Scanner inputFile = new Scanner("dataIn.txt");
Which of the following statements is correct?

A) This code will not open a file named "dataIn.txt", but will treat the string "dataIn.txt" as an input value.
B) This code will create a new file named "dataIn.txt".
C) This code will open an existing file named "dataIn.txt" for reading.
D) This code will open a file named "dataIn.txt" for writing.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read a web page.
Public static void main(String[] args) throws IOException
{
String address = "http://horstmann.com/index.html";
URL pageLocation = new URL(address);
Scanner in = _________;
) . .
}

A) new Scanner("http://horstmann.com/index.html")
B) new Scanner(pageLocation)
C) new Scanner(new File(pageLocation))
D) new Scanner(pageLocation.openStream())
سؤال
Which Java class implements a file dialog box for selecting a file by a program with a graphical user interface?

A) JOptionPane
B) JFileOption
C) JFilePane
D) JFileChooser
سؤال
Which of the following statements about reading web pages is true?

A) A Scanner object cannot be used to read a web page.
B) You must create a File object to use with a Scanner object to read a web page.
C) You must create a URL object to use with a Scanner object to read a web page.
D) You must use the openStream() method of a Scanner object to read a web page.
سؤال
Your program must read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?

A) public static void main(String[] args) throws FileMissingException
B) public static void main(String[] args) throws FileNotFoundException
C) public static void main(String[] args)
D) public static void main(String[] args) throws UnknownFileException
سؤال
Which of the following statements about reading and writing binary data is correct?

A) You use the Scanner class to read and write binary data.
B) You use the PrintWriter class to read and write binary data.
C) You use the InputStream class to read binary data and the FileOutputStream class to write binary data.
D) You use the InputStream class to write binary data and the FileOutputStream class to read binary data.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read binary data.
Public static void main(String[] args) throws IOException
{
String address = "http://horstmann.com/bigjava.gif";
URL imageLocation = new URL(address);
InputStream in = _________;
) . .
}

A) new Scanner("http://horstmann.com/bigjava.gif")
B) new Scanner(imageLocation)
C) new imageLocation.openStream
D) imageLocation.openStream()
سؤال
Consider the following code snippet.
PrintWriter outputFile = new PrintWriter("payrollReport.txt");
Which of the following statements about the PrintWriter object is correct?

A) If a file named "payrollReport.txt" already exists, an exception will occur.
B) If a file named "payrollReport.txt" already exists, existing data will be deleted before new data is added to the file.
C) If a file named "payrollReport.txt" already exists, new data will be added to the end of the file.
D) If a file named "payrollReport.txt" already exists, a new file named "payrollReport_1.txt" will be created and used.
سؤال
Insert the missing code in the following code fragment. This fragment is intended to allow the user to select a file to be opened.
JFileChooser chooser = new JFileChooser();
Scanner in = null;
If (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
File selectedFile = __________;
In = new Scanner(selectedFile);
) . .
}

A) chooser.getFileName()
B) chooser.getSelectedFileName()
C) chooser.getFilePath()
D) chooser.getSelectedFile()
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read all words from a text file.
File inputFile = new File("dataIn.txt");
Scanner in = new Scanner(dataIn.txt);
While (____________)
{
String input = in.next();
System.out.println(input);
}

A) in.getNext()
B) in.peek()
C) in.hasNext()
D) in.nextWord()
سؤال
Which of the following patterns should be used for the delimiter to read one character at a time using a Scanner object's next method?

A) Scanner in = new Scanner(. . .);
In)useDelimiter("[^A-Za-z]+");
B) Scanner in = new Scanner(. . .);
In)useDelimiter("[A-Za-z]+");
C) Scanner in = new Scanner(. . .);
In)useDelimiter("[^0-9]+");
D) Scanner in = new Scanner(. . .);
In)useDelimiter("");
سؤال
Which of the following statements about white space in Java is correct?

A) In Java, white space includes spaces only.
B) In Java, white space includes spaces and tab characters only.
C) In Java, white space includes spaces, tab characters, and newline characters.
D) In Java, white space includes spaces, tab characters, newline characters, and punctuation.
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
While (in.hasNextInt())
{
) . .
}
Under which condition will the body of the while loop be processed?

A) When an integer value is encountered in the input.
B) When a non-integer value is encountered in the input.
C) When an alphabetic value is encountered in the input.
D) When any numeric value is encountered in the input.
سؤال
When reading words using a Scanner object's next method, ____.

A) any characters at the beginning of the input that are considered to be white space are consumed and become part of the word being read.
B) any characters at the beginning of the input that are considered to be white space are consumed and do not become part of the word being read.
C) the program must discard white space characters at the beginning of the input before calling the next method.
D) any characters that are considered to be white space within the word become part of the word.
سؤال
Consider the following code snippet.
File inputFile = new File("dataIn.txt");
Scanner in = new Scanner(inputFile);
While (in.hasNext())
{
String input = in.next();
}
Which of the following statements about this code is correct?

A) This code will read in a word at a time from the input file.
B) This code will read in the entire input file in one operation.
C) This code will read in a line at a time from the input file.
D) This code will read in a character at a time from the input file.
سؤال
The ____ method of the Character class will indicate if a character contains white space.

A) isValid()
B) getChar()
C) hasNext()
D) isWhiteSpace()
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read floating-point numbers from a text file.
Scanner in = new Scanner(. . .);
While (____________)
{
Double hoursWorked = in.nextDouble();
System.out.println(hoursWorked);
}

A) in.getNextDouble()
B) in.peek()
C) in.hasNextDouble()
D) in.readNextWord()
سؤال
Insert the missing code in the following code fragment. This fragment is intended to read characters from a text file.
Scanner in = new Scanner(. . .);
In)useDelimiter("");
While (in.hasNext())
{
Char ch = ____________;
System.out.println(ch);
}

A) in.getNext()
B) in.next()
C) in.next.charAt(0)
D) in.nextChar()
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[^0-9]+");
What characters will be ignored and not read in using this code?

A) Only alphabetic characters will be ignored.
B) Only numeric characters will be ignored.
C) Only non-alphabetic characters will be ignored.
D) Only non-numeric characters will be ignored.
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
While (in.hasNextLine())
{
String input = in.nextLine();
System.out.println(input);
}
Which of the following statements about this code is correct?

A) This code will read in an entire line from the file in each iteration of the loop.
B) This code will read in the entire contents of the file in a single iteration of the loop.
C) This code will read in a single word from the file in each iteration of the loop.
D) This code will read in a single character from the file in each iteration of the loop.
سؤال
Which String class method will remove spaces from the beginning and the end of a string?

A) truncate()
B) trim()
C) clean()
D) strip()
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[^0-9A-Za-z]+");
What characters will be ignored and not read in using this code?

A) Only alphabetic characters will be ignored.
B) Only numeric characters will be ignored.
C) Characters that are neither alphabetic nor numeric will be ignored.
D) Both alphabetic and numeric characters will be ignored.
سؤال
Consider the following code snippet.
Scanner in = new Scanner(. . .);
While (in.hasNextDouble())
{
Double input = in.nextDouble();
}
Which of the following statements about this code is correct?

A) This code will read in one word at a time from the input file.
B) This code will read in the entire input file in one operation.
C) This code will read in one floating point value at a time from the input file.
D) This code will read in one character at a time from the input file.
سؤال
The Scanner class's ____ method is used to specify a pattern for word boundaries when reading text.

A) useDelimiter()
B) usePattern()
C) setDelimiter()
D) setPattern()
سؤال
When reading words with a Scanner object, a word is defined as ____.

A) Any sequence of characters consisting of letters only.
B) Any sequence of characters consisting of letters, numbers, and punctuation symbols only.
C) Any sequence of characters consisting of letters and numbers only.
D) Any sequence of characters that is not white space.
سؤال
Consider the following code snippet.
Scanner in = new Scanner(. . .);
While (in.hasNextLine())
{
String input = in.nextLine();
}
Which of the following statements about this code is correct?

A) This code will read in a word at a time from the input file.
B) This code will read in the entire input file in one operation.
C) This code will read in a line at a time from the input file.
D) This code will read in a character at a time from the input file.
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
Int ageValue = in.nextInt();
If there is no integer number appearing next in the input, what will occur?

A) ageValue will contain a null value.
B) ageValue will contain a zero.
C) ageValue will contain whatever characters are encountered.
D) An exception will occur.
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
While (in.hasNextInt())
{
) . .
}
Under which condition will the body of the while loop be processed?

A) When an integer value is encountered in the input.
B) When a non-integer value is encountered in the input.
C) When any numeric value is encountered in the input.
D) When any type of value is encountered in the input.
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[^A-Za-z]+");
What characters will be ignored and not read in when using this code?

A) Only alphabetic characters will be ignored.
B) Only numeric characters will be ignored.
C) Only non-alphabetic characters will be ignored.
D) Only non-numeric characters will be ignored.
سؤال
Consider the following code snippet:
Throw new IllegalArgumentException("This operation is not allowed!");
Which of the following statements about this code is correct?

A) This code constructs an object of type IllegalArgumentException and throws the object.
B) This code throws an existing IllegalArgumentException object.
C) This code constructs an object of type IllegalArgumentException and reserves it for future use.
D) This code will not compile.
سؤال
In the hierarchy of Exception classes, the NumberFormatException class is a subclass of the ____ class.

A) ArithmeticException.
B) ClassCastException.
C) IllegalArgumentException.
D) IllegalStateException.
سؤال
Which statement about handling exceptions is true?

A) If an exception has no handler, the error will be ignored.
B) Statements that may cause exceptions should be placed inside a catch clause.
C) Statements to handle exceptions should be placed inside a try clause
D) If an exception has no handler, the program will be terminated.
سؤال
Which method of an exception object will provide information about the chain of method calls that led to the exception?

A) printCallStack()
B) getCallStack()
C) printStackTrace()
D) getStackTrace()
سؤال
Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found.
Try
{
String filename = . . .;
Scanner in = new Scanner(new File(filename));
) . .
}
___________________
{
Exception.printStackTrace();
}

A) catch (IOException exception)
B) catch (new exception (IOException))
C) catch (IllegalArgumentException exception)
D) catch (IOException)
سؤال
When you start a Java program from a command line and supply argument values, the values ____.

A) are stored as int values
B) are stored as float values
C) are stored as String values
D) are stored as the type of value indicated by the argument
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
String result = "";
Int number = 0;
If (in.hasNextInt())
{
Number = in.nextInt();
}
Result = in.next();
If the input begins with the characters 626.14 average, what values will number and result have after this code is executed?

A) number will contain the value 626 and result will contain the value 14.
B) number will contain the value 626.14 and result will contain the value average.
C) number will contain the value 0 and result will contain the value 626.14.
D) number will contain the value 0 and result will contain the value average.
سؤال
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[A-Za-z]+");
What characters will be read in using this code?

A) Only alphabetic characters will be read in.
B) Only numeric characters will be read in.
C) Only non-alphabetic characters will be read in.
D) Only non-numeric characters will be read in.
سؤال
Consider the following code snippet:
System.out.printf("%-12s%8.2f",description,totalPrice);
Which of the following statements is correct?

A) This code will produce 2 columns, with the description field left justified and the totalPrice field right justified.
B) This code will produce 2 columns, with the description field right justified and the totalPrice field right justified.
C) This code will produce 2 columns, with the description field right justified and the totalPrice field left justified.
D) This code will produce 2 columns, with the description field left justified and the totalPrice field left justified.
سؤال
Consider the following code snippet:
If (in.hasNextDouble())
{
Number = in.nextDouble();
}
Result = in.next();
If the input contains the characters 626.14 average, what values will number and result have after this code is executed?

A) number will contain the value 626 and result will contain the value 14.
B) number will contain the value 626.14 and result will contain the value average.
C) number will contain the value 0 and result will contain the value 626.14.
D) number will contain the value 0 and result will contain the value average.
سؤال
Which of the following statements about exception handling is correct?

A) Statements that may cause an exception should be placed within a catch block.
B) The main method of a Java program will handle any error encountered in the program.
C) Statements that may cause an exception should be placed within a throws block.
D) Statements that may cause an exception should be placed within a try block.
سؤال
Consider the following code snippet:
Throw IllegalStateException("This operation is not allowed!");
Which of the following statements about this code is correct?

A) This code constructs an object of type IllegalArgumentException and throws the object.
B) This code throws an existing IllegalArgumentException object.
C) This code constructs an object of type IllegalArgumentException and reserves it for future use.
D) This code will not compile.
سؤال
Which method of an exception object will retrieve a description of the exception that occurred?

A) printStackTrace()
B) printMessage()
C) getMessage()
D) getDescription()
سؤال
Which of the following statements about command line arguments is correct?

A) Command line arguments must be read with a Scanner object.
B) You must declare additional parameters in the main method to receive command line argument values.
C) You cannot pass arguments to a program when starting the program from a command line prompt.
D) Command line arguments can be read using the main method's args parameter.
سؤال
Which of the following is the correct syntax for starting a Java program named myProg from a command line if the program requires two arguments named arg1 and arg2 to be supplied?

A) java myProg arg1 arg2
B) java myProg(arg1, arg2)
C) java myProg "arg1" "arg2"
D) java myProg arg1, arg2
سؤال
You have opened a command prompt window and you have entered the following:
Java myProg Bob Smith
Which of the following statements is correct?

A) You have supplied one argument value, and this value can be accessed in the main method using the arg1 parameter.
B) You have supplied two argument values, and these values can be accessed in the main method using the arg1 and arg2 parameters.
C) You have supplied one argument value, and this value can be accessed in the main method using the args parameter.
D) You have supplied two argument values, and these values can be accessed in the main method using the args parameter.
سؤال
Which of the following statements about exception reporting is true?

A) Use the reportError statement to report that an exception has occurred.
B) Use the reportException statement to report that an exception has occurred.
C) Use the throwException statement to report that an exception has occurred.
D) Use the throw statement to report that an exception has occurred.
سؤال
What is the purpose of the throw statement?

A) It is used to pass arguments to another method.
B) It is used to detect an error situation.
C) It is used to pass control to an error handler when an error situation is detected.
D) It is used to discard erroneous input.
سؤال
You wish to use the Scanner class's nextInt() method to read in whole numbers. To avoid exceptions that would occur if the input is not a whole number, you should use the ____ method before calling nextInt.

A) hasNext()
B) hasNextInteger()
C) hasIntegerValue()
D) hasNextInt()
سؤال
Which of the following statements about checked and unchecked exceptions is true?

A) Checked exceptions are handled by the Java runtime.
B) The compiler ensures that the program is handling unchecked exceptions.
C) The compiler ensures that the program is handling checked exceptions.
D) All exceptions that are descendants of RunTimeException are checked exceptions.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/100
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 7: Inputoutput and Exception Handling
1
The PrintWriter class is an enhancement of the ____ class.

A) Scanner
B) ReadStream
C) PrintStream
D) File
C
2
Consider the following code snippet.
File hoursFile = new File("hoursWorked.txt");
Your program must read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

A) Scanner in = new Scanner("hoursWorked.txt");
B) Scanner in = Scanner("hoursWorked.txt");
C) Scanner in = new Scanner(hoursFile);
D) Scanner in = Scanner.open(hoursFile);
C
3
Under which condition will the Scanner constructor generate a FileNotFoundException?

A) If the input file cannot be opened due to a security error.
B) If the input file does not exist.
C) If the input file already exists, but has data in it.
D) If the input file already exists, but is empty.
B
4
Consider the following code snippet:
PrintWriter out = new PrintWriter("output.txt");
Which of the following statements about the PrintWriter object is correct?

A) If a file named "output.txt" already exists, an exception will occur.
B) If a file named "output.txt" already exists, data will be added at the end of the file.
C) If a file named "output.txt" already exists, existing data will be deleted before data are added to the file.
D) If a file named "output.txt" already exists, a new file named "output_1.txt" will be created and used.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
5
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = _________________;
Scanner in = new Scanner(inputFile)
) . .
}

A) new File(inputFileName)
B) new File(outputFileName)
C) new File(inputFile)
D) new File(System.in)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
6
Which of the following statements reflects the textbook's recommendations about closing files?

A) Both the input and the output file do not need to be explicitly closed in the program.
B) Only the input file must be explicitly closed in the program.
C) Only the output file must be explicitly closed in the program.
D) Both the input and the output file should be explicitly closed in the program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following is the correct syntax for creating a File object?

A) File inFile = File("input.txt")
B) File inFile = new File("input.txt")
C) File inFile = File.open("input.txt")
D) File inFile = new File.open("input.txt")
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
8
Under which condition will the PrintWriter constructor generate a FileNotFoundException?

A) If the output file cannot be opened or created due to a security error.
B) If the output file does not exist.
C) If the output file already exists, but has data in it.
D) If the output file already exists, but is empty.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
9
Which of the following statements about using the PrintWriter object is correct?

A) If the output file already exists, the new data will be appended to the end of the file.
B) If the output file does not exist, a FileNotFoundException will occur.
C) If the output file already exists, the existing data will be discarded before new data are written into the file.
D) If the output file does not exist, an IllegalArgumentException will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following objects should be used for reading from a text file?

A) Scanner
B) ReadStream
C) PrintStream
D) ReadFile
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
11
Your program will read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?

A) public static void main(String[] args) throws FileMissingException
B) public static void main(String[] args) throws FileNotFoundException
C) public static void main(String[] args)
D) public static void main(String[] args) throws UnknownFileException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
12
Consider the following code snippet:
Public static void main(String[] args) throws IOException
Which of the following statements about this code is correct?

A) The main method is designed to catch and handle all types of exceptions.
B) The main method is designed to catch and handle the IOException.
C) The main method should simply terminate if the IOException occurs.
D) The main method will not terminate if any exception occurs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
13
Consider the following code snippet:
File inputFile = new File("input.txt");
You wish to read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?

A) Scanner in = Scanner ("input.txt")
B) Scanner in = new Scanner ("input.txt")
C) Scanner in = Scanner.open(inputFile)
D) Scanner in = new Scanner(inputFile)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
14
Insert the missing code in the following code fragment. This fragment is intended to read an input file.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = new File(inputFileName);
Scanner in = _______________;
) . .
}

A) new Scanner(inputFileName)
B) new Scanner(outputFileName)
C) new Scanner(inputFile)
D) new Scanner(System.in)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
15
Which of the following statements about reading and writing text files is correct?

A) You use the Scanner class to read and write text files.
B) You use the PrintWriter class to read and write text files.
C) You use the Scanner class to read text files and the PrintWriter class to write text files.
D) You use the Scanner class to write text files and the PrintWriter class to read text files.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
16
Insert the missing code in the following code fragment. This fragment is intended to read a file and write to a file.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = _____________;
) . .
}

A) new PrintWriter(outputFileName)
B) new Scanner(outputFileName)
C) new PrintWriter(outputFile)
D) new Scanner(outputFile)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
17
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt.
Public static void main(String[] args) throws FileNotFoundException
{
String inputFileName = "dataIn.txt";
String outputFileName = "dataOut.txt";
File inputFile = new File(inputFileName);
Scanner in = _________;
) . .
}

A) new File(inputFileName)
B) new File("dataIn.txt")
C) new Scanner(inputFile)
D) new Scanner("dataIn.txt")
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following statements about a PrintWriter object is true?

A) A PrintWriter will be automatically closed when the program exits.
B) Data loss may occur if a program fails to close a PrintWriter object before exiting.
C) No data loss will occur if the program fails to close a PrintWriter before exiting.
D) An exception will occur if the program fails to close a PrintWriter before exiting.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
19
Consider the following code snippet:
Public static void main(String[] args) throws FileNotFoundException
Which of the following statements about this code is correct?

A) The main method is designed to catch and handle all types of exceptions.
B) The main method is designed to catch and handle the FileNotFoundException.
C) The main method should simply terminate if the FileNotFoundException occurs.
D) The main method will not terminate if any exception occurs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
20
Insert the missing code in the following code fragment. This fragment is intended to read an input file.
Public static void main(String[] args) __________________
{
String inputFileName = "dataIn.txt";
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
) . .
}

A) extends FileNotFoundException
B) throws FileNotFoundException
C) inherits FileNotFoundException
D) catches FileNotFoundException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which of the following statements about using a PrintWriter object is NOT true?

A) A PrintWriter will be automatically closed when the program exits.
B) Data loss may occur if a program fails to close a PrintWriter object before exiting.
C) PrintWriter is an enhancement of the PrintStream class.
D) A program can write to a PrintWriter using println.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
22
Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt that resides in a folder named payroll on the C: drive of a Windows system.
Public static void main(String[] args) throws FileNotFoundException
{
File inputFile = ________;
Scanner in = new Scanner(inputFile);
) . .
}

A) new File(c:/payroll/"dataIn.txt")
B) new File(c://payroll//"dataIn.txt")
C) new File("c:\payroll\dataIn.txt")
D) new File("c:\\payroll\\dataIn.txt")
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
23
Consider the following code snippet.
Scanner inputFile = new Scanner("hoursWorked.txt");
Which of the following statements is correct?

A) This code will treat the string "hoursWorked.txt" as an input value.
B) This code will create a new file named "hoursWorked.txt".
C) This code will open an existing file named "hoursWorked.txt" for reading.
D) This code will open a file named "hoursWorked.txt" for writing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
24
Consider the following code snippet.
PrintWriter outFile = new PrintWriter("dataOut.txt");
Which of the following statements about the PrintWriter object is correct?

A) If a file named "dataOut.txt" already exists, an exception will occur.
B) If a file named "dataOut.txt" already exists, existing data will be deleted before new data is added to the file.
C) If a file named "dataOut.txt" already exists, new data will be added to the end of the file.
D) If a file named "dataOut.txt" already exists, a new file named "dataOut_1.txt" will be created and used.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
25
Your program wishes to open a file named C:\java\myProg\input.txt on a Windows system. Which of the following is the correct code to do this?

A) inputFile = new File("c:\java\myProg\input.txt");
B) inputFile = new File.open("c:\java\myProg\input.txt");
C) inputFile = new File("c:\\java\\myProg\\input.txt");
D) inputFile = new File.open("c:\\java\\myProg\\input.txt");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
26
Insert the missing code in the following code fragment. This fragment is intended to write an output file named dataOut.txt that resides in a folder named reports on the C: drive of a Windows system.
Public static void main(String[] args) throws IOException
{
PrintWriter outputFile = _______;
) . .
}

A) new PrintWriter("c:/reports/dataOut.txt")
B) new PrintWriter("c://reports//dataOut.txt")
C) new PrintWriter("c:\reports\dataOut.txt")
D) new PrintWriter("c:\\reports\\dataOut.txt")
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
27
Insert the missing code in the following code fragment. This fragment is intended to read an input file named hoursWorked.txt. You want the program to terminate if the file does not exist.
Public static void main(String[] args) ______________
{
File inputFile = new File("hoursWorked.txt");
Scanner in = new Scanner(inputFile);
) . .
}

A) catch FileMissingException
B) catch FileNotFoundException
C) throws FileMissingException
D) throws FileNotFoundException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
28
Your program must read in an existing text file. You want the program to terminate if any exception related to the file occurs. Which of the following indicates the correct code for the main method?

A) public static void main(String[] args) throws IOException
B) public static void main(String[] args) throws FileNotFoundException
C) public static void main(String[] args)
D) public static void main(String[] args) throws UnknownFileException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
29
Which method of the JFileChooser object will return the file object that describes the file chosen by the user at runtime?

A) getFile()
B) getSelectedFilePath()
C) getSelectedFile()
D) getFilePath()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
30
Insert the missing code in the following code fragment. This fragment is intended to read binary data.
Public static void main(String[] args) throws IOException
{
String address = "http://horstmann.com/bigjava.gif";
URL imageLocation = _________;
InputStream in = imageLocation.openStream());
) . .
}

A) new Scanner("http://horstmann.com/bigjava.gif")
B) new Scanner(address)
C) new imageLocation.openStream
D) new URL(address)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which return value of the JFileChooser object's showOpenDialog method indicates that a file was chosen by the user at run time?

A) APPROVE_OPTION
B) CANCEL_OPTION
C) OK_OPTION
D) SELECTED_OPTION
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
32
Consider the following code snippet.
Scanner inputFile = new Scanner("dataIn.txt");
Which of the following statements is correct?

A) This code will not open a file named "dataIn.txt", but will treat the string "dataIn.txt" as an input value.
B) This code will create a new file named "dataIn.txt".
C) This code will open an existing file named "dataIn.txt" for reading.
D) This code will open a file named "dataIn.txt" for writing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
33
Insert the missing code in the following code fragment. This fragment is intended to read a web page.
Public static void main(String[] args) throws IOException
{
String address = "http://horstmann.com/index.html";
URL pageLocation = new URL(address);
Scanner in = _________;
) . .
}

A) new Scanner("http://horstmann.com/index.html")
B) new Scanner(pageLocation)
C) new Scanner(new File(pageLocation))
D) new Scanner(pageLocation.openStream())
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which Java class implements a file dialog box for selecting a file by a program with a graphical user interface?

A) JOptionPane
B) JFileOption
C) JFilePane
D) JFileChooser
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which of the following statements about reading web pages is true?

A) A Scanner object cannot be used to read a web page.
B) You must create a File object to use with a Scanner object to read a web page.
C) You must create a URL object to use with a Scanner object to read a web page.
D) You must use the openStream() method of a Scanner object to read a web page.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
36
Your program must read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?

A) public static void main(String[] args) throws FileMissingException
B) public static void main(String[] args) throws FileNotFoundException
C) public static void main(String[] args)
D) public static void main(String[] args) throws UnknownFileException
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
37
Which of the following statements about reading and writing binary data is correct?

A) You use the Scanner class to read and write binary data.
B) You use the PrintWriter class to read and write binary data.
C) You use the InputStream class to read binary data and the FileOutputStream class to write binary data.
D) You use the InputStream class to write binary data and the FileOutputStream class to read binary data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
38
Insert the missing code in the following code fragment. This fragment is intended to read binary data.
Public static void main(String[] args) throws IOException
{
String address = "http://horstmann.com/bigjava.gif";
URL imageLocation = new URL(address);
InputStream in = _________;
) . .
}

A) new Scanner("http://horstmann.com/bigjava.gif")
B) new Scanner(imageLocation)
C) new imageLocation.openStream
D) imageLocation.openStream()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
39
Consider the following code snippet.
PrintWriter outputFile = new PrintWriter("payrollReport.txt");
Which of the following statements about the PrintWriter object is correct?

A) If a file named "payrollReport.txt" already exists, an exception will occur.
B) If a file named "payrollReport.txt" already exists, existing data will be deleted before new data is added to the file.
C) If a file named "payrollReport.txt" already exists, new data will be added to the end of the file.
D) If a file named "payrollReport.txt" already exists, a new file named "payrollReport_1.txt" will be created and used.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
40
Insert the missing code in the following code fragment. This fragment is intended to allow the user to select a file to be opened.
JFileChooser chooser = new JFileChooser();
Scanner in = null;
If (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
File selectedFile = __________;
In = new Scanner(selectedFile);
) . .
}

A) chooser.getFileName()
B) chooser.getSelectedFileName()
C) chooser.getFilePath()
D) chooser.getSelectedFile()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
41
Insert the missing code in the following code fragment. This fragment is intended to read all words from a text file.
File inputFile = new File("dataIn.txt");
Scanner in = new Scanner(dataIn.txt);
While (____________)
{
String input = in.next();
System.out.println(input);
}

A) in.getNext()
B) in.peek()
C) in.hasNext()
D) in.nextWord()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
42
Which of the following patterns should be used for the delimiter to read one character at a time using a Scanner object's next method?

A) Scanner in = new Scanner(. . .);
In)useDelimiter("[^A-Za-z]+");
B) Scanner in = new Scanner(. . .);
In)useDelimiter("[A-Za-z]+");
C) Scanner in = new Scanner(. . .);
In)useDelimiter("[^0-9]+");
D) Scanner in = new Scanner(. . .);
In)useDelimiter("");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
43
Which of the following statements about white space in Java is correct?

A) In Java, white space includes spaces only.
B) In Java, white space includes spaces and tab characters only.
C) In Java, white space includes spaces, tab characters, and newline characters.
D) In Java, white space includes spaces, tab characters, newline characters, and punctuation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
44
Consider the following code snippet:
Scanner in = new Scanner(. . .);
While (in.hasNextInt())
{
) . .
}
Under which condition will the body of the while loop be processed?

A) When an integer value is encountered in the input.
B) When a non-integer value is encountered in the input.
C) When an alphabetic value is encountered in the input.
D) When any numeric value is encountered in the input.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
45
When reading words using a Scanner object's next method, ____.

A) any characters at the beginning of the input that are considered to be white space are consumed and become part of the word being read.
B) any characters at the beginning of the input that are considered to be white space are consumed and do not become part of the word being read.
C) the program must discard white space characters at the beginning of the input before calling the next method.
D) any characters that are considered to be white space within the word become part of the word.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
46
Consider the following code snippet.
File inputFile = new File("dataIn.txt");
Scanner in = new Scanner(inputFile);
While (in.hasNext())
{
String input = in.next();
}
Which of the following statements about this code is correct?

A) This code will read in a word at a time from the input file.
B) This code will read in the entire input file in one operation.
C) This code will read in a line at a time from the input file.
D) This code will read in a character at a time from the input file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
47
The ____ method of the Character class will indicate if a character contains white space.

A) isValid()
B) getChar()
C) hasNext()
D) isWhiteSpace()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
48
Insert the missing code in the following code fragment. This fragment is intended to read floating-point numbers from a text file.
Scanner in = new Scanner(. . .);
While (____________)
{
Double hoursWorked = in.nextDouble();
System.out.println(hoursWorked);
}

A) in.getNextDouble()
B) in.peek()
C) in.hasNextDouble()
D) in.readNextWord()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
49
Insert the missing code in the following code fragment. This fragment is intended to read characters from a text file.
Scanner in = new Scanner(. . .);
In)useDelimiter("");
While (in.hasNext())
{
Char ch = ____________;
System.out.println(ch);
}

A) in.getNext()
B) in.next()
C) in.next.charAt(0)
D) in.nextChar()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
50
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[^0-9]+");
What characters will be ignored and not read in using this code?

A) Only alphabetic characters will be ignored.
B) Only numeric characters will be ignored.
C) Only non-alphabetic characters will be ignored.
D) Only non-numeric characters will be ignored.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
51
Consider the following code snippet:
Scanner in = new Scanner(. . .);
While (in.hasNextLine())
{
String input = in.nextLine();
System.out.println(input);
}
Which of the following statements about this code is correct?

A) This code will read in an entire line from the file in each iteration of the loop.
B) This code will read in the entire contents of the file in a single iteration of the loop.
C) This code will read in a single word from the file in each iteration of the loop.
D) This code will read in a single character from the file in each iteration of the loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
52
Which String class method will remove spaces from the beginning and the end of a string?

A) truncate()
B) trim()
C) clean()
D) strip()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
53
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[^0-9A-Za-z]+");
What characters will be ignored and not read in using this code?

A) Only alphabetic characters will be ignored.
B) Only numeric characters will be ignored.
C) Characters that are neither alphabetic nor numeric will be ignored.
D) Both alphabetic and numeric characters will be ignored.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
54
Consider the following code snippet.
Scanner in = new Scanner(. . .);
While (in.hasNextDouble())
{
Double input = in.nextDouble();
}
Which of the following statements about this code is correct?

A) This code will read in one word at a time from the input file.
B) This code will read in the entire input file in one operation.
C) This code will read in one floating point value at a time from the input file.
D) This code will read in one character at a time from the input file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
55
The Scanner class's ____ method is used to specify a pattern for word boundaries when reading text.

A) useDelimiter()
B) usePattern()
C) setDelimiter()
D) setPattern()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
56
When reading words with a Scanner object, a word is defined as ____.

A) Any sequence of characters consisting of letters only.
B) Any sequence of characters consisting of letters, numbers, and punctuation symbols only.
C) Any sequence of characters consisting of letters and numbers only.
D) Any sequence of characters that is not white space.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
57
Consider the following code snippet.
Scanner in = new Scanner(. . .);
While (in.hasNextLine())
{
String input = in.nextLine();
}
Which of the following statements about this code is correct?

A) This code will read in a word at a time from the input file.
B) This code will read in the entire input file in one operation.
C) This code will read in a line at a time from the input file.
D) This code will read in a character at a time from the input file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
58
Consider the following code snippet:
Scanner in = new Scanner(. . .);
Int ageValue = in.nextInt();
If there is no integer number appearing next in the input, what will occur?

A) ageValue will contain a null value.
B) ageValue will contain a zero.
C) ageValue will contain whatever characters are encountered.
D) An exception will occur.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
59
Consider the following code snippet:
Scanner in = new Scanner(. . .);
While (in.hasNextInt())
{
) . .
}
Under which condition will the body of the while loop be processed?

A) When an integer value is encountered in the input.
B) When a non-integer value is encountered in the input.
C) When any numeric value is encountered in the input.
D) When any type of value is encountered in the input.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
60
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[^A-Za-z]+");
What characters will be ignored and not read in when using this code?

A) Only alphabetic characters will be ignored.
B) Only numeric characters will be ignored.
C) Only non-alphabetic characters will be ignored.
D) Only non-numeric characters will be ignored.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
61
Consider the following code snippet:
Throw new IllegalArgumentException("This operation is not allowed!");
Which of the following statements about this code is correct?

A) This code constructs an object of type IllegalArgumentException and throws the object.
B) This code throws an existing IllegalArgumentException object.
C) This code constructs an object of type IllegalArgumentException and reserves it for future use.
D) This code will not compile.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
62
In the hierarchy of Exception classes, the NumberFormatException class is a subclass of the ____ class.

A) ArithmeticException.
B) ClassCastException.
C) IllegalArgumentException.
D) IllegalStateException.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
63
Which statement about handling exceptions is true?

A) If an exception has no handler, the error will be ignored.
B) Statements that may cause exceptions should be placed inside a catch clause.
C) Statements to handle exceptions should be placed inside a try clause
D) If an exception has no handler, the program will be terminated.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
64
Which method of an exception object will provide information about the chain of method calls that led to the exception?

A) printCallStack()
B) getCallStack()
C) printStackTrace()
D) getStackTrace()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
65
Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found.
Try
{
String filename = . . .;
Scanner in = new Scanner(new File(filename));
) . .
}
___________________
{
Exception.printStackTrace();
}

A) catch (IOException exception)
B) catch (new exception (IOException))
C) catch (IllegalArgumentException exception)
D) catch (IOException)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
66
When you start a Java program from a command line and supply argument values, the values ____.

A) are stored as int values
B) are stored as float values
C) are stored as String values
D) are stored as the type of value indicated by the argument
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
67
Consider the following code snippet:
Scanner in = new Scanner(. . .);
String result = "";
Int number = 0;
If (in.hasNextInt())
{
Number = in.nextInt();
}
Result = in.next();
If the input begins with the characters 626.14 average, what values will number and result have after this code is executed?

A) number will contain the value 626 and result will contain the value 14.
B) number will contain the value 626.14 and result will contain the value average.
C) number will contain the value 0 and result will contain the value 626.14.
D) number will contain the value 0 and result will contain the value average.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
68
Consider the following code snippet:
Scanner in = new Scanner(. . .);
In)useDelimiter("[A-Za-z]+");
What characters will be read in using this code?

A) Only alphabetic characters will be read in.
B) Only numeric characters will be read in.
C) Only non-alphabetic characters will be read in.
D) Only non-numeric characters will be read in.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
69
Consider the following code snippet:
System.out.printf("%-12s%8.2f",description,totalPrice);
Which of the following statements is correct?

A) This code will produce 2 columns, with the description field left justified and the totalPrice field right justified.
B) This code will produce 2 columns, with the description field right justified and the totalPrice field right justified.
C) This code will produce 2 columns, with the description field right justified and the totalPrice field left justified.
D) This code will produce 2 columns, with the description field left justified and the totalPrice field left justified.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
70
Consider the following code snippet:
If (in.hasNextDouble())
{
Number = in.nextDouble();
}
Result = in.next();
If the input contains the characters 626.14 average, what values will number and result have after this code is executed?

A) number will contain the value 626 and result will contain the value 14.
B) number will contain the value 626.14 and result will contain the value average.
C) number will contain the value 0 and result will contain the value 626.14.
D) number will contain the value 0 and result will contain the value average.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
71
Which of the following statements about exception handling is correct?

A) Statements that may cause an exception should be placed within a catch block.
B) The main method of a Java program will handle any error encountered in the program.
C) Statements that may cause an exception should be placed within a throws block.
D) Statements that may cause an exception should be placed within a try block.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
72
Consider the following code snippet:
Throw IllegalStateException("This operation is not allowed!");
Which of the following statements about this code is correct?

A) This code constructs an object of type IllegalArgumentException and throws the object.
B) This code throws an existing IllegalArgumentException object.
C) This code constructs an object of type IllegalArgumentException and reserves it for future use.
D) This code will not compile.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
73
Which method of an exception object will retrieve a description of the exception that occurred?

A) printStackTrace()
B) printMessage()
C) getMessage()
D) getDescription()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
74
Which of the following statements about command line arguments is correct?

A) Command line arguments must be read with a Scanner object.
B) You must declare additional parameters in the main method to receive command line argument values.
C) You cannot pass arguments to a program when starting the program from a command line prompt.
D) Command line arguments can be read using the main method's args parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
75
Which of the following is the correct syntax for starting a Java program named myProg from a command line if the program requires two arguments named arg1 and arg2 to be supplied?

A) java myProg arg1 arg2
B) java myProg(arg1, arg2)
C) java myProg "arg1" "arg2"
D) java myProg arg1, arg2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
76
You have opened a command prompt window and you have entered the following:
Java myProg Bob Smith
Which of the following statements is correct?

A) You have supplied one argument value, and this value can be accessed in the main method using the arg1 parameter.
B) You have supplied two argument values, and these values can be accessed in the main method using the arg1 and arg2 parameters.
C) You have supplied one argument value, and this value can be accessed in the main method using the args parameter.
D) You have supplied two argument values, and these values can be accessed in the main method using the args parameter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
77
Which of the following statements about exception reporting is true?

A) Use the reportError statement to report that an exception has occurred.
B) Use the reportException statement to report that an exception has occurred.
C) Use the throwException statement to report that an exception has occurred.
D) Use the throw statement to report that an exception has occurred.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
78
What is the purpose of the throw statement?

A) It is used to pass arguments to another method.
B) It is used to detect an error situation.
C) It is used to pass control to an error handler when an error situation is detected.
D) It is used to discard erroneous input.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
79
You wish to use the Scanner class's nextInt() method to read in whole numbers. To avoid exceptions that would occur if the input is not a whole number, you should use the ____ method before calling nextInt.

A) hasNext()
B) hasNextInteger()
C) hasIntegerValue()
D) hasNextInt()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
80
Which of the following statements about checked and unchecked exceptions is true?

A) Checked exceptions are handled by the Java runtime.
B) The compiler ensures that the program is handling unchecked exceptions.
C) The compiler ensures that the program is handling checked exceptions.
D) All exceptions that are descendants of RunTimeException are checked exceptions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 100 في هذه المجموعة.