CST4401 - Java All Quiz Questions

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

If you want to output a double so that at least 1 digit appears to the left side of the decimal point and exactly 1 digit appears to the right side of the decimal point, which pattern would you give a DecimalFormat variable when you instantiate it?

"0.0"

The final println command will output System.out.println("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas");

"But notin Texas"

Suppose that String name = "Frank Zappa". What will the instruction name.toUpperCase( ).replace('A', 'I'); return?

"FRINK ZIPPI"

The program will print the word "Here" and then print System.out.println("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas");

"There Everywhere" on the same line as "Here"

If the String major = "Computer Science", what is returned by major.charAt(1)?

'o'

Given the following assignment statement, which of the following answers is true regarding the order that the operators will be applied based on operator precedence? a = (b + c) * d / e - f;

+, *, /, -

What will be the result of the following assignment statement? Assume b = 5 and c = 10. int a = b * (-c + 2) / 2;

-20

A reasonable documentation comment for this program might be System.out.println("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas");

// a program that demonstrates the differences between print, println and how + works

The instruction: System.out.println("Hello World"); might best be commented as

// used to demonstrate an output message

Assume that x, y, and z are all integers (int) equal to 50, 20, and 6 respectively. What is the result of x / y / z?

0

The Random class has a method nextFloat( ) which returns a random float value between

0 and 1

What is output if x = 0, y = 1 and z = 1?

0.0

Binary numbers are composed entirely of

0s and 1s

Which memory capacity is the largest?

12,000,000 megabytes

What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5?

15

What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?

15

Consider the following statement: System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night"); This statement will output ________ lines of text

2

How many lines of output are provided by this program? System.out.println("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas");

2

A color image is broken down into individual pixels (points), each of which is represented by

3 values denoting the intensity of red, green, and blue in the image

If a, b, and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to

4

6 bits can be used to represent ________ distinct items or values

64

What will be displayed by this command: System.out.println(Math.pow(3, 3-1));

9

Which of the following characters does not need to have an associated "closing" character in a Java program?

<

What happens if you attempt to use a variable before it has been initialized?

Answers A syntax error may be generated by the compiler and A runtime error may occur during execution

If you want to store into the String name the value "George Bush", you would do which statement?

Any of these would work

What is the function of the dot operator?

Both It allows one to access the data within an object when given a reference to the object and It allows one to invoke a method within an object when given a reference to the object

Java is similar in syntax to what other high level language?

C++

Java is a strongly typed language. What is meant by "strongly typed"?

Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type

What is the advantage of putting an image in a JLabel instance?

It becomes part of the component and is laid out automatically

In the following list, which statement is not true regarding Java as a programming language?

It is a language whose programs do not require translating into machine language before they are executed

What is the function of a frame's pack method?

It sets the size appropriately for display

Which of the following GUI components is used to accept input into a JFrame?

JTextField

Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?

Math.sqrt(Math.abs(x));

Which properties are true of String objects?

Only Their lengths never change and The shortest string has zero length are true

Volatility is a property of

RAM

Following Java naming convention, which of the following would be the best name for a class about store customers?

StoreCustomer

If you want to output the text "hi there", including the quote marks, which of the following could do that?

System.out.println("\"hi there\"");

Assume that x is a double that stores 0.362491. To output this value as 36%, you could use the NumberFormat class with NumberFormat nf = NumberFormat.getPercentInstance( ); Which of the following statements then would output x as 36%?

System.out.println(nf.format(x));

Questions33_34 computes

The average of x, y, and z as a double, but the result may not be accurate the sum of x, y and z

Consider the following enumeration enum Speed { FAST, MEDIUM, SLOW };

The name of the Speed enumeration whose ordinal value is zero is FAST

Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.

The program won't compile-you'll receive a syntax error about the missing class.

In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will Mutation #3 yield if Mutation #1: mutation1 = phrase.concat(".")?

XINSTXIN

Which character below is not allowed in an identifier?

^

Which of the following is true regarding Java syntax and semantics?

a Java compiler can determine if you have followed proper syntax but not proper semantics

public void paint(Graphics page) { page.setColor(Color.blue); page.fillRect(50, 50, 100, 100); page.setColor(Color.white); page.drawLine(50, 50, 150, 150); page.drawLine(50, 150, 150, 50); page.setColor(Color.black); page.drawString("A nice box", 50,170); } The figure drawn in this applet is

a blue square with two white lines drawn diagonally through it

As presented in the Software Failure, the root cause of the Mars Climate Orbiter problem was

a communication issue between subsystems

A URL (Universal Resource Locator) specifies the address of

a document or other type of file on the Internet

An error in a program that results in the program outputting $100 instead of the correct answer, $250 is

a logical error

