2.99 See Answer

Question: What does the throw statement do?


What does the throw statement do?


> What method do you call to register an event handler with a Button control?

> In what package is the EventHandler interface?

> What is an event handler?

> When the user runs a program in a text-based environment, such as the command line interface, what determines the order in which things happen?

> What is an event? Give an example.

> Once you have created a GridPane container, how do you add a control to a ­specific column and row?

> How do you set the horizontal and vertical spacing in a GridPane container?

> What package is the Insets class in?

> What is the difference between spacing and padding, in regard to layout containers?

> Write a method named timesTen. The method should accept a double argument, and return a double value that is ten times the value of the argument.

> If you want to change the image that an ImageView object is displaying, what method do you call?

> If you want to make sure that an image does not appear stretched after it is resized, what method do you call?

> How do you set the width and height of an ImageView?

> If you want to display an image in a layout container, do you add an Image object, or an ImageView object to the layout container?

> What package contains the Image and ImageView classes?

> How does a command line interface work?

> What package is the Pos enumeration in?

> How do you change the alignment of an HBox container?

> The Scene class is in what package?

> If you want to arrange controls in a grid, with rows and columns, what layout container would you use?

> A program contains the following method definition: public static int cube(int num) { return num * num * num; } Write a statement that passes the value 4 to this method and assigns its return value to a variable named result.

> Account Balance A program that calculates the current balance in a savings account must ask the user for the following: The Starting Balance The total dollar amount of deposits made The total dollar amount of withdrawals made The monthly interest rate On

> What is the general difference between an HBox layout container, and a VBox layout container?

> The program in Code Listing12-1 calls a Stage class’s show method. What does this method do?

> The program in Code Listing12-1 calls a Stage class’s setTitle method. What does this method do?

> What is the purpose of the Application class’s abstract start method?

> What is the purpose of the launch method of the Application class?

> The JavaFX library has an abstract class that is the foundation of a GUI application. What is the name of the class?

> What is a user interface?

> If multiple exceptions can be thrown by code in a try block, how does the JVM know which catch clause it should pass the control of the program to?

> What is the difference between a try block and a catch block?

> How do you retrieve an error message from an exception?

> After the catch block has handled the exception, where does program execution resume?

> Look at the following method header: public static void myMethod(int a, int b, int c) Now look at the following call to myMethod: myMethod(3, 2, 1); When this call executes, what value will be stored in a? What value will be stored in b? What value will

> What is the difference between exceptions that inherit from the Error class and exceptions that inherit from the Exception class?

> Other than the Object class, what is the superclass for all exceptions?

> If an exception is thrown and the program does not handle it, what happens?

> What must you do to a class in order to serialize objects of that class?

> What are the two modes that a random access file may be opened in? Explain the difference between them.

> What class do you use to work with random access files?

> What is the difference between sequential and random access?

> What classes do you use to write output to a binary file? What classes do you use to read from a binary file?

> What is the difference between a text file and a binary file?

> Examine the following method header, and then write an example call to the method: public static void doSomething(int x)

> What does it mean to “throw" an exception?

> If you are writing a custom exception class, how can you make sure it is checked? How can you make sure it is unchecked?

> If a method has a throw statement, does it always have to have a throws clause in its header? Why or why not?

> What is the difference between the throw statement and the throws clause?

> What is the purpose of the argument that is passed to an exception object’s constructor? What happens if you do not pass an argument to the constructor?

> When are you required to have a throws clause in a method header?

> What are the differences between a checked and an unchecked exception?

> A program’s main method calls method A, which calls method B. None of these methods performs any exception handling. The code in method B throws an ­exception. Describe what happens.

> What is the call stack? What is a stack trace?

> Convert the following while loop to a for loop: int count = 0; while (count < 50) { System.out.println("count is " + count) ; Count++ ; }

> When does the code in a finally block execute?

> Briefly describe what an exception is.

> If a method in a subclass has the same name as a method in the superclass, but uses a different parameter list, does the subclass method overload or override the ­superclass method?

> If a method in a subclass has the same signature as a method in the superclass, does the subclass method overload or override the superclass method?

> How can a subclass method call an overridden superclass method?

