Font size
WorksheetsMSTIP-CC102-FinalExam
Total questions: 90
Worksheet time: 2hrs 30mins
All Java programs begin execution in this method:
start()
main()
runUntilHalt(int)
main(String[])
The Collections Framework is a group of Java components in the
java.lang package
com.java.util package
java.structures package
java.util package
java.storage package
Your custom package code space should take the following form:
anything-i-want
#$_3@&-*
<org-category>.<org-name>.<project-name>
<target-platform>.<year>.<month>
To output data to the screen, we use a command called?
Print.out.line
System.out.print
Print Screen
Data.out.printline
Select the properly formed comment:
\* This is a valid comment *\
/ This is a valid comment
// This is a valid comment
?* This is a valid comment *?
Select the properly formed output line to generate the following output:
Hello World!
System.out.print(Hello World!);
System.out.println("Hello World!");
System.out.print("Hello World);
System.out.print("Hello World!")
What is the output for the following statement:
System.out.print("1"+"1");
11
2
Error Message
Indicate the actual output of the statements below:
int thisYear = 2019;
System.out.println("The current year is "+thisYear);
The current year is thisYear
The current year is 2019
No output; an error exists
The current year is2019
Which term below means violating a programming language's rules on how symbols can be combined to create a program?
Logic Error
Style Error
Program Error
Syntax Error
Which provides runtime environment for java byte code to be executed?
JDBC
JVM
JAVAC
JAVA
The ----------------- define only abstract method and final fields.
classes
package
interface
method
the type ------------------- specifies a single precision value that uses 32 bits of storage
byte
short
float
double
1. The --------- package contain classes for primitive type, string, math functions and thread.
java.io
java.lang
java.util
java.new
which of the following method used to draw a square
drawRect()
drawLine()
drawString()
drawPolygon()
What is the value of y after evaluation: x = 7; y = ++x * 3 - 2
19
20
21
22
What is the value of y after evaluation: x = 7; y = ++x * 3 - 2
19
20
21
22
What type of values represent the outcome of the relational and logical operators?
constant values
Boolean values
null values
absolute values
Which of the following options is NOT a relational operator?
==
!=
&&
>=
Select the option to is equivalent to z-=10
z = 10 - z
z = z - 10
All of the above
NONE OF THESE
If-else is an example of what kind of statement?
if (time < 18)
{ System.out.println("Good day."); }
else
{ System.out.println("Good evening."); }
Expression Statement
Block Statement
Selection Statement
Return Statement
When will you use a "while loop"?
If the number of iteration is not fixed
If the number of iteration is not fixed and you must have to execute the loop at least once.
If the number of iteration is fixed
If the number of iteration is fixed and you must have to execute the loop at least once.
When will you use a "do-while loop"?
If the number of iteration is not fixed
If the number of iteration is not fixed and you must have to execute the loop at least once.
If the number of iteration is fixed
If the number of iteration is fixed and you must have to execute the loop at least once.
Of the following if statements, which one correctly executes two instructions if the condition is true?
if (x < 0)
a = b * 2;
y = x;
{ if (x <0)
a = b*2;
}
if { (x < 0)
a = b * 2;
y = x; }
if (x <0)
{ a = b*2;
y = x; }
Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?
if (x > 0) x++;
else x--;
if (x > 0) x++;
else if (x < 0) x--;
if (x > 0) x++;
if (x < 0) x--;
else x = 0;
if (x == 0) x = 0;
else x++;
x--;
If x is an int where x = 0, what will x be after the above loop terminates?
64
100
128
None of the above, this is an infinite loop
Given the above code, where x = 0, what is the resulting value of x after the for-loop terminates?
for(int i=0; i<5; i++)
x += i;
4
5
10
15
How many times will the above loop iterate?
0
9
10
11
If the Loop-Continuation Condition is omitted in for/while statement, the executes ____________
only one
zero number of times
infinite number of times
Error
Which of the following is Boolean Logical AND operator/ bitwise Operator?
&
&&
|
||
Which of the following primitive data type is a 1-bit and has only two values: true and false
char
string
int
boolean
The arithmetic operators +, -, *, /, and % perform mathematical operations on (a) and values.
(a) provide a service to clients.
Object behaviors are specified via (a) .
In the expression x + y, + is the operator, while x and y are its (a) .
The (a) + and - require only a single operand.
Arithmetic expressions mixing +, -, *, and/or / are evaluated in the same order as they are in ____________ _________________ .
(a)
_________ ________ follow the identifier naming rules.
(a)
Any (a) operands are converted into strings.
Java's statements involving (a) with simple arithmetic modification have convenient abbreviations.
Java's statements involving (a) with simple arithmetic modification have convenient abbreviations.
An object is an active agent that provides a service to (a) .
It is like a plan or (a) that defines objects.
(a) must be created to provide a service to clients.
The (a) can be used to concatenate two strings.
A parameter used in the method definition is called a __________ ______________.
(a)
Object values are called (a) .
As in ________________ _____________________, parentheses can be used to override the normal order of evaluation.
(a)
The (a) associates a method call with a particular object.
A (a) defines the structure of an object.
Like a mathematical function, a method can accept information via (a) and compute a result.
A (a) is the user of an object.
A (a) has exactly one definition, but it can be invoked zero or more times.
The types of a method's parameters must be specified within its (a) .
A method's result is indicated by a ____________ _________________.
(a)
(a) come in three varieties: single line, multiple line, and documentation comments.
The new operator creates an object from its ___________ ________________.
(a)
(a) comments improve the readability of source code.
Variables declared within a method are called _____________ __________________.
(a)
__________ _____________ elements are accessible anywhere; private class elements are only accessible within the class itself.
(a)
Local variables are isolated from all other variables within the (a) or interactive session.
A parameter used during a method invocation is called an ___________ __________________.
(a)
Who is the developer/founder of Java programming language?
Rasmus Lerdorf
James Gosling
Dennis Ritchie
Timothy Berners-Lee
What are the following <<, >>, &, ^, | symbols?
Bitwise Operators
Comparison / Relational Operators
Logical Operators
Assignment Operators
int x=32, y=2, z=0;
z = (x+100)*y;
z = (a)
int z = 300 % 10 *10;
z= (a)
int a=17, b=5;
int c=a/b+(a+b);
c = (a)
public static void main(String[] args) {
int a= ~10;
System.out.println(a);
}
(a)
A character with a backslash (\) just before it (ex. \n, \t, \r)
special character
reserved word
user-defined word
escape sequence
What is the result of this statements?
int a=10, b=3;
System.out.println(a<<b);
(a)
What is the result of this statements?
int a=10, b=3;
System.out.println(a>>b);
(a)
What is the result of this statements?
int a=10, b=3;
System.out.println(a & b);
(a)
What is the result of this statements?
int a=10, b=3;
System.out.println(a ^ b);
(a)
What will be the output of the following Java code?
class increment {
public static void main(String args[]){
int g = 3;
System.out.print(++g * 8); }
}
32
33
24
25
What is the extension of compiled java classes?
.txt
.class
.js
.java
What will be the output of the following Java program?
final class A {
int i;
}
class B extends A {
int j;
System.out.println(j + " " + i);
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
2 2
3 3
Runtime Error
Compilation Error
Here the class name is
(a)
memeber function name is
(a)
How do you call a method in Java?
methodName();
methodName[];
(methodName);
methodName;
The value of a string variable can be surrounded by single quotes.
true
false
The following are considerations if using if-else-if-else statement, which is not correct:
An if can have zero or one else’s and it must come after any else if’s
An if can have zero to many else if’s and they must come before else.
Once an else if succeeds, none of the remaining else if’s or else’s will be tested.
This statement can only have 2 to 3 elses.
An If statement sometimes uses the form if condition then code, where condition is a Boolean expression and code is code that is executed if the condition is TRUE but if the condition is not true will give us FALSE statement result.
TRUE
FALSE
We use if-else statements in making decisions in our programs but sometimes it is necessary to add additional conditions to accommodate several conditions in our programs that’s where if-else-if-else statement comes in
TRUE
FALSE
Create an example of a for-each loop. Take this array as a base
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
---> please use i as a variable.
All you have to do is print the array but use a for-each is a must!
(a)
What is the purpose of camelCase in Java naming conventions?
Which of the following is true about Java identifiers?
Explain the difference between int and double data types in Java.
The int data type is used to store decimal values, while the double data type is used to store whole numbers.
The int data type is used to store integer values, while the double data type is used to store floating-point numbers with decimal values.
The int data type is used to store floating-point numbers, while the double data type is used to store integer values.
The int data type is used to store both integer and floating-point numbers, while the double data type is used to store only integer values.
What will be the output of the following code
import java.util.Arrays;
import java.util.Comparator;
public class ComparatorTest {
public static void main(String args[]){
String[] ar= {“c”,”d”,”b”,”a”,”e”};
InnerClass in=new InnerClass();
Arrays.parallelSort(ar, in);
for(String str : ar)
System.out.println(str +””);
System.out.println(Arrays.binarySearch(ar, “b”));
}
static class InnerClass implements Comparator<String>{
public int compare(String s1, String s2){
return s2.compareTo(s1);
}
}
}
e d c b a -1
a b c 0 e d
d b c e a 1
e b a d c
What will be the output of the following code
import java.util.LinkedHashSet;
import java.util.Set;
public class LinkedHashSetTest {
public static void main (String args[]){
Set s=new LinkedHashSet();
s.add(“1”);s.add(1);
s.add(3);
s.add(2);
System.out.println(s);
}
}
[1, 1, 2, 3]
[1, 2, 2 3[
[1, 1, 3, 2]
[1, 2, 3]
Indicate the actual output of the statements below:
int thisYear = 2019;
System.out.println("The current year is "+thisYear);
The current year is thisYear
The current year is 2019
No output; an error exists
The current year is2019
Choose correct option.
Base::show() called
Derived::show() called
Compiler Error
Runtime Error
