Introduction to Java Programming and Data Structures, 12E, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.

Chapter 1 Introduction to Computers, Programs, and Java


Section 1.2 What is a Computer?
1.1  ________ is the physical aspect of the computer that can be seen.
A. Hardware
B. Software
C. Operating system
D. Application program

Section 1.2.1 What is a Computer?
1.2  __________ is the brain of a computer.
A. Hardware
B. CPU
C. Memory
D. Disk

1.3  The speed of the CPU may be measured in __________. Please select all that apply.
A. megabytes
B. gigabytes
C. megahertz
D. gigahertz

Section 1.2.2 Bits and Bytes
1.4  Why do computers use zeros and ones?
A. because combinations of zeros and ones can represent any numbers and characters.
B. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
C. because binary numbers are simplest.
D. because binary numbers are the bases upon which all other number systems are built.

1.5  One byte has ________ bits.
A. 4
B. 8
C. 12
D. 16

1.6  One gigabyte is approximately ________ bytes.
A. 1 million
B. 10 million
C. 1 billion
D. 1 trillion

Section 1.2.3 Memory
1.7  A program and its data must be moved into the computer's _______ before they can be executed by the CPU.
A. memory
B. hard disk
C. CPU
D. CD-ROM

Section 1.2.4 Storage Devices
1.8  A computer's _______ is volatile; that is, any information stored in it is lost when the system's power is turned off.
A. memory
B. hard disk
C. flash stick
D. CD-ROM

1.9  Which of the following are storage devices? Please select all that apply.
A. portable disk
B. hard disk
C. flash stick
D. CD-ROM

Section 1.2.5 Input and Output Devices
1.10  The ____________ specifies the number of pixels in horizontal and vertical dimensions of the display device.
A. screen resolution
B. pixel
C. dot pitch
D. monitor

Section 1.2.6 Communications Devices
1.11  ____________ is a device to connect a computer to a local area network (LAN).
A. Regular modem
B. DSL
C. Cable modem
D. NIC

Section 1.3 Program Languages
1.12  ____________ are instructions to the computer. Please select all that apply.
A. Hardware
B. Software
C. Programs
D. Keyboards

1.13  Computer can execute the code in ____________.
A. machine language
B. assembly language
C. high-level language
D. none of the above

1.14  ___________ translates high-level language program into machine language program.
A. An assembler
B. A compiler
C. CPU
D. The operating system

Section 1.4 Operating Systems
1.15  ____________ is an operating system.
A. Java
B. C++
C. Windows
D. Visual Basic
E. Ada

1.16  _____________ is a program that runs on a computer to manage and control a computer's activities.
A. Operating system
B. Java
C. Modem
D. Interpreter
E. Compiler

Section 1.5 Java, World Wide Web, and Beyond
1.17  Due to security reasons, Java ___________ cannot run from a Web browser in the new version of Java.
A. applications
B. applets
C. servlets
D. Micro Edition programs

1.18  ________ is not an object-oriented programming language.
A. Java
B. C++
C. C
D. C#
E. Python

1.19  ________ is interpreted.
A. Java
B. C++
C. C
D. Ada
E. Pascal

1.20  ________ is architecture-neutral.
A. Java
B. C++
C. C
D. Ada
E. Pascal

Section 1.6 The Java Language Specification, API, JDK, and IDE
1.21  ________ is a technical definition of the language that includes the syntax and semantics of the Java programming language.
A. Java language specification
B. Java API
C. Java JDK
D. Java IDE

1.22  ________ contains predefined classes and interfaces for developing Java programs.
A. Java language specification
B. Java API
C. Java JDK
D. Java IDE

1.23  ________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
A. Java language specification
B. Java API
C. Java JDK
D. Java IDE

1.24  ________ 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 API
C. Java JDK
D. Java IDE

Section 1.7 A Simple Java Program
1.25  The main method header is written as:
A. public static 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 void main(String[] args)

1.26  Which of the following statements is correct?
A. Every line in a program must end with a semicolon.
B. Every statement in a program must end with a semicolon.
C. Every comment line must end with a semicolon.
D. Every method must end with a semicolon.
E. Every class must end with a semicolon.

