Computer Science Quiz 1

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

Which statement starts the declaration of a class in Java?

public class Classname

Which of the following statements must you include in a Java class that can be executed by the virtual machine?

public static void main(String[] args)

The source code for a Java program is stored in a file ________________.

that ends with a .java suffix

Every statement in Java must be terminated with ____________.

the semi-colon character ;

During program development, errors are __________________.

unavoidable

In order to run Java programs on a computer, the computer needs to have software called a(n) __________.

virtual machine

Consider the following pseudocode, what does it produce? Set n to 0 Set a to 0 Set b to 1 Set p to 1 Print p Repeat until n equals 10 Set p to a + b Set a to b Set b to p Add 1 to n Print p

1 1 2 3 5 8 13 21 34 55 89

Consider the following pseudocode, what does it produce? Set n to 1 Set p to 1 Repeat until n equals 6 Multiply p by n and store result in p Add 1 to n Print p

1 2 6 24 120 720

What is the output of the following code snippet? public class PrintIt { public static void main(String[] args) { System.out.println("4 * 4" + 12); } }

4 * 412

What is the output of the following code snippet? System.out.print(4 + 4); System.out.print(12);

812

Which of the following statements is valid with respect to the usage of a semicolon in Java?

A semicolon is used to denote the end of a statement.

What is the difference between an editor and a compiler?

An editor allows program files to be written and stored; a compiler converts program files into an executable program.

What is a logic error?

An error that occurs when a program is running because, for example, the wrong operator was used.

Which one of the following translates high-level descriptions into machine code?

Compiler

Which of the following statements is true with respect to the main method in Java?

Every Java application must have a main method.

What is the output of the following code snippet? System.out.print("Hello"); System.out.println("Good Day!");

HelloGood Day!

How does Java achieve portability?

Java programs are compiled to instructions for a virtual machine.

What kind of error is created by the following code snippet? System.out.print("The sum of 8 and 12 is "); System.out.println(8 * 12);

Logic error: the program does not produce the desired result

Suppose you examine a simple Java program and the first line is public class HelloPrinter. Is this the same thing in Java as the line public class helloprinter?

No, because Java is case-sensitive, these are considered to be completely distinct.

A Java class with the name Printer has to be saved using the source file name:

Printer.java

What is one of the benefits of using a high-level programming language like Java?

Problems solved in a high-level language are independent of the underlying computer hardware.

Who or what is responsible for inspecting and testing the program to guard against logic errors?

Programmer

Which one of the following methodologies is a sequence of steps formulated in English for solving a problem?

Pseudocode

Because Java was designed for the Internet, which two of its attributes make it suitable for beginning programmers?

Safety and portability

Which of the following symbols is used to terminate a Java program statement?

Semicolon

A Java virtual machine is ____________.

Software

Which of the following refers to a collection of programs that a computer executes?

Software

Consider the following pseudocode, what does it produce? Set n to 1 Set p to 0 Set s to 0 Repeat until n equals 10 Calculate the square of n and store in s Add s to p Add 1 to n Print p

Sum of square of numbers between 1 and 10

What kind of error is created by the following code snippet? System.outt.println("Hello");

Syntax error: the program will not compile

Which one of the following code snippets compiles without errors and displays the output "Hello Good Day!" on the screen?

System.out.print("Hello "); System.out.println("Good Day!");

Which Java statement does not contain an error?

System.out.println();

Which Java statement prints a blank line?

System.out.println();

Consider a scenario in which you develop a Java program on a computer that has a Pentium processor. What step should you take to run the same Java program on a computer that has a different processor?

The compiled Java machine language instructions can be run on any processor that has a Java Virtual Machine.

When a compiler finds a syntax error in a program, what happens?

The compiler continues and may report about other errors but does not produce a Java class file.

These two lines of code do not produce the same output. Why? System.out.println(7 + 3); System.out.println("7 + 3");

The quotes cause the second expression to be treated as a string.

What is the output from this code snippet? System.out.print("The sum is "); System.out.println("7 + 3");

The sum is 7 + 3

What is the purpose of the following algorithm, written in pseudocode? num = 0 Repeat the following steps 10 times Input var1 If var1 > num Num = var1 Print num

To find the highest among 10 numbers

What is the purpose of the following algorithm? someNum = 0 Repeat the following steps 50 times Input variable1 if variable1 > someNum someNum = variable1 Print someNum

To find the largest of 50 numbers

Consider the following pseudocode. What does it produce? Set n to 1 Set p to 1 Repeat until n equals 20 Multiply p by 2 and store result in p Add 1 to n Print p

Two raised to the power 20

A single silicon chip made from potentially millions of transistors is called ______________.

a Central Processing Unit (CPU)

A Java Virtual Machine is _______________________.

a program that simulates a real CPU

A sequence of steps that is unambiguous, executable, and terminating is called _______________.

an algorithm

Some run-time errors are so severe that they generate ______________.

an exception

High-level programming languages _________________________.

are independent of the underlying hardware

Every Java program consists of one or more ___________.

classes

What kind of error is it when your program has a syntax error?

compile-time error

In order to translate a Java program to a class file, the computer needs to have software called a(n) _______________.

compiler

A Java "class" file _______________________.

contains instructions for the Java virtual machine

The first step in describing an algorithm in pseudocode is ______________.

determine the inputs and the outputs

Computers are machines that __________________.

execute programs

In Java, the following statement ____________________. System.out.print("hello");;;

is a legal statement

Programmers have embraced Java over its closest rival, C++, mainly because _____________.

it is easier to use

The Java programming language is itself relatively simple, but also contains a vast set of _______________.

library packages

While developing a program, the programmer adds the discount amount to the total due instead of subtracting it. What type of an error is this?

logic error

The Java statement public static void main(String[] args) declares a ____________.

method

The Central Processing Unit is primarily responsible for ______________.

performing program control and data processing

An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included?

presentation tools

Writing a computer game in Java that has graphics, motion, and sound effects _______________________.

requires a team of skilled programmers

The programmer, not the compiler, is responsible for testing a program to identify _________________.

run-time errors

The technical term for the values that a method needs in order to carry out its task is an argument. When there is more than one argument needed by a method, they are __________________.

separated by commas

Characters that are grouped together between double quotes (quotation marks) in Java are called _____________.

strings

Which one of the following errors represents a part of a program that is incorrect according to the rules of the programming language?

syntax errors


Kaugnay na mga set ng pag-aaral

final exam questions health and life insurance exam

View Set

Chapter 23: Promoting Asepsis and Preventing Infection Practice Problems

View Set

Drill Exam 2: Maternity and Pediatric Nursing

View Set

Biology Abiogenesis and Biogenesis Quiz

View Set

Chapter 7 Skeletal system: Gross Anatomy

View Set

Taxation of life insurance and annuities

View Set