Chapter1
1)________ is the physical aspect of the computer that can be seen.
A)Hardware B) Operating system C)Application program D) Software 2)________ is the brain of a computer. A)Disk B) Memory C)Hardware D) CPU
3)The speed of the CPU is measured in ________. (Choose all that apply.) A)megabytes B) megahertz C)gigabytes D) gigahertz 4)Why do computers use zeros and ones?
A)because binary numbers are the bases upon which all other number systems are built. B)because combinations of zeros and ones can represent any numbers and characters. C)because binary numbers are simplest.
D)because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
5)One byte has ________ bits. A)12 B) 4 C) 16 D) 8
6)Which of the following are storage devices? (Choose all that apply.) A)hard disk B) CD-ROM C)flash stick D) floppy disk
7)________ is a device to connect a computer to a local area network (LAN). A)Regular modem B) DSL C)NIC D) Cable modem
8)________ are instructions to the computer. (Choose all that apply.) A)Software B) Keyboards C)Hardware D) Programs 9)Computer can execute the code in ________.
A)machine language B) high-level language C)assembly language D) none of the above 10)________ translates high-level language program into machine language program. A)An assembler B) The operating system C)CPU D) A compiler 11)________ is an operating system.
A)Java B)Windows XP C)Visual Basic D)Ada E)C++
12)________ is a program that runs on a computer to manage and control a computer's activities. A)Modem B)Java C)Interpreter D)Operating system E)Compiler 13)Java was developed by ________.
A)IBM B)Microsoft C)Cisco Systems D)Oracle E)Sun Microsystems 14)Java ________ can run from a Web browser.
A)servlets B) applets C)Micro Edition programs D) applications
15)________is an object-oriented programming language. (Choose all that apply.) A)Ada B)Java C)C D)Pascal E)C++ 16)________is interpreted.
A)Ada B)C C)C++ D)Java E)Pascal 17)________is Architecture-Neutral.
A)C++ B)Pascal C)Ada D)Java E)C
18)________is a technical definition of the language that includes the syntax and semantics of the Java programming language.
A)Java IDE B) Java language specification C)Java API D) Java JDK
19)________ contains predefined classes and interfaces for developing Java programs. A)Java JDK B) Java language specification C)Java API D) Java IDE
- 1 -
20)________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
A)Java JDK B) Java IDE C)Java language specification D) Java API
21)________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.
A)Java language specification B) Java JDK C)Java IDE D) Java API 22)The main method header is written as:
A)public void main(String[ ] args) B)public static void main(String[ ] args) C)public static void Main(String[ ] args) D)public static main(String[ ] args) E)public static void main(string[ ] args)
23)Which of the following statements is correct?
A)Every statement in a program must end with a semicolon. B)Every comment line must end with a semicolon. C)Every line in a program must end with a semicolon. D)Every class must end with a semicolon. E)Every method must end with a semicolon.
24)Which of the following statements is correct to display Welcome to Java on the console? (Choose all that apply.)
A)System.out.println(\ B)System.out.print(\ C)System.println('Welcome to Java'); D)System.out.println('Welcome to Java'); E)System.out.print('Welcome to Java');
25)The JDK command to compile a class in the file Test.java is ______
A)java Test B)java Test.java C)JAVAC Test.java D)javac Test E)javac Test.java 26)Which JDK command is correct to run a Java application in ByteCode.class? A)javac ByteCode.java B)javac ByteCode
C)java ByteCode.class D)JAVAC ByteCode E)java ByteCode 27)Java compiler translates Java source code into ________.
A)another high-level language code B)machine code C)Java bytecode D)assembly code 28)________ is a software that interprets Java bytecode.
A)Java debugger B) Java compiler C)Java virtual machine D) Java API 29)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 ______ A)Test.class B)Test.doc C)Test.java D)Test.txt E)Any name with extension .java 30)The extension name of a Java bytecode file is ______ A).obj B) .exe C) .class D) .java
31)The extension name of a Java source code file is ______ A).java B) .obj C) .exe D) .class
32)Which of the following lines is not a Java comment? (Choose all that apply.)
A)-- comments B)/** comments */ C)** comments ** D)// comments E)/* comments */ 33)Which of the following are the reserved words? (Choose all that apply.)
- 2 -
A)static B) void C) class D) public
34)Every statement in Java ends with ________.
A)a semicolon (;) B) an asterisk (*) C)a period (.) D) a comma (,) 35)A block is enclosed inside ________.
A)braces B) parentheses C)brackets D) quotes
36)The ________ method displays a message dialog box. (Choose all that apply.)
A)JOptionPane.displayMessageDialog(null, \to Java!\\1.2 Output\JOptionPane.INFORMATION_MESSAGE);
B)JOptionPane.showMessageDialog(null, \
C)JOptionPane.showMessageDialog(null, \to Java!\\1.2 Output\JOptionPane.INFORMATION_MESSAGE);
D)JOptionPane.displayMessage(null, \to Java!\\1.2 Output\JOptionPane.INFORMATION_MESSAGE);
E)JOptionPane.showMessage(null, \to Java!\\1.2 Output\JOptionPane.INFORMATION_MESSAGE);
37)To use JOptionPane in your program, you may import it using: (Choose all that apply.) A)import javax.swing.*; B)import javax.swing.JOptionPane; C)import javax.*.JOptionPane; D)import javax.*;
1)A 2)D 3)B, D 4)D 5)D 6)A, B, C, D 7)C 8)A, D 9)A 10)D 11)B 12)D 13)E 14)B 15)B, E 16)D 17)D 18)B 19)C 20)A 21)C 22)B 23)A 24)A, B 25)E 26)E 27)C 28)C 29)C 30)C 31)A 32)A, C 33)A, B, C, D 34)A 35)A 36)B, C 37)A, B
Chapter2
1)Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in);
What method do you use to read an int value?
A) input.nextInteger(); B) input.integer(); C) input.nextInt(); D) input.int(); 2)The following code fragment reads in two numbers: (Choose all that apply.) Scanner input = new Scanner(System.in); int i = input.nextInt();
double d = input.nextDouble();
What are the correct ways to enter these two numbers?
A) Enter an integer, a space, a double value, and then the Enter key. B) Enter an integer, an Enter key, a double value, and then the Enter key. C) Enter an integer, two spaces, a double value, and then the Enter key.
D) Enter a numeric value with a decimal point, a space, an integer, and then the Enter key. 3)If you enter 1 2 3, when you run this program, what will be the output? import java.util.Scanner; public class Test1 {
public static void main(String[ ] args) { Scanner input = new Scanner(System.in); System.out.print(\ double number1 = input.nextDouble();
- 3 -
double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute average
double average = (number1 + number2 + number3) / 3; // Display result
System.out.println(average); } }
A)1.0 B) 2.0 C) 4.0 D) 3.0
4)Every letter in a Java keyword is in lowercase. A)true B) false
5)Which of the following is a valid identifier? (Choose all that apply.) A)$343 B)radius C)9X D)8+9 E)class
6)Which of the following are correct names for variables according to Java naming conventions? (Choose all that apply.)
A)RADIUS B)radius C)FindArea D)Radius E)findArea
7)Which of the following are correct ways to declare variables? (Choose all that apply.) A)int length; int width; B) int length, int width; C)int length; width; D) int length, width; 8)________ is the Java assignment operator. A)== B) = C) := D) =:
9)To assign a value 1 to variable x, you write _______ A)1 = x; B)x = 1; C)1 := x; D)x == 1; E)x := 1;
10)Which of the following assignment statements is incorrect? (Choose all that apply.) A)i == j == k == 1; B) i = j = k = 1; C)i = 1; j = 1; k = 1; D) i = 1 = j = 1 = k = 1;
11)To declare a constant MAX_LENGTH inside a method with value 99.98, you write ______ A)final float MAX_LENGTH = 99.98; B)double MAX_LENGTH = 99.98; C)final double MAX_LENGTH = 99.98; D)final MAX_LENGTH = 99.98;
12)Which of the following is a constant, according to Java naming conventions? (Choose all that apply.)
A)MAX_VALUE B)COUNT C)Test D)ReadInt E)read
13)To improve readability and maintainability, you should declare ________ instead of using literal values such as 3.14159.
A)constants B) methods C)classes D) variables
14)Which of these data types requires the most amount of memory? A)long B) int C) byte D) short
15)To declare an int variable number with initial value 2, you write ______
A)int number = 2; B) int number = 2.0; C)int number = 2L; D) int number = 2l; 16)What is the result of 45 / 4? A)11 B) 10 C) 11.25 D) 12
17)Which of the following expressions will yield 0.5? (Choose all that apply.) A)(double) (1 / 2) B)1 / 2 C)1.0 / 2 D)1 / 2.0 E)(double) 1 / 2 18)Which of the following expression results in a value 1? A)15 % 4 B) 2 % 1 C) 25 % 5 D) 37 % 6
- 4 -
19)25 % 1 is ________. A)1 B) 2 C) 3 D) 4 E) 0 20)-25 % 5 is ________. A)1 B) 2 C) 3 D) 4 E) 0 21)24 % 5 is ________. A)1 B) 2 C) 3 D) 4 E) 0 22)-24 % 5 is ________ A)-1 B) -2 C) -3 D) -4 E) 0 23)-24 % -5 is ________. A)3 B) -3 C) 4 D) -4 E) 0
24)To add a value 1 to variable x, you write (Choose all that apply.) A)x = x + 1; B)x := 1; C)1 + x = x; D)x += 1; E)x = 1 + x;
25)To add number to sum, you write (Note: Java is case-sensitive) (Choose all that apply.) A)number = sum + number; B)sum += number;
C)number += sum; D)sum = sum + number; E)sum = Number + sum; 26)Suppose x is 1. What is x after x += 2? A)0 B) 1 C) 2 D) 3 E) 4
27)Suppose x is 1. What is x after x -= 1? A)0 B) 1 C) 2 D) -1 E) -2
28)What is x after the following statements? int x = 1; int y = 2;
x *= y + 1;
A)x is 2. B) x is 3. C) x is 4. D) x is 1. 29)What is x after the following statements? int x = 1; x *= x + 1;
A)x is 2. B) x is 3. C) x is 1. D) x is 4. 30)Math.pow(2, 3) returns ________. A) 9.0 B) 9 C) 8.0 D) 8
31)The ________ method returns a raised to the power of b.
A)Math.exponent(a, b) B) Math.pow(b, a) C)Math.pow(a, b) D) Math.power(a, b) 32)Analyze the following code. public class Test {
public static void main(String[ ] args) { int month = 09;
System.out.println(\ } }
A)The program displays month is 9 B)The program displays month is 9.0 C)The program displays month is 09
D)The program has a syntax error, because 09 is an incorrect literal value. 33)What is y displayed in the following code?
- 5 -