JAVA Exam 1

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/328

flashcard set

Earn XP

Description and Tags

@$U CSE 110

Last updated 10:43 PM on 2/14/23
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

329 Terms

1
New cards
Which of the following refers to a collection of programs that a computer executes?
Software
2
New cards
Computers are machines that
execute programs
3
New cards
Computer programming is
the act of designing and implementing a computer program
4
New cards
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, IV
5
New cards
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, IV
6
New cards
The Central Processing Unit is primarily responsible for
performing program control and data processing
7
New cards
A single silicon chip made from potentially millions of transistors is called
a Central Processing Unit (CPU)
8
New cards
An example of an output device that interfaces between computers and humans is
a speaker
9
New cards
An example of an input device that interfaces between computers and humans is
a microphone
10
New cards
Programs that are not running are usually stored
in secondary storage
11
New cards
When a program begins to run
it is moved to the CPU's memory
12
New cards
Which one of the following typically provides data persistence without electricity?

I. The CPU's memory

II. The hard disk

III. Secondary storage
II, III
13
New cards
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
14
New cards
High-level programming languages
are independent of the underlying hardware
15
New cards
Which one of the following translates high-level descriptions into machine code?
compiler
16
New cards
Computer scientists have devised something that allows programmers to describe tasks in words that are closer to the syntax of the problems being solved. This is called (an)
high-level programming language
17
New cards
Small applications written in the Java programming language that can be located on the Internet are called
applets
18
New cards
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
19
New cards
Because Java was designed for the Internet, which two of its attributes make it suitable for beginning programmers?
Safety and portability
20
New cards
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
21
New cards
Which of the following are reasons why Java is good, but not perfect, for beginners?

I. A certain amount of technical machinery is necessary to write basic, simple programs

II. There are many extensions

III. There are a large number of extensive libraries in Java
I, II, III
22
New cards
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
23
New cards
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
24
New cards
What statements about the integrated development environment (IDE) are true?

I. You may run Java class files even after exiting the IDE

II. The IDE can invoke a virtual machine, which is required to run a Java program

III. Translating Java source code into class files is enough to then actually run the program
I, II, III
25
New cards
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
I, II
26
New cards
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, III
27
New cards
Every Java program consists of one or more
classes
28
New cards
Characters that are grouped together between double quotes (quotation marks) in Java are called
strings
29
New cards
Every statement in Java must be terminated with
the semi-colon character ;
30
New cards
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
31
New cards
What is the output from this code snippet?

System.out.print("The sum is ");
System.out.println("7 + 3");
The sum is 7 + 3
32
New cards
Which of the following symbols is used to terminate a Java program statement?
semicolon
33
New cards
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
34
New cards
Which of the following statements is true with respect to the main method in Java?
Every Java application must have a main method
35
New cards
A Java class with the name Printer has to be saved using the source file name:
Printer.java
36
New cards
Which statement starts the declaration of a class in Java?
public class Classname
37
New cards
Which Java statement prints a blank line?
System.out.println();
38
New cards
Which Java statement does not contain an error?
System.out.println();
39
New cards
What is the output of the following code snippet?

System.out.print(4 + 4);
System.out.print(12);
812
40
New cards
What kind of error is it when your program has a syntax error?
Compile-time error
41
New cards
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
42
New cards
What kind of error is created by the following code snippet?

System.outt.println("Hello");
Syntax error: the program will not compile
43
New cards
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
44
New cards
What is a logic error?
An error that occurs when a program is running because, for example, the wrong operator was used
45
New cards
How do programmers find exceptions and run-time errors?
Testing by running the program with a variety of input values
46
New cards
The programmer, not the compiler, is responsible for testing a program to identify
Run-time errors
47
New cards
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
48
New cards
Who or what is responsible for inspecting and testing the program to guard against logic errors?
Programmer
49
New cards
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
50
New cards
Which one of the following methodologies is a sequence of steps formulated in English for solving a program?
Pseudocode
51
New cards
In order to run Java programs on a computer, the computer needs to have software called a(n)
virtual machine
52
New cards
In order to translate a Java program to a class file, the computer needs to have software called a(n)
compiler
53
New cards
The Java statement public static void main(String[] args) declares a
method
54
New cards
A Java virtual machine is
software
55
New cards
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)
56
New cards
What is the output of the following code snippet?

System.out.print("Hello");
System.out.println("Good Day!");
HelloGood Day!
57
New cards
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!");
58
New cards
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
59
New cards
Writing a computer game in Java that has graphics, motion, and sound effects
requires a team of skilled programmers
60
New cards
Which option correctly completes this statement?

Programs can repeat simple instructions very quickly to

I. help human users to perceive images and sound

II. remove the drudgery of repeating instructions by hand

III. overcome the need for connectivity to the computer network
I, II
61
New cards
The ENIAC computer burned out transistors at the rate of
none \-- it used vacuum tubes
62
New cards
In order for the ENIAC computer to be re-programmed
wires needed to be plugged into a different wiring configuration
63
New cards
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
64
New cards
The term "applet" refers to
a Java program that runs within a web browser
65
New cards
Programmers have embraced Java over its closest rival, C++, mainly because
it is easier to use
66
New cards
Java is said to be a "safe" programming language. What does this mean?
Java programs can run within a browser without fear that they may attack your computer
67
New cards
In order for Java to achieve protability
compiled Java programs contain instructions for a virtual machine
68
New cards
A Java Virtual Machine is
a program that simulates a real CPU
69
New cards
The Java programming language is itself relatively simple, but also contains a vast set of
library packages
70
New cards
The source code for a Java program is stored in a file
that ends with a.java suffix
71
New cards
A Java "class" file
contains instructions to the Java virtual machine
72
New cards
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, III
73
New cards
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, III
74
New cards
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
75
New cards
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
76
New cards
In Java, the statement

