Java Set 1
What type of relationship exists between two objects when one object is a specialized version of another object?
"is a"
What will the following code display?String input = "99#7"; int number; try{ number = Integer.parseInt(input); }catch(NumberFormatException ex) {number = 0; }catch (RuntimeException ex) { number = 1; }catch(Exception ex){number = -1;} System.out.println(number);
0
What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = .05; else if (purchase > 750) discountRate = .03; else if (purchase > 500) discountRate = .01;
0.0
What will be the value of x after the following code is executed? int x, y = 15; x = y--;
15
What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }
20
What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x);
5.0
What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);
9, 14, 2018, and -
Which of the following problems can be solved recursively?
All of these (Towers of Hanoi, binary search ,greatest common denominator )
Which of the following is not part of the programming process?
All of these are parts of the programming process.(defining and modeling the problem, testing and debugging, entering code and compiling it )
Which of the following creates a blue circle centered at X = 50, Y = 50 with a radius of 50?
Circle blueCircle = new Circle(50, 50, 50); blueCircle.setFill(Color.BLUE);
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC
ClassB
Which of the statements below give an alternative way to write the following: FileInputStream fstream = new FileInputStream("info.dat"); DataInputStream inputFile = new DataInputStream(fstream);
DataInputStream inputFile = new DataInputStream(new FileInputStream("info.dat"));
Unchecked exceptions are those that inherit from the
Error class or the RuntimeException class.
You can use the enum key word to
F Both of these (create your own data type -specify the values that belong to the type.)
To read data from a binary file, you create objects from which of the following classes?
FileInputStream and DataInputStream
Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?
FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);
The ________ layout container arranges the contents into cells, similar to a spreadsheet.
GridPane
________ refers to the physical components that a computer is made of.
Hardware
________ is the term for the relationship created by object aggregation.
Has a
What does the following code snippet do? Circle myCircle = new Circle(50, 50, 25); TranslateTransition rtrans = new TranslateTransition(new Duration(5000), myCircle);
It creates a circle with center point (25, 50), radius = 25, and duration = 5 seconds.
What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>();
It specifies that only String objects may be stored in the ArrayList object
________ operators are used to determine whether a specific relationship exists between two values
Relational
If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method?
SavingsAccount.getNumberOfAccounts();
In order for an object to be serialized, the class must implement the ______ interface
Serializable
Which of the following statements creates a Slider with a range of 1 to 20 with a starting value of 1?
Slider slider = new Slider(1.0, 20.0, 1.0)
The catch clause
The catch clause does all of these.
What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb);
The cow jumped over the moon.
Which of the following statements is not true about the following code? StringBuilder strb = new StringBuilder("Total numbers of parts: "); strb.insert(23, 32);
The ending position for the insert is 32.
What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);
The inFile variable will reference an object that is able to read binary data from the Input.dat file
What would be the result after the following code is executed? int[] number=(40,3,5,7,8,12,10); int value=number[0]; for (int i=1; I<numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; }
The value variable will contain the lowest value in the numbers array.
Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant?
Tree.PINE
When a character is stored in memory, it is actually the ________ that is stored.
Unicode number
What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder ("We have lived in Chicago, Trenton, and Atlanta."); strb.replace(17, 24, "Tampa"); System.out.println(strb);
We have lived in Tampa, Trenton, and Atlanta.
Enclosing a group of statements inside a set of braces creates
a block of statements
What does the following UML diagram entry mean? + setHeight(h : double) : void
a public method with a parameter of data type double that does not return a value
When a method's type is an object, what is actually returned by the calling program?
a reference to an object of that class
A computer program is
a set of instructions that allow the computer to solve a problem or perform a task
A ragged array is
a two-dimensional array where the rows have different numbers of columns.
Which of the following is a named storage location in the computer's memory?
a variable
What is the following statement an example of? import java.util.*;
a wildcard import statement
A class becomes abstract when you place the ________ key word in the class definition.
abstract
A(n) ________ method is a method that appears in a superclass but expects to be overridden in a subclass
abstract
The variable used to keep a running total in a loop is called a(n)
accumulator
The ________ is at least one case in which a problem can be solved without recursion.
base case
If you do not provide initialization values for a class's numeric fields, they will
be automatically initialized to 0.
A block of code is enclosed in a set of
braces, { }
The RandomAccessFile class treats a file as a stream of
bytes.
In the ________ file format, when data in a spreadsheet is exported, each row is written to a line and commas are used to separate the values in the cells.
comma separated value
When recursive methods directly call themselves, it is known as
direct recursion.
A declaration for an enumerated type begins with the ________ key word.
enum
If a random access file contains a stream of characters, which of the following statements would move the file pointer to the starting byte of the fifth character in the file?
file.seek(8);
To retrieve text that a user has typed into a TextField control, you call the ________ method.
getText
When you write a method that throws a checked exception, you must
have a throws clause in the method header.
The ________ statement is used to create a decision structure which allows a program to have more than one path of execution.
if
include both the Image and the ImageView classes.
import java.io.*;
Which of the following import statements is required in order to write an event handler class?
import javafx.event.EventHandler;
To display an image in a JavaFX application you must
include both the Image and the ImageView classes.
In object-oriented programming, ________ allows you to extend the capabilities of a class by creating another class that is a specialized version of it.
inheritance
A(n) ________ is a dialog box that prompts the user for input.
input dialog
Which of the following is a valid declaration for a ragged array with five rows but no columns?
int[][] ragged = new int[5][];
A search algorithm
is used to locate a specific item in a collection of data
When the this variable is used to call a constructor
it must be the first statement in the constructor making the call.
To return an array of long values from a method, which return type should be used for the method?
long[]
A method
may have zero or more parameters
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
methods
Which of the following expressions will generate a random number in the range of 1 through 10?
myNumber = randomNumbers.nextInt(10) + 1
In order to leave 15 pixels of space in an HBox container, use which of the following statements?
myhbox.setPadding(new Insets(15));
Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.
nonletter
By default, a reference variable that is an instance field is initialized to the value
null
UML diagrams do not contain
object names
Using the blueprint/house analogy, you can think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint.
objects
A subclass can directly access
only public and protected members of the superclass.
Enumerated types have the ________ method which returns the position of an enum constant in the declaration list.
ordinal
If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.
overrides
A ________ loop will always be executed at least once
posttest
Computers can do many different jobs because they are
programmable.
A cross between human language and a programming language is called
pseudocode.
Which of the following statements correctly specifies two interfaces?
public class ClassA implements Interface1, Interface2
In the ________, we must always reduce the problem to a smaller version of the original problem
recursive case
In the hexadecimal color value #CCAA99, the CC refers to which color component?
red
What will be displayed after the following statements are executed? String str = "red$green&blue#orange"; String[] tokens = str.split("[$&#]"); for (String s : tokens) System.out.print(s + " ");
red green blue orange
The ________ method removes an item from an ArrayList at a specific index.
remove
To apply specific styles to all of the nodes in a scene, use the ________ selector.
root
How would a stylesheet named javafxstyles.css be applied to a JavaFX application, assuming that scene is the variable that refers to a Scene object?
scene.getStylesheets().add("javafxstyles.css");
To combine several effects, use the Effect class's ________ method.
setInput
Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?
str1.equalsIgnoreCase(str2)
A(n) ________ is used as an index to pinpoint a specific element within an array
subscript
Which CSS type selector corresponds with the TextField JavaFX class?
text-field
In a recursive program, the number of times a method calls itself is known as
the depth of recursion
When an exception is thrown by code in its try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to
the first catch clause that can handle the exception.
In a class hierarchy
the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.
If a BorderPane region does not contain anything,
the region will not appear in the GUI.
What is syntax?
the rules that must be followed when writing a program
In an if-else statement, if the boolean expression is false
the statement or block following the else is executed.
If a method does not handle a possible checked exception, what must the method have?
throws clause in its header
Which of the following methods returns a string representing all of the items stored in an ArrayList object?
toString
A series of words or other items of data, separated by spaces or other characters, are known as
tokens
You can concatenate String objects by using the
using the concat method or the + operator.
Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?
while (inputFile.hasNext())
A partially filled array is normally used
with an accompanying integer value that holds the number of items stored in the array.