Font size
WorksheetsJAVA FINAL TEST 01
Total questions: 112
Worksheet time: 4hrs 44mins
Which of these packages contain classes and interfaces used for input & output operations of a program?
java.util
java.lang
java.io
all of the mentioned
Which of these class is not a member class of java.io package?
String
StringReader
Writer
File
Which of these classes is used for input and output operation when working with bytes?
InputStream
Reader
Writer
All of the mentioned
Which of these method of InputStream is used to read integer representation of next available byte input?
read()
scanf()
get()
getInteger()
Which of these class is used to read characters in a file?
FileReader
FileWriter
FileInputStream
InputStreamReader
Which of these is a process of writing the state of an object to a byte stream?
Serialization
Externalization
File Filtering
All of the mentioned
Which of these is method of ObjectOutputStream class used to write the object to output stream as required?
Write()
write()
StreamWrite()
writeObject()
Which of these is method of ObjectIntputStream class used to read the object from input stream as required?
read()
Read()
StreamRead()
readObject()
How an object can become serializable?
If a class implements java.io.Serializable class
If a class or any superclass implements java.io.Serializable interface
Any object is serializable
No object is serializable
Serializaed object can be transferred via network.
True
False
Difference between System.out.print() and System.out.println()?
print() prints out to the current line and does not go onto a new line like println() does.
They are the same and it is up to the user on which one is used.
println() prints out to the current line and does not go onto a new line like print() does.
Is Java a static language or dynamic?
Static
Dynamic
int x = 1;
x += 3;
int y = 6;
x = y
System.out.println(x);
What is the console output from the code above?
It would result in an error.
The output would be the number 4.
The output would be the number 6.
The output would be the number 3
int x = 40;
for (int i = 0; i < x; i++){
// Do stuff
}
Is this the correct way to write a for loop?
True
False
Java does not support.
Multiple Inheritance
Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Scanner class in Java belongs to which package?
io
util
lang
net
Which of the following is correct way of writing class name in Java?
MyClass
myclass
MYclass
MYCLASS
Which of the following is correct way of writing function name in Java?
myfunction( )
myFunction( )
MYFUNCTION( )
MyFunction( )
Package name in Java should be written in?
Small letter
Capital letters
What is the correct way of creating object in Java?
ClassName object_name;
ClassName object_name = new ConstructorName( );
ClassName new = object_name ConstructorName( );
ClassName object_name = ConstructorName( );
Which of the following is NOT used while writing main() function in Java?
public
static
void
private
1. main() function is compulsory in Java.
2. Every program in Java should have at-least one class.
Only 1 is true
Only 2 is true
Both are true
Both are false
Array is
immutable
mutable
always contant
Which of the following are built-in packages in Java? Select TWO correct answers.
util
stdio
io
out
Which java package is used to create GUI application programs?
java.lang
java.awt
java.io
Which event is generated when clicking a Button?
ActionEvent
ClickEvent
WindowEvent
Which one of the following is not a swing GUI component?
JFrame
JLabel
Button
JTextField
Which of one of the following package does not contain GUI components?
java.applet
java.awt
javax.swing
java.io
The statement JFrame myFrame = new JFrame(); creates a JFrame that is _______.
invisible and has no title
invisible and has a title
visible and has no title
visible and has a title
Window created in a java program can be made to show using the method
display()
setVisible()
focus()
How would you change the text of a label to the text contained by an integer named num;
label.setText(num);
label.updateText(num);
label.setTest("num");
label.setText(num+ "");
Math class is a part of Java.________ package
io
util
lang
what will be the output of Math.sqrt(-4.0)
2
-2
NaN
What will be the return value of Math.pow(2.0,3.0)
8.0
8
NaN
__________ function returns the magnitude of the number without the sign
Math.round
Math.floor
Math.abs
The return value for Math.round(-51.2) is
-51
-50
-52
Math.ceil() will always return _____ data type
integer
float
double
The output of the function Math.ceil(-31.987)
-31.0
-32.0
-30.0
The output of Math.floor(36.987) is
36
37
35
The output of the function Math.floor(-0.9)
1
0
-1
Math.max(-43,-41) will return
-43
-41
NaN
extends keyword is used in java for...?
Inheritance
Interfaces
Copying a class
No answer
Re-usability is achieved with.........
interface
object
class
Which of the below are reserved keyword in Java?
Array
goto
null
None of the above
What are the valid statements for static keyword in Java?
We can have static block in a class.
The static block in a class is executed every time an object of class is created.
We can have static method implementations in interface.
We can define static block inside a method.
Which of the following is not a Java features?
Dynamic
Architecture Neutral
Use of pointers
Object-oriented
which of the following is wrapper class in java
Float
Integer
Double
all of above
which one of the following is a legal decelration of a two- dimensional array of integers
int[] a[] = new int[5][];
int[5][5] a = new int[][];
int a = new int[5,5];
int[][] a = new int[][5];
which interface needs to be implemented in order to make an object seralized
clonnable
remote
seralizable
none of the above
which of this class is used by character streams for reading data from buffer
BufferReader
InputStreamReader
FileReader
FileInputStream
What index value is used to locate the last element in the nums ArrayList?
nums.size()-1
nums.length()-1
nums.size()
nums.length
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6For the array:
int stats[3];
What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
int [] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums?
nums[4]
nums[3]
nums(4)
nums(3)
a = {0, 2, 3, 4} and v = 1?
a = {0, 2, 3, 4} and v = 3?
a = {0, 2, 3, 4} and v = 2?
A variable that holds words
String
boolean
int
float
A dictionary
A variable that holds true or false
String
boolean
int
float
Alex Trebek
Name the data type: 1.0
double
int
char
boolean
Name the data type: "true"
boolean
char
String
double
Name the data type: false
String
boolean
int
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
Describe method.
A component of a program in a big program.
A program to perform a specific task.
A component of a program written to perform a specific task.
A variable that use to read an input.
There two (2) types of method which are
return
Standard library
User defined
non-return
This is a general structure a method.
<Returnvalue type> <Method Name> (argument / s)
<Modifier> < type> <Method Name> (parameter / s)
public static void main (String[ ] args)
<Method Name> (parameter)
This is an example of a non-return method.
True
False
In which line is representing the meaning of Standard library method.
Line 2
Line 8
Line 13
Line 10
Identify the line with syntax error.
Line 8 and Line 15
Line 10 only
Line 6, Line 8, Line 10
Line 8, Line 11 and Line 15
Identify and fix the syntax error.
Mismatched of the argument and parameter.
Fix with :- call.Display(name,age);
Wrong name of the class to declare the method call object.
Fix with :- Greeting call = new Greeting( );
Wrong type of return type method.
Fix with :- int Display (int number, String member);
Wrong method's name in calling the method.
Fix with :- call.Greeting(name,age);
This program is consist with syntax error. Identify the reason and fix the error with the most suitable answer.
Mismatched with data type of radius and height.
FIx with :- char radius, height;
Mismatched with data type of r and h in method.
FIx with :- int r, h;
Mismatched with variable name of radius and height.
FIx with :- double r, h;
Mismatched with data type of radius and height.
FIx with :- double radius, height;
How many stars are printed?
7
3
4
5
Infinite Loop
In total, how many times is the inner loop executed?
5
10
15
50
Infinite Loop
How many times does the loop print a *
40
20
24
30
Infinite Loop
What does the following code print?
A rectangle of 8 rows with 5 stars per row
A rectangle of 8 rows with 4 stars per row
A rectangle of 6 rows with 5 stars per row
A rectangle of 6 rows with 4 stars per row
Infinite Looo
What does the following code print?
A rectangle of 9 rows with 5 stars per row
A rectangle of 6 rows with 6 stars per row
A rectangle of 7 rows with 5 stars per row
A rectangle of 7 rows with 6 stars per row
Infinite Loop
What does the following code print?
5 6 7 8 9
4 5 6 7 8 9 10 11 12
3 5 7 9 11
3 4 5 6 7 8 9 10 11 12
How many times does the following method print a *?
9
6
7
10
If a loop condition is never satisfied then the loop does not execute.
1 2 4 8 16 32 64
1 2 4 8 16 32
2 4 8 16 32 64
2 4 8 16 32
4 8 16 32 64
200 66 22 7 2
66 22 7 2
200 66 22 2
200 66 22
7
10
15
17
22
25
2
5
7
9
13
20
-1 0 2 5
-1 0 3 7
-1 1 4 8
0 2 5 9
0 1 3 7
0.0
-4.0
5
The program will end successfully, but nothing will be printed.
Nothing will be printed. Run-time error: ArithmeticException.
Which data type gets returned from length() method in String class?
double
String
int
number
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
Which is correct method to convert String into uppercase
changeUpperCase()
convertUpperCase()
toUpper()
toUpperCase()
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
What will be the output of below code?
String statement = "Outfit of the day";
System.out.println(statement.Substring(3,6));
it of
tfit
fit
FIT
Choose most appropriate purpose of trim() method in String?
to remove white spaces
to get a substring of the string
to cut String at desired index
to remove extra white spaces from start and end of String
What is the return type of equalsIgnorecase() method?
int
String
char
boolean
What is the most appropriate way to check if two Strings are identical?
string1 == string2
string1.equals(string2)
string1.same(string2)
string1.equalsIgnorecase(string2)
What is the correct relation between length and last-index of array?
last-index is always 1 more than the length
last-index is 1 less than the length (but not always)
last-index is always 1 less than the length
last-index is always equal to the length
What is word.length()?
What is word.charAt(7) ?
What is word.startsWith("A few") ?
String word = "A few good men";
What is word.indexOf(“f”)?
2
0
1
3
What is word.substring(3, 7) ?
Consider the given code. What would be the display on the screen?
Class A
Class B
Class C
Compile error
