JAVA ALL QUESTIONS SET 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is a value that is written into the code of a program? *********

a literal

A ragged array is

a two-dimensional array where the rows have different numbers of columns.

A static field is created by placing the key word static

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

Which symbol indicates that a member is private a UML diagram?

-

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 CSS named color?

All of these

When an array is passed to a method

All of these are true.

Which of the following is not a rule that must be followed when naming identifiers?

Identifiers can contain spaces.

To create a TextField control, you use the ________ class which is in the ________ package.

TextField, javafx.scene.control

The boolean data type may contain which of the following range of values?

true or false

The sequential search algorithm

uses a loop to sequentially step through an array, starting with the first element.

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

Java provides a mechanism known as a ________ which makes it possible to write a method that takes a variable number of arguments.

variable-length argument list

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

A loop that executes as long as a particular condition exists is called a(n) ________ loop.

conditional

A loop that repeats a specific number of times is known as a(n)

count-controlled

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

flag

Which of the following is the operator used to determine whether an object is an instance of a particular class?

instanceOf

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

specific JavaFX node.

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)

Software refers to

programs.

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

setInterpolator

An array of String objects

consists of an array of references to String objects.

The ________ loop is ideal in situations where you always want the loop to iterate at least once.

do-while

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

exception

A(n) ________ is a section of code that gracefully responds to exceptions when they are thrown.

exception handler

A method that calls itself is a ________ method.

recursive

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

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = .08; break; case 'B': discountRate = .06; case 'C': discountRate = .04; default: discountRate = 0.0; }

0.0

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

120

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.indexOf("ov");

15

What will be displayed after the following code is executed? String str = "abc456"; for (int i = 0; i < str.length(); i++) { char chr = str.charAt(i); if (!Character.isLetter(chr)) System.out.print(Character.toUpperCase(chr)); }

456

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 happens when the following code is executed? ComboBox<string> myComboBox = new ComboBox<>; myComboBox.getItems().addAll(5, 10, 15, 20);

A compiler error will occur.

Which of the following is not a way a user can interact with a computer?

All of these are ways a user can interact with a computer.

All of the exceptions that you will handle are instances of classes that extend the ________ class.

Exception

If a subclass constructor does not explicitly call a superclass constructor,

Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes.

The original name for Java was

Oak

The type of control normally used when you want the user to only be allowed to select one option from several possible options is the

RadioButton.

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

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

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x= float[ARRAY_SIZE]; for (i=1; i<ARRAY_SIZE; i++) { x[i]=10.0; }

The code contains a syntax error and will not compile.

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

Assuming three ImageView objects named puppy, kitten, and bunny have been created, what does the following statement do? HBox hbox = new HBox(5, puppy, kitten, bunny);

There will be five pixels of space between the controls horizontally in the container.

A Java program must have at least one of the following:

a class definition

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

RAM is usually

a volatile type of memory, used for temporary storage.

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

diskOut.println("Calvin");

To replace a ListView control's existing items with a new list of items, use the ________ method

getItems().setAll()

To retrieve text that a user has typed into a TextField control, you call the ________ method.

getText

A constructor

has the same name as the class

You should not define a class that is dependent on the values of other class fields

in order to avoid having stale data.

Methods that operate on an object's fields are called

instance methods.

Another term for an object of a class is a(n)

instance.

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

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[]

What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str1); System.out.println(matches);

moon

Which of the following statements will allow a user to type input into a field of a ComboBox named myComboBox?

myComboBox.setEditable(true);

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

When a field is declared static there will be

only one copy of the field in memory.

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

A(n) ________ is used to write computer programs

programming language

Of the following, which would be considered the no-arg constructor for the Rectangle class?

public Rectangle()

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

Which of the following statements will set a ListView control, puppyListView, to be 300 pixels high and 200 pixels wide?

puppyListView.setSize(200, 300);

________ operators are used to determine whether a specific relationship exists between two values.

relational

The ________ method removes an item from an ArrayList at a specific index.

remove

Given the following method header, what will be returned from the method? public Rectangle getRectangle()

the address of an object of the Rectangle class

A series of words or other items of data, separated by spaces or other characters, are known as

tokens.

A(n) ________ contains one or more statements that are executed and can potentially throw an exception.

try block

If object1 and object2 are objects of the same class, to make object2 a copy of object1

write a method for the class that will make a field by field copy of object1 data members into object2 data members.

Which of the following is(are) used as delimiters if the StringTokenizer class's constructor is called and a reference to a String object is passed as the only argument?

All of these

Which of the following is not part of the programming process?

All of these are parts of the programming process.

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

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

FadeTransition

What does the following code do? Scanner 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.

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

The catch clause

The catch clause does all of these.

________ is the term for the relationship created by object aggregation.

"Has a"

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

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

5

Which of the following is a subclass of Node?

Both of these

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

In order for an object to be serialized, the class must implement the ________ interface.

Serializable

If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

The file, data.dat, will be created.

What would be the result after the following code is executed? int [ ] numbers = {40, 3, 5, 7, 12, 10}; int value = numbers[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.

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

class

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

import java.io.*;

Which of the following import statements is required in order to create a BorderPane layout container?

import javafx.scene.layout.BorderPane;

UML diagrams do not contain

object names.

Byte code instructions are

read and interpreted by the JVM

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

sentinel

In a class hierarchy

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.

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

The simplest way to use the System.out.printf method is

with only a format string and no additional arguments.

When you make a copy of the aggregate object and of the objects that it references,

you are performing a deep copy.


Kaugnay na mga set ng pag-aaral

BIO 345 Evolution Prof Maley & Sterner: Exam 1

View Set

POLS 2305-25: Ch. 9: Political Parties

View Set

React Native Interview Questions

View Set