JAVA test 1

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

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

1) the solution may not be the best (most efficient) 2) the solution may have errors and need testing and fixing before we are done 3)the solution may, at a later date, need revising to handle new specifications 4) the solution may, at a later date, need revising because of new programming language features

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"

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

"FRINK ZIPPI"

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;

+, *, /, -

Which of the following lines is not a Java comment? (Choose all that apply.) 1) /** comments */ 2) // comments 3) -- comments 4) /* comments */ 5) ** comments **

-- comments ** comments **

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

-20

The extension name of a Java bytecode file is

.class

The extension name of a Java source code file is

.java

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

Consider the double value likelihood = 0.013885. What would be output if DecimalFormat dformatter = DecimalFormat("0.00##"); and you execute System.out.println(df.format(likelihood)); ?

0.0139

Binary numbers are composed entirely of

0s and 1s

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

1) String name = "George Bush"; 2) String name = new String("George Bush"); 3) String name = "George" + " " + "Bush"; 4) String name = new String("George" + " " + "Bush");

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

C++

________ is a program that runs on a computer to manage and control a computer's activities.

Operating system

Volatility is a property of

RAM

________ is the physical aspect of the computer that can be seen.

Hardware

is true regarding the mod operator, %

It can be performed on any numeric values, and the result always is numeric

In the following list, which statement is not true regarding Java as a programming language? 1) It is a relatively recent language, having been introduced in 1995 2) It is a language whose programs do not require translating into machine language before they are executed 3) It is an object-oriented programming language 4) It is a language that embraces the idea of writing programs to be executed using the World Wide Web 5) all of these are true

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

The ________ method displays a message dialog box.

JOptionPane.showMessageDialog(null, "Welcome to Java!", "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Welcome to Java!");

________is Architecture-Neutral.

Java

________is interpreted.

Java

________is an object-oriented programming language.

Java C++

________ contains predefined classes and interfaces for developing Java programs.

Java API

________provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.

Java IDE

________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.

Java JDK

Java compiler translates Java source code into ________.

Java bytecode

________is a technical definition of the language that includes the syntax and semantics of the Java programming language.

Java language specification

________ is a software that interprets Java bytecode.

Java virtual machine

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

________ is a device to connect a computer to a local area network (LAN).

NIC

Suppose you define a Java class as follows: public class Test{ } In order to compile this program, the source code should be stored in a file named

Test.java

________ is an operating system.

Windows XP

If x is an int and y is a float, all of the following are legal except which assignment statement? 1) y = x; 2) x = y; 3) y = (float) x; 4) x = (int) y; 5) all of these are legal

x = y;

Which of the following would return the last character of the String x? 1) x.charAt(0); 2) x.charAt(last); 3) x.charAt(length(x)); 4) x.charAt(x.length( )-1); 5) x.charAt(x.length( ));

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

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

z will equal 0.0

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

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

Which of the following is not syntactically legal in Java? 1) public class Foo 2) System.out.println("Hi"); 3) { } 4) s t a t i c main(String[ ] args) 5) only System.out.println("Hi"); is legally valid, all of the rest are illegal

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

6 bits can be used to represent ________ distinct items or

64

One byte has ________ bits.

8

Which of the following characters does not need to have an associated "closing" character in a Java program? 1) { 2) ( 3) [ 4) < 5) all of these require closing characters

<

________ translates high-level language program into machine language program.

A compiler

________ is the brain of a computer.

CPU

Which of the following statements is correct? 1) Every line in a program must end with a semicolon. 2) Every statement in a program must end with a semicolon. 3) Every comment line must end with a semicolon. 4) Every method must end with a semicolon. 5) Every class must end with a semicolon.

Every statement in a program must end with a semicolon.

Java ________ can run from a Web browser.

applets

________ are instructions to the computer.

Software Programs

Following Java naming convention, which of the following would be the best name for a class about store customers? 1) StoreCustomer 2) Store Customer 3) storeCustomer 4) STORE_CUSTOMER 5) Store-Customer

StoreCustomer

Java was developed by ________.

Sun Microsystems

Which of the following statements is correct to display Welcome to Java on the console? (Choose all that apply.) 1) System.out.println('Welcome to Java'); 2) System.out.println("Welcome to Java"); 3) System.println('Welcome to Java'); 4) System.out.print('Welcome to Java'); 5) System.out.print("Welcome to Java");

System.out.println("Welcome to Java"); System.out.print("Welcome to Java");

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

Which character below is not allowed in an identifier? 1) $ 2) _ 3) 0 (zero) 4) q 5) ^

^

Which of the following is true regarding Java syntax and semantics? 1) a Java compiler can determine if you have followed proper syntax but not proper semantics 2) a Java compiler can determine if you have followed proper semantics but not proper syntax 3) a Java compiler can determine if you have followed both proper syntax and semantics 4) a Java compiler cannot determine if you have followed either proper syntax or semantics 5) a Java compiler can determine if you have followed proper syntax and can determine if you have followed proper semantics if you follow the Java naming convention rules

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

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

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

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

Every statement in Java ends with ________.

a semicolon (;)

Mistyping "println" as "printn" will result in

a syntax error

Comments should

be insightful and explain what the instruction's intention is

Why do computers use zeros and ones?

because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.

Java is an example of

both high-level language and fourth generation language

You specify the shape of an oval in a Java applet by defining the oval's

bounding box

A block is enclosed inside ________.

braces

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? 1) int 2) byte 3) float 4) char 5) all of these can store numeric values

char

In order to create a constant, you would use which of the following Java reserved words?

final

Which of the following would be a good variable name for the current value of a stock? 1) curstoval 2) theCurrentValueOfThisStockIs 3) currentStockVal 4) csv 5) current

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

Using getCurrencyInstance( ) formats a variable, automatically inserting

decimal point for cents dollar sign percent sign

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

do nothing

Which of the following are storage devices? (Choose all that apply.) 1) floppy disk 2) hard disk 3) flash stick 4) CD-ROM

floppy disk hard disk flash stick

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

execute

Which of the following is a legal Java identifier? 1) i 2) class 3) ilikeclass! 4) idon'tlikeclass 5) i-like-class

i

To use JOptionPane in your program, you may import it using:

import javax.swing.JOptionPane; import javax.swing.*;

Which JDK command is correct to run a Java application in ByteCode.class?

java ByteCode

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

The JDK command to compile a class in the file Test.java is

javac Test.java

Computer can execute the code in ________.

machine language

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

main memory

The speed of the CPU is measured in ________.

megahertz gigahertz

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

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

the combined TCP/IP protocol

Which of the following is a legal Java identifier? 1) 1ForAll 2) oneForAll 3) one/4/all 4) 1_4_all 5) 1forall

oneForAll

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 reserved words

public static void class

The main method for a Java program is defined by

public static main(String[ ] args)

The main method header is written as:

public static void main(String[ ] args)

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

random access

A Java program is best classified as

software

A cast is required in which of the following situations? 1) using charAt to take an element of a String and store it in a char 2) storing an int in a float 3) storing a float in a double 4) storing a float in an int 5) all of these require casts

storing a float in an int


Conjuntos de estudio relacionados

AP Environmental Science El Niño

View Set