MIDTERM JAVA
When a character is stored in memory, it is actually the __________ that is stored.
Unicode number
A runtime error is usually the result of
a logical error
A computer program is
a set of instructions that allow the computer to solve a problem or perform a task
RAM is usually
a set of instructions that allow the computer to solve a problem or perform a task
Java requires that the boolean expression being tested by an if statement be enclosed in
a set of parentheses
What is the following statement an example of? import java.util.*;
a wildcard import statement
What will be displayed after the following statements are executed? int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans);
120
What will be the value of x after the following statements are executed? int x = 75; int y = 60; if (x > y) x = x - y;
15
What will be displayed after the following statements are executed? int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); }
40
There are __________ bits in a byte.
8
Which of the following is not part of the programming process?
All of these are parts of the programming process
__________ refers to the physical components that a computer is made of
Hardware
The original name for Java was
OAK
"Shadowing" is the term used to describe how the field name is hidden by the name of a local or parameter variable.
TRUE
A constructor is a method that is automatically called when an object is created.
TRUE
A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.
TRUE
A procedure is a set of programming language statements that, together, perform a specific task.
TRUE
A solid-state drive has no moving parts and operates faster than a traditional disk drive.
TRUE
All it takes for an OR expression to be true is for one of the subexpressions to be true.
TRUE
An access specifier indicates how a class may be accessed.
TRUE
An important style rule that should be used when writing if statements is to write the conditionally executed statement on the line after the if statement.
TRUE
Application software refers to programs that make the computer useful to the user
TRUE
Each byte is assigned a unique number known as an address
TRUE
Encapsulation refers to the combining of data and code into a single object
TRUE
If the expression on the left side of the && operator is false, the expression on the right side will not be checked.
TRUE
Logical errors are mistakes that cause the program to produce erroneous results
TRUE
The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.
TRUE
The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.
TRUE
The java.lang package is automatically imported into all Java programs.
TRUE
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
TRUE
The boolean expression in an if statement must evaluate to
true or false
Because Java byte code is the same on all computers, compiled Java programs
are highly portable
A characteristic of __________ is that only an object's methods are able to directly access and make changes to an object's data
data hiding
It is common practice in object-oriented programming to make all of a class's
fields private
A __________ is a boolean variable that signals when some condition exists in the program.
flag
Which of the following expressions will generate a random number in the range of 1 through 10?
myNumber = randomNumbers.nextInt(10) + 1;
If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?
str1.equals(str2)
Variables are
symbolic names made up by the programmer that represent memory locations
The data contained in an object is known as
the attributes
The central processing unit (CPU) consists of two parts which are
the control unit and the arithmetic and logic unit (ALU)
To indicate the data type of a variable in a UML diagram you specify
the variable name followed by a colon and the data type
The two primary methods of programming in use today are
procedural and object-oriented
While __________ is centered on creating procedures, __________ is centered on creating objects.
procedural programming, object-oriented programming
A set of programming language statements that perform a specific task is a(n)
procedure
Computers can do many different jobs because they are
programmable
A(n) __________ is used to write computer programs.
programming language
Software refers to
programs
A cross between human language and a programming language is called
pseudocode
One type of design tool used by programmers when creating a model of a program is
pseudocode
looking at the following code waht is wrong with line 7 public class NumericTypes 1. { 2. public static void main (String [] args) 3. { //TASK #2 Create a Scanner object here (not used for alternate) 4. //identifier declarations 5. final int NUMBER = 2 ; // number of scores 6. final int SCORE1 = 100; // first test score 7. final int SCORE2 = 95; /* second test score */
/ missing
looking at the following code which line is wrong if any? If none put 0. public class NumericTypes 1. { 2. public static void main (String [] args) 3. { //TASK #2 Create a Scanner object here (not used for alternate) 4. //identifier declarations 5. final int NUMBER = 2 ; // number of scores 6. final int SCORE1 = 100; // first test score 7. final int SCORE2 = 95; /* second test score */
0
What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = 0.05; else if (purchase > 750) discountRate = 0.03; else if (purchase > 500) discountRate = 0.01;
0.0
What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = 0.08; break; case 'B': discountRate = 0.06; case 'C': discountRate = 0.04; default: discountRate = 0.0; }
0.0
What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = 0.05; else discountRate = 0.04; else if (purchase > 750) if (cust == 'Y') discountRate = 0.04; else discountRate = 0.03; else discountRate = 0.0;
0.04
What will be the value of bonus after the following statements are executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;
1000
What will be the value of x after the following statements are executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }
20
What will be displayed after the following statements are executed? int hours = 30; double pay, payRate = 10.00; pay = hours <= 40 ? hours*payRate : hours*payRate*2.0; System.out.println(pay);
300.0
looking at the following code which line is wrong public class NumericTypes 1. { 2. public static void main (String [] args) 3. { //TASK #2 Create a Scanner object here (not used for alternate) 4. //identifier declarations 5. final float NUMBER = 2 ; // number of scores 6. final int SCORE1 = 100; // first test score 7. final int SCORE2 = 95; /* second test score */
5
A method that gets a value from a class's field but does not change it is known as a mutator method.
FALSE
A random number, created as an object of the Random class, is always an integer.
FALSE
All it takes for an AND expression to be true is for one of the subexpressions to be true.
FALSE
Colons are used to indicate the end of a Java statement
FALSE
Compiled byte code is also called source code
FALSE
In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.
FALSE
Java source files end with the .class extension
FALSE
The DecimalFormat class is part of the Java API so it is automatically available to your programs.
FALSE
The public access specifier for a field indicates that the field may not be accessed by statements outside the class.
FALSE
The term "default constructor" is applied to the first constructor written by the author of the class.
FALSE
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
FALSE
What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x = y) ans = x + 10;
The code contains an error and will not compile
For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }
The z field is available to code written outside the Sphere class.
Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?
Write the code.
Enclosing a group of statements inside a set of braces creates
a block of statements
What is the following statement an example of? import java.util.Scanner;
an explicit import statement
What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x + 10; x -= y; } else { ans = y + 10; y += x; }
ans = 60, x = 0, and y = 50
If you do not provide initialization values for a class's numeric fields, they will
be automatically initialized to 0
One or more objects may be created from a(n)
class
A constructor
has the same name as the class
The __________ statement is used to create a decision structure which allows a program to have more than one path of execution.
if
When an object is created, the attributes associated with the object are called
instance fields
Methods that operate on an object's fields are called
instance methods
Which of the following commands will run the compiled Java program named DoItNow?
java DoItNow
Validating the results of a program is important to
make sure the program solves the original problem
Assume you are at the operating system command line and want to use the following command to compile a program: javac MyClass.java Before entering the command you mus
make sure you are in the same directory or folder where the MyClass.java file is located
A(n) __________ is a software entity that contains data and procedures.
object
Using the blueprint/house analogy, you can think of a class as a blueprint that describes a house and __________ as instances of the house built from the blueprint.
objects
A constructor is a method that
performs initialization or setup operations
Byte code instructions are
read and interpreted by the JVM
looking at the following code waht is wrong with line 7 public class NumericTypes 1. { 2. public static void main (String [] args) 3. { //TASK #2 Create a Scanner object here (not used for alternate) 4. //identifier declarations 5. final int NUMBER = 2 ; // number of scores 6. final int SCORE1 = 100; // first test score 7. final int SCORE2 = 95 // second test score
semi-colon missing
The end of a Java statement is indicated by a ________.
semicolon (;)
The scope of a local variable is
the method in which it is defined
An object typically hides its data but allows outside code access to
the methods that operate on the data
When an argument is passed by value
the parameter variable holds the address of the argument
Application software refers to
the programs that make the computer useful to the user
What is syntax?
the rules that must be followed when writing a program
In an if-else statement, if the boolean expression is false
the statement or block following the else is executed
Key words are
words that have a special meaning in the programming language
Which of the following expressions will determine whether x is less than or equal to y?
x <= y