1.27  Which of the following statements is correct to display Welcome to Java on the console?
A. System.out.println('Welcome to Java');
B. System.out.println("Welcome to Java");
C. System.println('Welcome to Java');
D. System.out.println('Welcome to Java");
E. System.out.println("Welcome to Java');

1.28  What is the output of the following code?

  System.out.println("1 + 2 + 3");
  System.out.println(1 + 2 + 3);
A. 1 + 2 + 3 followed by 6
B. "6" followed by 6
C. 1 + 2 + 3 followed by 1 + 2 + 3
D. 6 followed by 6

Section 1.8 Creating, Compiling, and Executing a Java Program
1.29  The JDK command to just compile a class (not run) in the file Test.java is
A. java Test
B. java Test.java
C. javac Test.java
D. javac Test
E. JAVAC Test.java

1.30  Which JDK command is correct to run a Java application in ByteCode.class?
A. java ByteCode
B. java ByteCode.class
C. javac ByteCode.java
D. javac ByteCode
E. JAVAC ByteCode

1.31  Java compiler translates Java source code into _________.
A. Java bytecode
B. machine code
C. assembly code
D. another high-level language code

1.32  _________ is a software that interprets Java bytecode.
A. Java virtual machine
B. Java compiler
C. Java debugger
D. Java API

1.33  Suppose you define a Java class as follows, the source code should be stored in a file named _________.

public class Test {

}
A. Test.class
B. Test.doc
C. Test.txt
D. Test.java
E. Any name with extension .java

1.34  The extension name of a Java bytecode file is
A. .java
B. .obj
C. .class
D. .exe

1.35  The extension name of a Java source code file is
A. .java
B. .obj
C. .class
D. .exe

1.36  Which of the following lines is not a Java comment? Please select all that apply.
A. /** comments */
B. // comments
C. -- comments
D. /* comments */
E. ** comments **

1.37  Which of the following are the reserved words? Please select all that apply.
A. public
B. static
C. void
D. class

1.38  Every statement in Java ends with ________.
A. a semicolon (;)
B. a comma (,)
C. a period (.)
D. an asterisk (*)

1.39  A block is enclosed inside __________.
A. parentheses
B. braces
C. brackets
D. quotes

Section 1.9 Programming Style and Documentation
1.40  Programming style is important, because ______________. Please select all that apply.
A. a program may not compile if it has a bad style
B. good programming style can make a program run faster
C. good programming style makes a program more readable
D. good programming style helps reduce programming errors

1.41  Analyze the following code.

I:
public class Test {
  public static void main(String[] args) {
    System.out.println("Welcome to Java!");
  }
}

II: 
public class Test {  public static void main(String[] args) {    
System.out.println("Welcome to Java!");  } }
A. Both I and II can compile and run and display Welcome to Java, but the code in II has a better style than I.
B. Only the code in I can compile and run and display Welcome to Java.
C. Only the code in II can compile and run and display Welcome to Java.
D. Both I and II can compile and run and display Welcome to Java, but the code in I has a better style than II.

1.42  Which of the following code has the best style?

I:
public class Test {
public static void main(String[] args) {
    System.out.println("Welcome to Java!");
  }
}

II:
public class Test {
    public static void main(String[] args) {
    System.out.println("Welcome to Java!");
  }
}

III:
public class Test {
  public static void main(String[] args) {
  System.out.println("Welcome to Java!");
  }
}

IV:
public class Test {
  public static void main(String[] args) {
    System.out.println("Welcome to Java!");
  }
}
A. I
B. II
C. III
D. IV

Section 1.10 Programming Errors
1.43  If a program compiles fine, but it produces incorrect result, then the program suffers __________.
A. a compile error
B. a runtime error
C. a logic error

1.44  The following code has __________.

public class Test {
  public static void main(String[] args) {
    System.out.println("Welcome to Java!);
  }
}
A. a compile error
B. a runtime error
C. a logic error

1.45  The following code has __________.

public class Test {
  public static void main(string[] args) {
    System.out.println("Welcome to Java!");
  }
}
A. a compile error
B. a runtime error
C. a logic error