A containment hierarchy is

a nested collection of relationships among containers

Mistyping "println" as "printn" will result in

a syntax error

In Java a variable may contain

a value or a reference

A JPanel can be added to a JFrame to form a GUI. In order to place other GUI components such as JLabels and Buttons into the JFrame, which of the following messages is passed to the JPanel?

add

The advantage(s) of the Random class' pseudo-random number generators, compared to the Math.random method, is that

all but answer the generators in Random are more efficient than the one in Math.random

Once we have implemented the solution, we are not done with the problem because

all of these

Using getCurrencyInstance( ) formats a variable, automatically inserting

all three

Java.text's NumberFormat class includes methods that

allow you to format currency, allow you to format percentages, round their display during the formatting process, but not truncate their display during the formatting process

An API is

an Application Programming Interface

If two variables contain aliases of the same object then

answers the object may be modified using either alias and the object will become an "orphan" if both variables are set to null are correct

Comments should

be insightful and explain what the instruction's intention is

public void paint(Graphics page) { page.setColor(Color.blue); page.fillRect(50, 50, 100, 100); page.setColor(Color.white); page.drawLine(50, 50, 150, 150); page.drawLine(50, 150, 150, 50); page.setColor(Color.black); page.drawString("A nice box", 50,170); } The String "A nice box" is drawn

below the box

Java is an example of a(n)

both high-level language and fourth generation language

A unique aspect of Java that allows code compiled on one machine to be executed on a machine of a different hardware platform is Java's

bytecodes

Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying

c = a.concat(b);

Of the following types, which one cannot store a numeric value?

char

Layout managers are associated with

containers

In Java, "instantiation" means

creating a new object of the class

Which of the following would be a good variable name for the current value of a stock?

currentStockVal

A Java variable is the name of a

data value stored in memory that can change its value but cannot change its type during the program's execution

JOptionPane is a class that provides GUI

dialog boxes

The line of Java code "// System.out.println("Hello");" will

do nothing

Which phase of the fetch-decode-execute cycle might use a circuit in the arithmetic-logic unit?

execute

The main difference between a frame and a panel is

frames can have a title bar; panels cannot

Which of the following will yield a pseudorandom number in the range [ -5, +5 ) given the following:

gen.nextFloat( ) * 10 - 5

Which of the following is a legal Java identifier?

i

The Swing package

is complementary to the AWT

Which library package would you import to use NumberFormat and DecimalFormat?

java.text

Which library package would you import to use the class Random?

java.util

When executing a program, the processor reads each program instruction from

main memory

The word println is a(n)

method

It is important to dissect a problem into manageable pieces before trying to solve the problem because

most problems are too complex to be solved as a single, large activity

In order for a computer to be accessible over a computer network, the computer needs its own

network address

What value will z have if we execute the following assignment statement? int z = 50 / 10.00;

none of these, a run-time error arises because z is an int and 50 / 10.00 is not

Which of the following is a legal Java identifier?

oneForAll

The advantages of the DecimalFormat class compared with the NumberFormat class include

only precise control over the number of digits to be displayed and control over the presence of a leading zero

If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following sets of commands might you use?

page.setColor(Color.green); page.fillRect(50, 50, 100, 100); page.setColor(Color.red); page.fillOval(60, 60, 80, 80);

The main method for a Java program is defined by

public static main(String[ ] args)

The ability to directly obtain a stored item by referencing its address is known as

random access

Which of the following is not syntactically legal in Java?

s t a t i c main(String[ ] args)

Consider the following two lines of code. What can you say about s1 and s2?

s1 and s2 are both references to different String objects

A Java program is best classified as

software

In addition to their usage providing a mechanism to convert (to box) primitive data into objects, what else do the wrapper classes provide?

static constants

A cast is required in which of the following situations?

storing a float in an int

Given the following code fragment

strB.compareTo(strC) would yield 0

Autoboxing is

the automatic conversion of a wrapper object to/from its corresponding primitive type

For a computer to communicate over the Internet, it must use

the combined TCP/IP protocol

An "alias" is when

two different reference variables refer to the same physical object

If x is an int and y is a float, all of the following are legal except which assignment statement?

x = y;

Which of the following would return the last character of the String x?

x.charAt(x.length( )-1);

The String class' compareTo method

yields 0 if the two strings are identical

What value will z have if we execute the following assignment statement? float z = 5 / 10;

z will equal 0.0


Conjuntos de estudio relacionados

Care of Nasogastric (Decompression) Tubes

View Set

Study questions (LAB 8) measurement of arterial blood pressure

View Set

24. Probability of committing type I error and how to avoid it...

View Set

AP Bio Cellular respiration and Photosynthesis PT.2

View Set