Java set 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

A static field is created by placing the key word static

after the access specifier and before the field's data type

What will be displayed after the following code has been executed? int x=65; int y=55; if (x>=y) { int ans = x+y; } System.out.println(ans);

120

What happens when the following code is executed? ComboBox<string> myComboBox = new ComboBox<>(); myComboBox.getItems().addAll(5, 10 ,15 ,20);

A compiler error will occur.

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

FileOutputStream and DataOutputStream

On a Web page, the ________ specifies what information to display and the ________ specifies how that information should be displayed.

HTML, CSS

The boolean expression in an if statement must evaluate to

true or false.

In Java there are two categories of exceptions which are

unchecked and checked.

To get the name of a calling enum constant

use the toString method.

The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

valueOf

An array of String objects *

consists of an array of references to String objects.

The key word new

creates an object in memory

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

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

Software refers to

programs

The ________ method is used to display a message dialog.

showMessageDialog

A group of related classes is called a(n)

package

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

package

The two primary methods of programming in use today are

procedural and object-oriented.

In memory, GUI objects in a______ are organized as ______ in a tree-like hierarchial data structures

scene, nodes

The end of a Java statement is indicated by a

semicolon (;)

A ________ is a value that signals when the end of a list of values has been reached

sentinel

Character literals are enclosed in ________ and string literals are enclosed in ________.

single quotes, double quotes

The ________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted.

trim

What will be displayed after the following statements have been executed? 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

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);

x=37,y=5

The ________ class is used to create a menu bar.

MenuBar

Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00);

The account object's toString method will be implicitly called

To create an animation in which a node fades in or out over a period of time, use the ________ class

FadeTransition

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

All fields declared in an interface

are final and static

A characteristic of ________ is that only an object's methods are able to directly access and make changes to an object's data

data hiding

An item that separates other items is known as a

delimiter.

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

Which key word indicates that a class inherits from another class?

extends

It is common practice in object-oriented programming to make all of a class's

fields private

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

final

A ________ is a boolean variable that signals when some condition exists in the program.

flag

The JVM periodically performs the ________ process to remove unreferenced objects from memory.

garbage collection

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

getMessage

Overloading is

having two or more methods with the same name but different signatures.

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;

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

infinite

What does the following code do? keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename);

it allows the user to enter the name of the file that data will be written to

When using the throw statement, if you don't pass a message to the exception object's constructor,

it will be null message.

Which of the following commands will run the compiled Java program named DoItNow?

java DoItNow

In order to preserve an image's aspect ratio (so it does not appear stretched or distorted), you should use which of the following? Assume myView references an ImageView object.

myView.setPreserveRatio(true);

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

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

5

What is the value of scores [2][3] in the following array? int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80} {98, 95, 92, 94}, {91, 84, 88, 96} };

94

What does the following statement do? Image puppy = new Image("file:C:\\images\terrier.jpg");

It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive.

Which of the following is a subclass of Node?

Neither of these(Media Player - Media)

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

No import statement is required

Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

String str = Integer.toString(number);

Which of the following statements draws the string "Love to animate!" starting at coordinates (200, 50)?

Text myWords = new Text(200.0, 50.0, "Love to animate!");

Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9];

The numbers array has 6 rows and 9 columns.

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 ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

a UML diagram

Classes that inherit from the Error class are for exceptions that are thrown when

a critical error occurs, and the application program should not try to handle them.

While ________ is centered on creating procedures, ________ is centered on creating objects.

procedural programming, object-oriented programming

One type of design tool used by programmers when creating a model of a program is

pseudocode

All methods specified by an interface are

public

Which method is used to determine the number of items stored in an ArrayList object?

size

In a JavaFX CSS style definition, if a selector name starts with a period, that selector corresponds to a

specific JavaFX node.

The Application class's ________ method is the main entry point for a JavaFX application.

start

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

the File class's exists method

In order to do a binary search on an array

the array must first be sorted.

Which of the following can you use to compare two enum data values?

the equals and compareTo methods

In the following Java statement, what value is stored in the variable name? String name = "John Doe";

the memory address where "John Doe" is located

A Java source file must be saved with the extension

.java

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y)

Nothing. There is an error in the code.

To print "Hello, world" on the monitor, which of the following Java statements should be used?

System.out.println("Hello, world");

Which of the following is not a valid Java comment?

*/ Comment two /*

QUESTION 112 What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.lastIndexOf("ov", 14);

-1

Which of the following creates a custom style class that will allow a Button control to appear with a blue background and yellow text?

.button-color { -fx- background-color: blue; -fx- text-fill: yellow

What will be the value of bonus after the following code is 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; elsebonus = 1250;

1000

How many times will the following for loop be executed? for(int count =10; count <=21; count++) System.out.println("Java is great!");

12

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

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 determines whether the variable temp is within the range of 0 through 100 (inclusive)?

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

All the transition classes inherit a method named ________ which allows you to specify how the animation begins and ends.

setInterpolator

An object typically hides its data but allows outside code access to

the methods that operate on the data.

A protected member of a class may be directly accessed by

Any of these (methods in the same package, methods of a subclass, methods of the same class.)

A class's responsibilities include

Both of these ( respinsible for doing and for knowing)

After the header, the body of the method appears inside a set of

braces, { }

One or more objects may be created from a(n)

class

In a UML diagram you show a realization relationship by connecting a class and an interface with a

dashed line with an open arrowhead at one end.

When a field is declared static there will be

only one copy of the field in memory.

Which of the following statements will correctly convert the data type, if x is a float and y is a double?

x = (float)y;

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

###.#

If you want to use the System.out.printf method to print a string argument, use the ________ format specifier.

%s

What does the following code snippet do when the animation is played, given that imageView has been created? Fade Transition ftrans = new Fade Transition (new Duration (5000), imageView); ftrans. setFromValue (1.0); ftrans.setToValue (0.5); ftrans.play():

The image will be completely opaque when displayed and will decrease to 50% opacity over the five minutes of the animation.

What happens if a program does not handle an unchecked exception?

The program is halted and the default exception handler handles the exception.

What will be the result of the following code? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 0; i < numbers.length; i++) value += numbers{i};

The value variable will contain the sum of all the values in the numbers array.

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.

Which class specifies the amount of time an animation should last?

Duration

A method is called from the main method for the first time. It then calls itself seven times. What is the depth of recursion?

7

If you have two RadioButtons ( dogRadio and catRadio), how should you code them to create a mutually exclusive relationship?

ToggleGroup radioGroup = new ToggleGroup(); dogRadio.setToggleGroup(radioGroup); catRadio.setToggleGroup(radioGroup):

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

ToogleGroup

To serialize an object and write it to the file, use the ________ method of the ObjectOutputStream class.

WriteObject


Conjuntos de estudio relacionados

GCD 3022 - Exam 4 Book Questions

View Set

Chapter 7 Wrist & Hand Joints & Muscles

View Set