Saddleback CS 4A Java Midterm – Flashcards

Unlock all answers in this set

Unlock answers
question
The integer Data type (int) does not include the following data type.. 1. long 2. double 3. byte 4. short
answer
2. double
question
Which of the following data types comes under floating point data types? 1. long 2. float & long 3. byte 4. double & float
answer
4. double & float
question
Any assignment statement can be used as an assignment expression.
answer
true
question
The expression 4 + 20 / (3 - 1) * 2 is evaluated to ________.
answer
24
question
To obtain the current hour in UTC, use ________. System.currentTimeMillis() % 3600 System.currentTimeMillis() % 60 System.currentTimeMillis() / 1000 % 60 System.currentTimeMillis() / 1000 / 60 % 60 System.currentTimeMillis() / 1000 / 60 / 60 % 24
answer
System.currentTimeMillis() / 1000 / 60 / 60 % 24
question
Which of the following assignment statements is incorrect? i = j = k = 1; i = 1; j = 1; k = 1; i = 1 = j = 1 = k = 1; i == j == k == 1;
answer
i = 1 = j = 1 = k = 1; i == j == k == 1;
question
24 % 5 is ________.
answer
4
question
A variable may be assigned a value only once in the program.
answer
false
question
If a number is too large to be stored in a variable of the float type, it ________.
answer
causes overflow
question
If you attempt to add an int, a byte, a long, and a double, the result will be a ________ value.
answer
double
question
Math.pow(4, 1 / 2) returns ________.
answer
1.0
question
The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
answer
76
question
To assign a double variable d to an int variable x, you write ________.
answer
x = (int)d;
question
To declare a constant MAX_LENGTH inside a method with value 99.98, you write ________.
answer
final double MAX_LENGTH = 99.98;
question
What is printed? int j = 0; int i = j++ +j*5; System.out.println(i);
answer
5
question
What is the result of 45 / 4?
answer
11
question
What is the value of (double)5/2?
answer
2.5
question
pow is a method in the ________ class.
answer
Math
question
currentTimeMills is a method in the ________ class.
answer
System
question
________ are valid Java identifiers. $Java _RE4 3ere 4+4 int
answer
$Java _RE4
question
You can define a variable twice in a block.
answer
false
question
You can change the value of a constant.
answer
false
question
You can cast a double value to ________. byte short int long float
answer
byte short int long float
question
You can always assign a value of long type to a variable of int type without loss of precision.
answer
false
question
Which of these data types requires the most amount of memory? long int short byte
answer
long
question
Which of these data types requires the least amount of memory? double float short byte
answer
byte
question
Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4)
answer
(A) & (C)
question
Which of the following is a valid identifier? $343 class 9X 8+9 radius
answer
$343 radius
question
Which of the following expressions will yield 0.5? 1 / 2 1.0 / 2 (double) (1 / 2) (double) 1 / 2 1 / 2.0
answer
1.0 / 2 (double) 1 / 2 1 / 2.0
question
Which of the following are correct names for variables according to Java naming conventions? radius Radius RADIUS findArea FindArea
answer
radius findArea
question
___________ is also referred to as the Software Life Cycle, which includes from beginning to end, all of the tasks which are completed while developing your application.
answer
The Software Development Process
question
1. What are the 6 attributes of all variables regardless of computer language or OS? 2. Which attribute is optional
answer
Name (Optional) Memory Location Type Value Scope Lifetime
question
Java source code can be executed on a Java Virtual Machine.
answer
false
question
One byte has ________ bits.
answer
8
question
Why do computers use zeros and ones?
answer
because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
question
If a program compiles fine, but it produces incorrect result, then the program suffers ________.
answer
a logic error
question
If you forget to put a closing quotation mark on a string, what kind error will be raised?
answer
a compilation error
question
Programming style is important, because ________. a program may not compile if it has a bad style good programming style can make a program run faster good programming style makes a program more readable good programming style helps reduce programming errors
answer
good programming style makes a program more readable good programming style helps reduce programming errors
question
Suppose you define a Java class as follows: public class Test { } In order to compile this program, the source code should be stored in a file named ________.
answer
Test.java
question
The ________ loads Java bytecode to the memory.
answer
class loader
question
The compiler generates bytecode even if the program has syntax errors
answer
false
question
The extension name of a Java source code file is ________.
answer
.java
question
The main method header is written as ________.
answer
public static void main(String[] args)
question
The keywords in Java are all in lowercase.
answer
true
question
A ________ is a program that translates Java source code into Java bytecode.
answer
Java interpreter
question
__________ translates high-level language program into machine language program.
answer
A compiler
question
You use ________ to run a Java program.
answer
java
question
The _________ must be the same as the filename that contains the class.
answer
public classname
question
________ is a software that interprets Java bytecode.
answer
Java virtual machine
question
________ is a program that runs on a computer to manage and control a computer's activities.
answer
Operating system
question
________ contains predefined classes and interfaces for developing Java programs.
answer
Java API
question
________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
answer
Java JDK
question
Java compiler translates Java source code into ________.
answer
Java bytecode
question
"abcdefgh".subString(1, 3) returns ________.
answer
bc
question
A Java character is stored in ________.
answer
two bytes
question
An int variable can hold ________. 'x' 120 120.0
answer
'x' 120
question
You can cast a character value to an int, or an int to char.
answer
true
question
Which of the following method returns the sine of 90 degree? Math.sine(90) Math.sin(90) Math.sin(PI) Math.sin(Math.toRadian(90)) Math.sin(Math.PI)
answer
Math.sin(Math.toRadian(90))
question
Which of the following is the correct expression of character 4? 4 "4" '004' '4'
answer
'4'
question
Which of the following is a possible output for (int)(51 * Math.random())? 0 50 100 500
answer
0 50
question
What is the return value of "SELECT".substring(4, 4)? an empty string C T E
answer
an empty string
question
What is Math.round(3.6)?
answer
4
question
What is Math.floor(3.6)?
answer
3.0
question
What is Math.ceil(3.6)?
answer
4.0
question
What is "Welcome" + 1 + 1 * 2?
answer
Welcome12
question
To concatenate s1, s2, s3, and s4, you write ________. s1.concate(s2).concate(s3).concate(s4); s1.concate(s2) + s3.concate(s4); ((s1.concate(s2)).concate(s3)).concate(s4); s1.concate(s2).(concate(s3).concate(s4));
answer
s1.concate(s2).concate(s3).concate(s4); s1.concate(s2) + s3.concate(s4); ((s1.concate(s2)).concate(s3)).concate(s4);
question
Math.ceil(5.5) evaluates to ________.
answer
6.0
question
Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.
answer
A1
question
Suppose s1 and s2 are two strings. What is the result of the following code?
answer
**Sorry lost answer**
question
Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?
answer
c
question
You compare two strings s1 and s2 using ________. compare(s1, s2) s1.compare(s2) compareTo(s1, s2) s1.compareTo(s2)
answer
s1.compareTo(s2)
question
Which of the following assignment statements is correct to assign character 5 to c? char c = '5'; char c = 5; char c = "5"; char c = "344";
answer
char c = '5';
question
The statement System.out.printf("%5d", 123456) outputs ________.
answer
123456
question
The statement System.out.printf("%10s", 123456) outputs ________. (Note: * represents a space)
answer
****123456
question
Analyze the following code: int i = 3434; double d = 3434; System.out.printf("%5.1f %5.1f", i, d); (A) The code compiles and runs fine to display 3434.0 3434.0. (B) The code compiles and runs fine to display 3434 3434.0. (C) i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.
answer
(C) i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.
question
What does the following code output? double price = 19.8; System.out.printf("$%6.2f each", price);
answer
$ 19.80 each
question
After a program executes String name = "Mary, Mary quite contrary"; name.indexOf("Mary", 1); returns ______
answer
6
question
What will be the result of the given code? String s = "StudyTonight"; s+= ".com"; s = s.toUpperCase(); 1. STUDYTONIGHT 2. STUDYTONIGHT.COM 3. studytonight 4. studytonight.com
answer
2. STUDYTONIGHT.COM
question
Which method is used to determine the number of characters in a String object? 1. length() 2. numChars() 3. getLength() 4. None of the above
answer
1. length()
question
To read a string from the console, invoke the[x]() method on a [y] object.
answer
x: next y: Scanner
question
You can use the _____() method to read an entire line of text.
answer
nextLine
question
Strings are ______ in Java.
answer
objects
question
A [x] is a sequence of characters. It is enclosed in matching double quotes ("). A [y] value is enclosed in matching single quotes (').
answer
x: string y: char
question
A break statement can be used only in a loop.
answer
false
question
A continue statement can be used only in a loop.
answer
true
question
A variable declared in the for loop control can be used after the loop exits.
answer
false
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New