System.out.print("hello");;;
is a legal statement
77
New cards
Sometimes errors throw the compiler off track because
the compiler does not give up when it find the first error
78
New cards
Some run-time errors are so severe that they generate
an exception
79
New cards
During program development, errors are
unavoidable
80
New cards
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
I, II, III
81
New cards
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
I, III
82
New cards
A sequence of steps that is unambiguous, executable, and terminating is called
an algorithm
83
New cards
The first step in describing an algorithm in pseudo code is
determine the inputs and outputs
84
New cards
1) Which of the following loops executes the statements inside the loop before checking the condition?

a) for
b) while
c) do
d) do-for
Answer: c) do
85
New cards
2) How many times will the following loop run?

int i \= 0;
while (i < 10)
{
System.out.println(i);
i++;
}

a) 0
b) 8
c) 9
d) 10
Answer: d) 10
86
New cards
int i \= 0;
while (i !\= 9)
{
System.out.println("" + i);
i \= i + 2;
}

a) No output
b) 0 2 4 6 8
c) 10 12 14 16 18 .... (infinite loop)
d) 0 2 4 6 8 10 12 14 .... (infinite loop)
Answer: d) 0 2 4 6 8 10 12 14 .... (infinite loop)
87
New cards
4) How many times does the code snippet given below display "Loop Execution"?

int i \= 1;
while (i !\= 10)
{
System.out.println ("Loop Execution");
i++;
}

a) Infinite times
b) 8 times
c) 9 times
d) 10 times
Answer: c) 9 times
88
New cards
5) What is the output of the code fragment given below?

int i \= 0;
int j \= 0;
while (i < 27)
{
i \= i + 2;
j++;
}
System.out.println("j\=" + j);

a) j\=27
b) j\=12
c) j\=13
d) j\=14
Answer: d) j\=14
89
New cards
6) What is the output of the following code snippet?

int i \= 1;
while (i < 10)
{
System.out.print(i + " ");
i \= i + 2;
if (i \== 5)
{
i \= 9;
}
}

a) 1 3 5
b) 1 3 9
c) 1 3 5 7 9
d) 1 3 5 9
Answer: b) 1 3 9
90
New cards
7) The code snippet below checks whether a given number is a prime number. What will be the result of executing it?

public static void main(String[] args)
{
int j \= 2;
int result \= 0;
int number \= 0;
Scanner reader \= new Scanner(System.in);
System.out.println("Please enter a number: ");
number \= reader.nextInt();
while (j
Answer: b) The code snippet will display the desired result.
91
New cards
8) What are the values of i and j after the following code fragment runs?

int i \= 60;
int j \= 50;
int count \= 0;
while (count < 5)
{
i \= i + i;
i \= i + 1;
j \= j - 1;
j \= j - j;
count++;
}
System.out.println("i\=" + i + ", j\=" + j);

a) i \= 1951, j \= 0
b) i \= 1951, j \= 45
c) i \= 65, j \= 1
d) i \= 65, j \= 45
Answer: a) i \= 1951, j \= 0
92
New cards
9) Which error type does the "off-by-one" error belong to?

a) Syntax error
b) Compile-time error
c) Run-time error
d) Infinite loop
Answer: c) Run-time error
93
New cards
10) How many times does the following code fragment display "Hi"?

int i \= 10;
while (i \>\= 0)
{
System.out.println("Hi");
i--;
}

a) 9 times
b) 10 times
c) 11 times
d) 12 times
Answer: c) 11 times
94
New cards
11) What is the output of the following code fragment?

int i \= 1;
int sum \= 0;
while (i
Answer: b) The value of sum is 66
95
New cards
12) How many times does the loop execute in the following code fragment?

int i;
for (i \= 0; i < 50; i \= i + 4)
{
System.out.println(i);
}

a) 11
b) 12
c) 13
d) 14
Answer: c) 13
96
New cards
13) How many times does the following code snippet display "Loop Execution"?

for (int i \= 0; i < 10; i++);
{
System.out.println("Loop Execution");
}

a) Ten times.
b) The code snippet does not run because of a compile error.
c) Infinite loop.
d) Only one time.
Answer: d) Only one time.
97
New cards
14) What is the output of the code snippet given below?

int i;
int j \= 0;
for (i \= 0; i < 5; i++)
{
if (i % 2 \== 0)
{
i \= i + 2;
j++;
}
else
{
i++;
j \= j + 2;
}
j++;
}
System.out.println("i\=" + i + ", j\=" + j);

a) i\=7, j \=7
b) i \=7, j \=6
c) i \=6, j \=7
d) i \=5, j \=5
Answer: d) i \=5, j \=5
98
New cards
15) Which loop does not check a condition at the beginning of the loop?

I. The do loop
II. The while loop
III. The for loop

a) I and II
b) I and III
c) I only
d) III only
Answer: c) I only
99
New cards
16) How many times does the following loop run?

int i \= 0;
int j \= 1;
do
{
System.out.println("" + i + ";" + j);
i++;
if (i % 2 \== 0)
{
j--;
}
}
while (j \>\= 1);

a) 0 times
b) 1 times
c) 2 times
d) 4 times
Answer: c) 2 times
100
New cards
17) A loop inside another loop is called:

a) A sentinel loop
b) A nested loop
c) A parallel loop
d) A do/while loop
Answer: b) A nested loop