JAVA ALL QUESTIONS SET 3

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following code snippets creates a Line and uses a RotateTransition object to animate it for seven seconds?

Line myLine = new Line(25, 50, 100, 50); // RotateTransition rtrans = //new RotateTransition(new Duration(7000), myLine);

When a class does not use the extends key word to inherit from another class, Java automatically extends it from the ________ class

Object

Which of the following statements correctly creates a Scanner object for keyboard input?

Scanner keyboard = new Scanner(System.in);

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

Write the code.

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String object containing "ghi"

Which symbol indicates that a member is public in a UML diagram?

+

To build a menu system you must

All of these are necessary steps. (create the Menu objects and register an event handler for each menu item object. Add the MenuBar object to the scene graph. create a MenuBar object.)

To display an image in a JavaFX application you must

include both the Image and the ImageView classes.

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop

infinite

Which Scanner class method reads a String?

nextLine

If numbers is a two-dimensional array, which of the following would give the number of columns in row r?

numbers[r].length

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.

overrides

Computers can do many different jobs because they are

programmable.

All methods specified by an interface are

public.

In the ________, we must always reduce the problem to a smaller version of the original problem.

recursive case

The process of connecting an event handler object to a control is called ________ the event handler.

registering

The end of a Java statement is indicated by a

semicolon (;)

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

setOnAction

A method's signature consists of

the method name and the parameter list.

Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by

using the private access specifier on the class fields.

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;

0.0

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x > 100);

1

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

a UML diagram

If ClassC is derived from ClassB which is derived from ClassA, this would be an example of

a chain of inheritance.

A runtime error is usually the result of

a logical error.

Java requires that the boolean expression being tested by an if statement be enclosed in

a set of parentheses.

Beginning with Java7, you can use ________ to reduce a lot of duplicated code in a try statement needs to catch multiple exceptions, but performs the same operation for each one.

multi-catch

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

An exception object's default error message can be retrieved using the ________ method.

getMessage

If you don't provide an access specifier for a class member, the class member is given ________ access by default.

package

A group of related classes is called a(n)

package.

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

polymorphic

The StringBuilder class's insert method allows you to insert a(n) ________ into the calling object's string.

All of these (char array - a primitive type -a String object.)

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);

CRC stands for

Class, Responsibilities, Collaborations.

Which effect class do you use to increase an image's brightness?

ColorAdjust

Adding RadioButton controls to a ________ object creates a mutually exclusive relationship between them.

ToggleGroup

Given the following declaration: enum Tree ( OAK, MAPLE, PINE ) What is the fully-qualified name of the PINE enum constant?

Tree.PINE

The variable used to keep a running total in a loop is called a(n)

accumulator.

When a method in the ________ class returns a reference to a field object, it should return a reference to a copy of the field object to prevent security holes.

aggregate

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }

ans = 60, x = 0, and y = 50

The ________ is at least one case in which a problem can be solved without recursion.

base case

The following catch clause catch (Exception e)

can handle all exceptions that are instances of the Exception class or one of its subclasses.

In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0);

char[]

Which of the following shows the inheritance relationships among classes in a manner similar to that of a family tree?

class hierarchy

The key word new

creates an object in memory.

Which of the following statements is invalid?

double r = 2.9X106;

Variables of the boolean data type are useful for

evaluating conditions that are either true or false.

What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

1000

What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 100; }

110

What will be the value of x after the following code is executed? int x, y =15; x = y--;

15

Given the following code, how many times will the while loop be executed? StringTokenizer st = new StringTokenizer("Java programming is fun!"); while (st.hasMoreTokens()) System.out.println(st.nextToken());

4

What does the following statement do? double[] array1 = new double[10];

All of these (-Declares array1 to be a reference to an array of double values -Creates an instance of an array of 10 double values -Will allow valid subscripts in the range of 0 - 9)

Which of the following statements converts a double variable named tax to a string and stores the value in the String object named str?

String str = Double.toString(tax);

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

In memory, GUI objects in a ________ are organized as ________ in a tree-like hierarchical data structure.

scene, nodes

Which CSS type selector corresponds with the TextField JavaFX class?

text-field

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%?

"##0.0%"

Protected class members can be denoted in a UML diagram with the ________ symbol.

#

What will be displayed after the following statements are executed? int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); }

40

Given the following code that uses recursion to find the factorial of a number, how many times will the else clause be executed if n = 5? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }

5

What is the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x);

8.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 statements opens a file named MyFile.txt and allows you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

To read data from a binary file, you create objects from which of the following classes?

FileInputStream and DataInputStream

Which of the following is a named storage location in the computer's memory?

a variable

If you do not provide initialization values for a class's numeric fields, they will

be automatically initialized to 0.

Which of the following problems can be solved recursively?

All of these (binary search towers of Hanoi greatest common denominator)

When you write an enumerated type declaration, you

All of these (-are actually creating a special kind of class. -do not enclose the enum constants in quotation marks. -should use the standard convention of writing the enum constants in uppercase.)

What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};

An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created.

________ occurs when method A calls method B which in turn calls method A.

Indirect recursion

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 (50, 50), radius = 25, and duration = 5 seconds.

The ________ class is used to create a menu bar.

MenuBar

Which of the following statements will display the maximum value that a double can hold?

System.out.println(Double.MAX_VALUE);

To use recursion for a binary search, what is required before the search can proceed?

The array must be stored

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.

For the following code, which statement is not true? public class Sphere { Private double radius; public double x; private double y; private double z; }

The z field is available to code written outside the Sphere class.

What would be displayed as a result of executing the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

There are 5785 hens in the hen house.

In the following code that uses recursion to find the factorial of a number, what is the base case? private static int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }

if (n == 0) return 1;

Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)?

if (temp >= 0 && temp <= 100)

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case? public static int gcd(int x, int y) { if (x % y == 0) return y; else return gcd(y, x % y); }

if (x % y ==) return y;

Which of the following import statements is required to use the StringTokenizer class?

import java.util.StringTokenizer;

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 class that is defined inside another class is called a(n)

inner class

When an exception is thrown

it must be handled by the program or by the default exception handler.

What will be displayed after the following code is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26); System.out.println(str2);

jumped

Variables are

symbolic names made up by the programmer that represent memory locations.

Which of the following is the method you can use to determine whether a file exists?

the File class's exists method

The central processing unit (CPU) consists of two parts which are

the control unit and the arithmetic and logic unit (ALU).

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.

When an exception is thrown by code in the 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.

The scope of a local variable is

the method in which it is defined.

When an argument is passed by value

the parameter variable holds the address of the argument.

Application software refers to

the programs that make the computer useful to the user.

The primitive data types only allow a(n) ________ to hold a single value.

variable

The binary search algorithm

will cut the portion of the array being searched in half each time it fails to locate the search value.

Key words are

words that have a special meaning in the programming language

What would be displayed as a result of executing the following code? int x = 15, y = 20, z = 32; x += 12; y /= 6; z -= 14; System.out.println("x = " + x + ", y = " + y + ", z = " +z);

x = 27, y = 3, z = 18


Ensembles d'études connexes

El poder de las flores Misterio 3: ¿Por que algunas manzanas son rojas y otras son verde?

View Set

Chapter 40 - Nursing Management: Nutritional Problems

View Set

CYBR3.CompTIA A+ Practice Exam 2 (220-1102 Core 2) (61)

View Set

ECON 202 TEST 3 humpries chap 11

View Set

Networking + Post-Assessment Quiz

View Set

Kingfisher Security+ SYO-501 Chapter 5: Application Security

View Set

Advanced exercise physiology exam 1

View Set