CS A170 - Intro to Java PQs
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? System.out.print("Hello"); System.out.println("Good Day!");
HelloGood Day!
Consider the following statements about folders and your integrated development environment (IDE): I. Hierarchical folders help to organize a project. II. Folders are a way to visualize the layout of a file system. III. Folders make it impossible to lose or accidentally delete a file. Which statements are correct?
I and II only
Which of the following statements regarding backup strategies for Java files are true? I. You should back up your projects often to prevent loss of valuable work. II. You should check your backups only in case of loss of data. III. You should pay attention to the backup direction.
I and III only
Which of these are true about writing algorithms in pseudocode? I. The exact wording is not important II. The sequence of steps should be ambiguous III. The algorithm should terminate
I and III only
Which pointers about backing up your Java projects are important? I. Check your backups once in a while. II. Rely on the Java programming language's built-in back up system. III. Back up often.
I and III only
If you misspell a word in your Java program, which of the following statements are true? I. the program will not compile II. the program may compile, but not run III. the program may compile and run but still have a logic error
I, II, and III
Which statements are true? I. In Java, a file can contain at most one public class. II. The word public denotes that the class is usable by the "public". III. Every Java program must have a main method.
I, II, and III
Which of the following typically provides data persistence without electricity? I. The CPU's memory II. The hard disk III. Secondary storage
II and III only
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.
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
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? 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 a situation where you are buying videos online. The video seller charges $21.50 as the price per video and $6.75 as the handling cost for up to three videos. For every video purchased in addition to three videos, there is a handling charge of $1.50. In addition, there is a 9 percent tax on the cost of the videos but not on the handlingCharges. Assuming that numVideos represents the number of videos you are purchasing, which of the following is the correct algorithm for calculating the total cost of your purchase?
Total charge for videos = 21.50 * numVideos Tax on the videos = total charge for videos * .09 if (numVideos <= 3) then handlingCharges = 6.75 else handlingCharges = 6.75 + 1.50 * (numVideos - 3) Total cost of order = total charge for videos + tax + handlingCharges
A Java Virtual Machine is _______________________.
a program that simulates a real CPU
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
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
Evaluate the pseudocode below to calculate the payment (pmt) with the following test values: The total number of hours worked (workingHours) = 60 The rate paid for hourly work (rate) = 15 Input workingHours Input rate pmt = workingHours * rate If workingHours > 40 then extraHours = workingHours - 40 extraPmt = extraHours * rate * 2 pmt = pmt + extraPmt Output pmt
1,500
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
Evaluate the pseudocode below to calculate the payment (pmt) with the following test values: The total number of hours worked (workingHours) = 50 The rate paid for hourly work (rate) = 10 Input workingHours Input rate pmt = workingHours * rate If working_hours > 45 extraHours = workingHours - 45 extraPmt = extraHours * rate * 2 pmt = pmt + extraPmt Output pmt
600
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.
Which of the following statements is true with respect to the main method in Java?
Every Java application must have a main method.
Imagine you are developing an algorithm to calculate the total cost of a purchase order that contains several items. The cost of each item and the tax rate is known. The standard shipping charge for the entire order is $4.95, and the special delivery charge is $19.95. In addition, there is no tax on the shipping cost. Which of the following is the correct pseudocode for the required algorithm?
For each item on the purchase order: Order cost = order cost + item cost If standard shipping Shipping cost = 4.95 Else Shipping cost = 19.95 Total purchase order cost = order cost + order cost * tax rate + shipping cost
Consider the following statements about computer programs: I. Computer programs can be written by someone who has a basic knowledge of operating a computer. II. Computer programs can complete complex tasks quickly. III. Large and complex computer programs are generally written by a group of programmers. IV. Computer programs are composed of extremely primitive operations. Which of the statements are correct?
II, III, and IV only
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.
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 prints a blank line?
System.out.println();
How do programmers find exceptions and run-time errors?
Testing by running the program with a variety of input values
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.
Imagine you are planning to purchase a new cable TV dish. You are considering two cable TV dishes that have different purchase prices. Each channel service provider charges a different rate for each month that the cable TV dish is used. To determine which cable TV dish is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cable TV dish. What are all of the inputs that you need for this algorithm?
The cost of each cable TV dish, the rate per month for using each cable TV dish, and the number of months you would use the cable TV dish
Imagine you are planning to buy a new cell phone. You are considering two cell phones. These cell phones have different purchase prices. Each mobile service provider charges a different rate for each minute that the cell phone is used. To determine which cell phone is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cell phone. What are all the inputs needed for this algorithm?
The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes you would use the cell phone
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.
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)
The term applet refers to _________________.
a Java program that runs within a web browser
An example of an input device that interfaces between computers and humans is ____________.
a microphone
An example of an output device that interfaces between computers and humans is ____________.
a speaker
An integrated development environment (IDE) bundles tools for programming into a unified application. What kinds of tools are usually included?
an editor and a compiler
Some run-time errors are so severe that they generate ______________.
an exception
Small applications written in the Java programming language that can be located anywhere on the Internet are called __________.
applets
The first step in describing an algorithm in pseudocode is ______________.
determine the inputs and the outputs
Computers are machines that __________________.
execute programs
Computer scientists have devised __________________ that allow programmers to describe tasks in words that are closer to the syntax of the problems being solved.
high-level programming languages
Programs that are not running are usually stored _____________________.
in secondary storage
In Java, the following statement ____________________. System.out.print("hello");;;
is a legal statement
A pseudocode step is executable when _____________________________.
it can be carried out in practice
Programmers have embraced Java over its closest rival, C++, mainly because _____________.
it is easier to use
When a program begins to run, ___________________________.
it is moved to the CPU's memory
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
Who or what is responsible for inspecting and testing the program to guard against logic errors?
programmer
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)
Writing a computer game in Java that has graphics, motion, and sound effects _______________________.
requires a team of skilled programmers
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
A Java virtual machine is ____________.
software
Which of the following refers to a collection of programs that a computer executes?
software
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
The source code for a Java program is stored in a file ________________.
that ends with a .java suffix
Computer programming is ______________________.
the act of designing and implementing a computer program
Sometimes errors throw the compiler off track because __________________.
the compiler does not give up when it finds the first error
Every statement in Java must be terminated with ____________.
the semi-colon character ;
During program development, errors are __________________.
unavoidable
The language developed by Sun Microsystems that became the Java programming language was originally designed to be simple, secure, and _______________.
usable for many different processor types
In order to run Java programs on a computer, the computer needs to have software called a(n) __________.
virtual machine
In order for the ENIAC computer to be re-programmed, __________________________.
wires needed to be plugged into a different wiring configuration
In Java, if you want the compiler to interpret what you type as program instructions, you must __________________.
write correct Java statements separated by the semicolon