1/140
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
True or False: The word import in a Java program is a key word reserved by the language.
True
True or False: A byte can contain either 32 or 64 bits.
False
True or False: According to the Java standard naming convention class names and variables must start with an upper case letter and must contain a number.
False
True or False: Each byte is assigned a unique number known as a bytecode.
False
True or False: In computers, data is stored in a hexadecimal form, which is denoted as 0x00-0x11.
False
True or False: What is the value of b after executing these statements
boolean b;
int x = 10, y = 7, z =10;
if (x>y && y>z) b = true;
if (y
if (x
False
True or False: The Java Virtual Machine is responsible for executing Java Byte Code.
True
True or False: Java runs differently on different CPU architectures.
False
True or False: A declared variable is always visible to the entire method in which it is declared.
False
True or False: Because the || operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left.
True
True or False: Logical errors are mistakes that are not caught by the compiler.
True
True or False: When two Strings are compared using the equals method, their cases are ignored.
False
True or False: System.out.print, the nextInt in the Scanner class and main are all "methods".
True
True or False: In Java, a method call can only be executed once.
False
True or False: Suppose we have the following declarations
int a = 5, b=3;
is (a* (b/a) ==3) true or false?
False
What is the output of the following code fragment?
String x = "Java rules!";
String y = "TAMU!";
if (y.charAt(3) == x.charAt(1))
System.out.println(y.length());
else
System.out.println(x.length());
11
What would be the value of the x after the following statements were executed?
int x = 17;
switch (x){
case 17:
x += 15;
case 18:
x-= 15;
case 20:
x = 10;
break;
default:
x*=3;
}
10
The name of a variable is known as its...
Identifier
Each different type of CPU has its own...
Machine language
Which one of these is a valid comment in Java
\\ this is a comment
A syntax error differs from a runtime error in that...
syntax errors are reported by the compiler
In the Java programming language, an argument is used to...
provide valued to an invoked method
What is the output of the following code segment?
System.out.print*"A\t" + 4 + "\tB");
A 4 B
The import statement...
allows access to classes defines elsewhere
The keyword 'new'...
allocates memory for the object
Where does the interpreter begins execution?
The interpreter executes instructions as they are read.
Primitive data types
byte
short
int
long
float
double
boolean
char
Which of the following is valid?
(a) short x;
int y;
double z;
x=y=z=3;
(b) String y;
char z;
z = 'a';
y = z;
(c) float w;
double v;
w = 1.0f;
v = w;
(d) float v;
int y;
v = 5.0;
y = v;
c
What will be the output after the following statements have been executed?
int x = 5, y = 13;
double z;
z = (double)(y/x);
z += y;
z -= x;
System.out.println(z);
10.0
The major components of a typical computer system consist of...
The CPU
Input/Output devices
Main memory
Secondary storage decives
What is wrong with this code?
class TestClass{
public static void main(String [] args){
int x = 0;
double y = 3;
if (x == y) System.out.println("Equal");
if (x
There is nothing wrong
A program is a sequence of instructions stored in..
memory
When a computer is running a program, the CPU is engaged in a process formally known as...
The fetch/decode/execute cycle
Variables are...
symbolic names made up by the programmer that represent locations in the computer's RAM
What will be printed when the following code is executed?
double x = 13579.246;
DecimalFormat formatter = new DecimalFormat("#,##0.0");
System.out.println(formatter.format(x));
13,579.2
RAM is usually...
A volatile type of memory, used only for temporary storage
Key words are...
Words that have a special meaning in the programming language and words that cannot be re-defined by the programmer
A Java program must have one of these...
a main method
What will be printed when the following code segment is executed?
int y = 32;
if (y <= 40)
{
int x = 30;
x += y;
}
System.out.print("x = ");
System.out.print(x);
There will be a compile error.
In Java, ____________ must be declared before they can be used.
variables
If the following Java statements are executed, what will be displayed?
System.out.println("The top three teams are\n\n");
System.out.print("new England Patriots\n");
System.out.print("Greenbay Packers");
System.out.println("Seattle Seahawks");
The top three teams are
New England Patriots
Greenbay PackersSeattle Seahawks
In the following Java statement what value is stores in the variable name?
String name = "Hillary Trump";
The memory address where "Hillary Trump" is located
What will be displayed as a result of executing the following code?
int x = 5, y = 14;
x += 30;
if (x > 32) y/= 4;
System.out.println("x = " +x+ ", y = " +y);
x = 35, y = 3
What will be displayed as a result of executing the following code?
public class Test
{
public static void main(String [] args)
{
int value1 = 15;
System.out.println(value1);
int value2 = 10;
System.out.prinltn(value2);
System.out.println(value3);
int value3 = 3;
}
}
There will be a compile error.
What does the following code display?
int a = 6;
double b = 16.2;
System.out.printf("%2.3f %4d\n", b, a);
16.200 6
If chr is a character variable, which of the following if statements is written correctly?
(a) if (chr = "h")
(b) if (chr == "e")
(c) if (chr == 'I')
(d) if (chr = 'I')
(e) if (chr == o)
c
What is the value of z after the following code has been executed?
int x = 13;
int y = 16, z = 6;
if (y < x);
z += x;
19
What would be the value of bonus after the following statements are executed?
int bonus, sales = 2500;
if (sales > 2000)
bonus = 1000;
if (sales > 500);
bonus = 250;
if (sales > 50)
bonus = 25;
else
bonus = 0;
25
True or False: The private method modifier means the method is available to code outside the class.
False
True or False: The PrintWriter class will append to an already existing file.
False
True or False: A return statement used in a void method terminates the program.
False
True or False: Java provides unary operators that let the programmer increment and decrement variables
True
True or False: A method can take values of expressions as arguments.
True
True or False: A variable's scope is always the entirety of the class in which the variable is declared.
False
True or False: When you use the Scanner class, the class can potentially throw an IOException.
True
True or False: A value-returning code fragment results in an infinite loop.
int i = 100;
while (i != 100){
i--;
}
False
True or False: A class defines how the object created from this class will work.
True
True or False: Local variables are stored in an area of memory called stack.
True
True or False: Since the do-while loop always executes for at least one iteration, it requires its conditions to be true for the first iteration.
False
True or False: In a for statement, the control variable must be incremented by 1 for each iteration.
False
True or False: When the continue statements is encountered in a loop, the execution continues from the beginning of the body of the loop.
False
True or False: An array index can be a double value.
False
What will be printed after the following code is executed?
for (int number = 5; number <= 10; number -=3)
System.out.print(number + ", ");
An infinite series of numbers
Which of the following will open a file named SomeText.txt and allow you to read data from it?
(a) File file = new File ("SomeText.txt);
Scanner inputFile = new Scanner(file);
(b) File file = new File("SomeText.txt");
(c) PrintWriter inputFile = new PrintWriter(SomeText.txt);
(d) Scanner inputFile = new Scanner("SomeText.txt");
(e) File file = new File("SomeText.txt);
Scanner inputFile = new Scanner(System.in);
a
You can use this method to determine whether a file exists.
The File class's exists method
Methods are commonly used to...
break a problem down into small manageable pieces
Which method return type is invalid?
(a) int
(b) double
(c) Scanner)
(d) String
(e) class
e
If method A calls method B, and method B calls method C, and method C calls method A, when the last call to method A finishes, what happens?
control is returned to method C
Which of the following would be a valid method call for the following method?
public static void decideWinner(char c, int num1, double num2)
{
int winner;
winner = num1 * (int)num2;
System.out.println("The winner is " +winner);
}
(a) decideWinner('d', 4.1, 3.0);
(b) decideWinner('a', 4, 2);
(c) decideWinner("c", 9, 2.1);
(d) decideWinner('b', 3.7, 5);
(e) all of the above
b
When an object, such as a String, is passed as an argument, it is...
actually a reference to the object that is passed
A parameter variable's scope...
is the method in which the parameter is declared.
What is the output of the following code?
int a = 2, b = 2;
while (--a > 0 && b++ > 0){
System.out.println(a + " " + b);
1 3
Local variables...
are only meant for use in the method they are declared and lose the values stored in them between calls to the method in which the variable is declared.
Which of the following values can be passed to a method that has an int parameter variable?
(a) int
(b) short
(c) double
(d) A and B
(e) all of the above
d
When you pass an argument to a method...
it initializes the parameter variable in the method definition.
The method header must specify....
The parameters of the method and the data type of the return value.
The phrase divide and conquer is sometimes used to describe...
the process of breaking a problem down into smaller pieces.
The values of local variables...
are lost between calls to the method in which they are declared
Local variables can be initialized with...
constant values
values passed into the method via parameters
the results of an arithmetic operation
How many "USA" are displayed from the following code fragment?
int count = 0;
while (count < 8)
System.out.println("USA");
count ++)
Infinite
Consider the following program:
for (int loop1 = 0; loop1 <= 11; loop1++)
for (int loop2 = 0l loop2 <=11; loop2++)
System.out.println("1");
How many lines of output will be printed?
144
Class objects normally have ____________ that perform useful operations on their data, but primitive variables do not.
methods
For the following code, which statement is not true?
public class Car
{
private String make;
public double price;
private int year;
private String owner;
}
(a) price is available to code that is written outside the Car class.
(b) make is not available to code written outside the Car class.
(c) owner is available to code that is written outside the Car class.
(d) make, price, year, and owner are called data fields of the Car class.
(e) Class Car can have both public and private fields, even though it is declared public
c
What will be the value of sum after the following code is executed?
int sum, left = 5, middle = 1, right = 4;
sum = (left++) * (middle++) / (++right);
1
Each repetition of a loop is known as what?
an iteration
What will be the value of a after the following code is executed?
int a = 3, b = 17;
while (b < 100)
{
a+= b;
b -+a;
}
This is an infinite loop
__________ is the process of inspecting data given to the program by the user and determining if it is reasonable.
Input Validation
How many times will the following for loop be executed?
for (int count = 15; count <= 26; count++)
System.out.println("How many times?");
12
What value is not stored in the array?
int[] array = new int[10];
for (int i = 0, i < array.length; i++)
array[i] = i;
System.out.println(array[4]);
10
This is a value that signals when the end of a list of values has been reached.
Sentinel
This type of loop is ideal in situations where the exact number of iterations is known.
for
Given the following statement, which statement will write "AGGIES" to the file DiskFile.txt?
PrintWriter pwtr = new PrintWriter("DiskFile.txt);
(a) System.out.println(diskOut, "AGGIES");
(b) pwtr.println("AGGIES");
(c) DiskFile.println("AGGIES");
(d) PrintWriter.println("AGGIES");
(e) None of the above
b
What will be the values of x and y as result of the following code?
int x =4, y =7;
x += y++;
y = --x + --x;
x *= y--;
x = 171
y = 18
Which of the following are pre-test loops?
(a) while, for, if, do-while
(b) while, do-while
(c) for, do-while
(d) while, for
(e) for, if, while
d
To determine the value of an array during runtime each array has a field associated with it called...
length
True or False: The enhanced for loop can be used to change the elements in an array.
False
True or False: An advantage of ArrayList over arrays is that they can hold different types.
False
True or False: A single copy of a class's static field is shared by all instances of the class.
True
True or False: Instance methods should have the keyword static in their headers.
False
True or False: An array can only hold values of primitive types.
False