












































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













































































Which of the following refers to a collection of programs that a computer
executes? ✔✔
Software
Computers are machines that ✔✔ execute
programs
Computer programming is ✔✔ the act of designing and implementing a
computer program
Consider the following statements regarding
computers:
I. Computers can execute a large number of instructions in a fraction of
a second.
II. Computer application areas mainly target the research and scientific
communities.
III. The physical components of a computer constitute its
hardware.
IV. Unlike humans, a computer never gets bored or exhausted when
performing repetitive tasks.
Which are true? ✔✔ I, III,
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 are true? ✔✔ II, III,
The Central Processing Unit is primarily responsible for ✔✔ performing
program control and data processing
A single silicon chip made from potentially millions of transistors is called
✔✔ a Central Processing Unit (CPU)
An example of an output device that interfaces between computers and
humans is ✔✔
a speaker
An example of an input device that interfaces between computers and
humans is ✔✔ a microphone
Programs that are not running are usually stored ✔✔ in
secondary storage
When a program begins to run ✔✔ it is moved to the CPU's
memory
Which one of the following typically provides data persistence without
electricity?
I. The CPU's
memory
II. The hard
disk
III. Secondary storage ✔✔
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
languageinstructions can be run on any processor that has a Java Virtual
Machine
High-level programming languages ✔✔ are independent of the
underlying hardware
Which one of the following translates high-level descriptions into machine
code?compil ✔✔
er
Computer scientists have devised something that allows programmers to
describein words thattasks are closer to the syntax of the problems being solved. This is
called (an) ✔✔ high-level programming
language
Small applications written in the Java programming language that can be
located on the Internet are called ✔✔ applets
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
Because Java was designed for the Internet, which two of its attributes
make it suitable for beginning programmers? ✔✔ Safety and portability
An integrated development environment (IDE) bundles tools for
programming into a
unified application. What kinds of tools are usually included? ✔✔ An
editorcompil and a
er
Characters that are grouped together between double quotes (quotation
marks) in Java are called ✔✔ strings
Every statement in Java must be terminated with ✔✔ the semi-colon
character ;
These two lines of code do not produce the same
output. Why?
System.out.println(
System.out.println("7 + 3"); ✔✔ The quotes cause the second expression to
beas atreated
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
Which of the following symbols is used to
terminate a Java program statement? ✔✔
semicolon
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
Which of the following statements is true with respect to the main method
in Java? ✔✔
Every Java application must have a main method
A Java class with the name Printer has to be saved using the source file
name: ✔✔
Printer.java
Which statement starts the declaration of a class in Java? ✔✔ public class
Classname
Which Java statement prints a blank line? ✔✔
System.out.println();
Which Java statement does not contain an error? ✔✔
System.out.println();
What is the output of the following code
snippet?
System.out.print(4 + 4);
System.out.print(12); ✔✔
What kind of error is it when your program has a syntax error? ✔✔
Compile-time error
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
What kind of error is created by the following code
snippet?
System.outt.println("Hello"); ✔✔ Syntax error: the program will
not compile
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
theresul desired
t
What is a logic error? ✔✔ An error that occurs when a program is running
because,example, forthe wrong operator was
used
How do programmers find exceptions and run-time errors? ✔✔ Testing by
runningprogram the with a variety of input
values
The programmer, not the compiler, is responsible for testing a program to
identifyRun-time ✔✔
errors
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
Who or what is responsible for inspecting and testing the program to guard
against logic errors? ✔✔
Programmer
When developing a program, the programmer adds the discount amount
to the total instead of subtracting it. What type of an error is this? ✔✔ A
logic error
Which one of the following methodologies is a sequence of steps
formulated in English for solving a program? ✔✔
Pseudocode
In order to run Java programs on a computer, the computer needs to
have software called a(n) ✔✔ virtual
machine
In order to translate a Java program to a class file, the computer needs to
have software called a(n) ✔✔
compiler
The Java statement public static void main(String[] args) declares a
✔✔ method
A Java virtual machine is ✔✔
software
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)
Java is said to be a "safe" programming language. What does this mean?
✔✔programs Java can run within a browser without fear that they may attack
your computer
In order for Java to achieve protability ✔✔ compiled Java programs contain
instructions for a virtual machine
A Java Virtual Machine is ✔✔ a program that simulates a
real CPU
The Java programming language is itself relatively simple, but also contains
a vast set of ✔✔ library packages
The source code for a Java program is stored in a file ✔✔ that ends with
a.java suffix
A Java "class" file ✔✔ contains instructions to the Java virtual
machine
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,
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 ✔✔
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,
theyseparated are ✔✔ by
commas
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
In Java, the
statement
System.out.print("hello");;; ✔✔ is a legal
statement
Sometimes errors throw the compiler off track because ✔✔ the compiler
does not give up when it find the first error
Some run-time errors are so severe that they generate ✔✔ an
exception
During program development, errors are ✔✔
unavoidable
If you misspell a word in your Java program it may be
true that
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
Which of these are true about writing algorithms in
pseudo code?
I. The exact wording is not
important
II. The sequence of steps should be
ambiguous
III. The algoirthm should terminate
A sequence of steps that is unambiguous, executable, and terminating is
called ✔✔ an algorith
m
The first step in describing an algorithm in pseudo code is ✔✔ determine the
inputsoutput and
s
beforethe checking
condition?
a)
forb)
whilec)
do d) do-for ✔✔ Answer: c)
do
loop run?
int i = 0;
while (i <
{System.out.println
(i);i+
a)
b)
snippet?
int i = 1;
while (i <
{System.out.print(i +
"i = "); i +
2;if (i ==
i =
a) 1 3
5 b) 1 3
9 c) 1 3 5 7
d) 1 3 5 9 ✔✔ Answer: b) 1
number. What will be the result of
executing it?
public static void main(String[]
args)
{int j =
int result =
0;int number =
0;Scanner reader = new
Scanner(System.in);System.out.println("Please enter a
number:number =");
reader.nextInt();while (j <= number
if (number % j
result =
j+
if (result ==
System.out.println("Number: " + number + " is Not
Prime."); }
els
e{
System.out.println("Number: " + number + " is
Prime.} ");
a) The code snippet will not
compile.b) The code snippet will display the desired
result. c) The code snippet will display an incorrect
result.
d) The code snippet will loop forever. ✔✔ Answer: b) The code snippet will
displaydesired the
result.
fragment runs?
int i =
60; int j
int count = 0;
while (count <
i = i +
i;i = i +
1;j = j -
1;j = j - j;
count+
System.
out.print
ln("i="
j=" + j);
a) i =
1951, j
b) i = 1951, j =
c) i = 65, j
d) i = 65, j = 45 ✔✔ Answer: a) i =
1951, j = 0
belong to?
a) Syntax
errorb) Compile-time
error c) Run-time
error
d) Infinite loop ✔✔ Answer: c) Run-time
error
display "Hi"?
int i = 10;
while (i >=
{System.out.println("
Hi");i--
a) 9
timesb) 10
times c) 11
times
int j = 0;
for (i = 0; i < 5;
i++)
{if (i % 2 ==
i = i +
2;j+
els
e
i+
+;j = j +
j+
System.out.println("i=" + i + ",
j=" + j);
a) i=7, j
=7b) i =7, j
=6c) i =6, j
d) i =5, j =5 ✔✔ Answer: d) i
=5, j =
the loop?
I. The do
loopII. The while
loopIII. The for
loop
a) I and
b) I and
IIIc) I
only
d) III only ✔✔ Answer: c) I
only
loop run?
int i =
0; int j
do
System.out.println("" + i +
";"i+ + j);
+;if (i % 2 ==
j--;
while (j >=
a) 0
times b) 1
timesc) 2
times
d) 4 times ✔✔ Answer: c) 2
times
called:
a) A sentinel
loop
b) A nested
loopc) A parallel
loop
d) A do/while loop ✔✔ Answer: b) A
nested loop
code snippet?
int n = 20;
for (int i = 0; i <= n;
i++)
{for (int j = 0; j <= i;
j++) {
System.out.println(""
+} i);
a) 0 and
20 b) 1 and
20 c) 0 and
d) 1 and 19 ✔✔ Answer: a) 0
and 20
code snippet?
for (int num2 = 1; num2 <= 3;
num2++)
{for (int num1 = 0; num1 <= 2;
num1++){
System.out.println("" + num2 + " " +
num1);}
a) 3
timesb) 6
timesc) 9
times
d) 12 times ✔✔ Answer:c) 9
times
snippet?
System.out.println("The Average Salary: " +
average);
els
e {
System.out.println ("No
data!");}
return
a) The Average
Salary: 0
b) The Average Salary:
30 c) The Average Salary:
d) There will be no output as the code snippet will not compile. ✔✔
Answer:Average b)Salary: The
snippet?
boolean token =
false; while (token)
System.out.println("Hell
} o");
a) "Hello" will be displayed infinite
times.b) No output because of compilation
error.c) No output after successful
compilation.
d) "Hello" will be displayed only once. ✔✔ Answer: c) No output after
successfulcompilatio
n.
snippet?
boolean token =
false; do
System.out.println("Hell
o");
while (token);
a) "Hello" will be displayed infinite
times.b) No output because of compilation
error.c) No output after successful
compilation.
d) "Hello" will be displayed only once. ✔✔ Answer: d) "Hello" will be
displayedonce only
snippet?
int i = 1;
while (i <=
{System.out.println("Inside the while
loop");i = i +
a) No output because of compilation
error.b) "Inside the while loop" will be displayed
10 c) Notimes. output after successful
compilation.
d) "Inside the while loop" will be displayed only once. ✔✔ Answer: d)
"Insideloop" will the be while displayed only
once.
snippet?
boolean val1 =
true; boolean val
= false; while
(val1)
{if
(val1){
System.out.println("Hell
o");}
val1 =
val
a) No output will be displayed because of
compilation error.
b) "Hello" will be displayed only
once.c) "Hello" will be displayed infinite
times.
d) No output will be displayed even after successful compilation of the code
snippet.Answer:b) ✔✔ "Hello" will be displayed only
once.
"Hello"?
int i = 0;
while (i !=
{System.out.println("Hell
o");i+
a) Infinite
times
b) 14
timesc) 15
times
d) 16 times ✔✔ Answer: c) 15
times
do
y = x /
2; x = x
i + 1;
while (x < 2.5);
System.out.print(i +
a)
1 b)
c)
d) 4 ✔✔ Answer: c) 3
following code snippet?
int r1 = (int) (Math.random() *
a) Between 1 and
49 b) Between 0 and
50 c) Between 0 and
d) Between 1 and 50 ✔✔ Answer: d) Between 1 and 50
dice to get a sum of the numbers on two dice between 2 and 12 with
different probabilities?
a)b) (int) (int) (Math.random()(Math.random() ** 126 + 1)
+c) 1)(int) (Math.random() * 6 + 1) + (int)
(Math.random() * 6 + 1)
d) (int) (Math.random() * 12 - 2) ✔✔ Answer: c) (int) (Math.random() * 6
+(Math.random() 1) + (int) * 6 + 1)
26 alphabet characters in the string str?
String str = "";
for (char c = 'A'; c < 'Z';
{ c++)
str = str +
} c;
a) int c =
b) str = c +
str;c) c <=
d) Must change to use a do loop ✔✔ Answer: c)
c <= 'Z
below?
String s =
"abcde"; int i =
while (i < 5)
{System.out.print(s.substring(i, i
i+
a) No
outputb)
abcdc)
abcde
d) bcde ✔✔ Answer: d)
bcde
below?
String s =
"abcde"; int i =
do
{if (i >
System.out.print(s.substring(i, i
while (i <
a) No
outputb) No output (infinite
loop)c)
abcde d) bcde ✔✔ Answer: b) No output (infinite
loop)
below?
String s =
"12345"; int i =
while (i < 5)
{System.out.print(s.substring(i, i
+i+ 1));
a) No
outputb)