> Under what circumstances would a subclass need to override a superclass method?

> Look at the following classes: public class Ground { public Ground() { System.out.println("You are on the ground."); } public Ground(String groundColor) { System.out.println("The ground is " + groundColor); } } public class Sky extends Ground { public S

> Look at the following classes: public class Ground { public Ground() { System.out.println("You are on the ground."); } } public class Sky extends Ground { public Sky() { System.out.println("You are in the sky."); } } What will the following program displ

> Class B extends class A. (Class A is the superclass and class B is the subclass.) Describe the order in which the class’s constructors execute when a class B object is created.

> Write the first line of a class named Employee, which implements interfaces named Payable and Listable.

> Convert the while loop in the following code to a do-while loop: Scanner keyboard = new Scanner(System.in); int x = 1; while (x > 0) { System.out.print("Enter a number:”) ; x = keyboard.nextInt (); }

> Write the first line of a class named Customer, which implements an interface named Relatable.

> If an interface has fields, how are they treated?

> How is an interface different from an abstract class, or any class?

> How is an interface similar to an abstract class?

> What is the purpose of an interface?

> If a class is defined as abstract, what can you not do with the class?

> What is the purpose of an abstract class?

> If a subclass extends a superclass with an abstract method, what must you do in the subclass?

> Look at the following class declarations and answer the questions that follow them: public class Shape { private double area; public void setArea(double a) { area = a; } public double getArea() { return area; } } public class Circle extends Shape { priva

> What is the purpose of an abstract method?

> Write a for loop that calculates the total of the following series of numbers: 130+229+328+⋯301

> Recall the Rectangle and Cube classes discussed earlier, as shown in Figure10-18. 1. Is the following statement legal or illegal? If it is illegal, why? Rectangle r = new Cube(10, 12, 5); 2. If you determined that the statement in part a is legal, are th

> When you create a class, it automatically has a toString method and an equals method. Why?

> Look at the following class definition: public class ClassD extends ClassB { (Member Declarations . . .) } Because ClassD inherits from ClassB, is it true that ClassD does not inherit from the Object class? Why or why not?

> Why is it easy to give package access to a class member by accident?

> What is the difference between private access and package access?

> Why should you avoid making class members protected when possible?

> What is the difference between private members and protected members?

> When a class member is declared as protected, what code may access it?

> How do you prevent a method from being overridden?

> Here is the first line of a class declaration. What is the name of the superclass? What is the name of the subclass? public class Truck extends Vehicle

> Write a for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000

> Look at the following declaration: String cafeName = "Broadway Cafe"; String str; Which of the following methods would you use to make str reference the string “Broadwayâ€. startsWith regionMatches substring indexOf

> Modify the method so it performs a case-insensitive test. The method should return true if the argument ends with “ger†in any possible combination of uppercase and lowercase letters.

> Write a method that accepts a reference to a String object as an argument and returns true if the argument ends with the substring “gerâ€. Otherwise, the method should return false.

> Write a loop that counts the number of uppercase characters that appear in the String object str.

> What will the following code display? char var = '$'; System.out.println(Character.toUpperCase(var));

> Write a loop that asks the user, “Do you want to repeat the program or quit? (R/Q)”. The loop should repeat until the user has entered an R or Q.

> What is the purpose of the MIN_VALUE and MAX_VALUE variables that are members of the numeric wrapper classes?

> What wrapper class methods convert a number from decimal to another numbering system? What wrapper classes are these methods a member of?

> What is the output of the following statement? System.out.println(Character.toUpperCase(Character.toLowerCase('A')));

> Write a statement that converts the following integer to a string and stores it in the String object referenced by str: int i = 99;

> Write code that does the following: opens a file named NumberList.txt, uses a loop to write the numbers 1 through 100 to the file, and then closes the file.

> Look at the following string: "dog$cat@bird%squirrel" Write code using the String class’s split method that can be used to extract the following tokens from the string: dog, cat, bird, and squirrel.

> Look at the following string: "/home/rjones/mydata.txt" Write code using the String class’s split method that can be used to extract the following tokens from the string: home , rjones , mydata , and txt.

2.99

See Answer