NEW
Font size
WorksheetsJava Fundamentals
Total questions: 78
Worksheet time: 1hrs 15mins
Command to compile the Java program
java
javac
javap
javadoc
command to run the java program
javac
javap
javadoc
java
Which of this method is given parameter via command line arguments?
main()
recursive() method
Any method
System defined methods
Which of these data types is used to store command line arguments?
Array
Stack
String
Integer
How many arguments can be passed to main()?
Infinite
Only 1
System Dependent
None of the mentioned
Which of these is a correct statement about args in the following line of code?
public static void main(String args[])
args is a String
args is a Character
args is an array of String
args in an array of Character
Can command line arguments be converted into int automatically if required?
Yes
No
Compiler Dependent
Only ASCII characters can be converted
What will be the output of the following Java program, Command line execution is done as – “java Output This is a command Line”?
class Output
{
public static void main(String args[])
{
System.out.print("args[0]");
}
}
java
Output
is
This
What will be the output of the following Java program, Command line execution is done as – “java Output This is a command Line”?
class Output
{
public static void main(String args[])
{
System.out.print("args[3]");
}
}
a
command
is
This
What will be the output of the following Java program, Command line execution is done as – “java Output command Line 10 A b 4 N”?
java
10
20
b
What will be the output of the following Java snippet, if attempted to compile and run this code with command line argument “java abc Rakesh Sharma”?
Compile time error
Compilation but runtime error
Compilation and output Rakesh :-Please pay Rs.2000
Compilation and output Sharma :-Please pay Rs.2000
What will be the output of the following Java snippet, if attempted to compile and execute?
The snippet compiles, runs and prints 0
The snippet compiles, runs and prints 1
The snippet does not compile
The snippet compiles and runs but does not print anything
What will be the output of the following Java code snippet running with “java demo I write java code”?
The snippet compiles, runs and prints “I code”
The snippet compiles, runs and prints “java code”
The snippet compiles, runs and prints “demo code”
The snippet compiles, runs and prints “java demo”
Which four options describe the correct default values for array elements of the types indicated?
1, 2, 3, 4
1, 3, 4, 5
2, 4, 5, 6
3, 4, 5, 6
Which one of these lists contains only Java programming language keywords?
class, if, void, long, Int, continue
try, virtual, throw, final, volatile, transient
goto, instanceof, native, finally, default, throws
strictfp, constant, super, implements, do
byte, break, assert, switch, include
Which is a valid keyword in java?
interface
string
Float
unsigned
Which three are valid declarations of a float?
1, 2, 4
2, 3, 5
1, 3, 6
2, 4, 6
What is the numerical range of a char?
-128 to 127
-(215) to (215) - 1
0 to 32767
0 to 65535
Which of the following are legal lines of Java code?
1 and 2
All statements are correct
2 and 3
3 and 4
Which of these is necessary condition for automatic type conversion in Java?
The destination type is smaller than source type
The destination type is larger than source type
The destination type can be larger or smaller than source type
None of the mentioned
If an expression contains double, int, float, long, then the whole expression will be promoted into which of these data types?
long
int
double
float
Which of these coding types is used for data type characters in Java?
ASCII
UNICODE
ISO-LATIN-1
None of the mentioned
Which of these values can a boolean variable contain?
True & False
0 & 1
true
Any integer value
Which one is a valid declaration of a boolean?
boolean b1 = 1;
boolean b2 = ‘false’;
boolean b3 = false;
boolean b4 = ‘true’
What will be the output of the following Java code?
0
1
true
false
what is the output of the following code?
byte b=10;
b+=20;
System.out.println(b)
10
30
0
error: incompatible types
what is the output of the following code?
byte b=10;
b=b+30;
System.out.println(b)
10
40
0
error: incompatible types
Which of these is not a bitwise operator?
&
&=
|=
<=
What will be the output of the following Java program?
7 2
7 7
7 5
5 2
What will be the output of the following Java program?
256 0
0 64
64 0
0 256
a = b * 2;
y = x;
z = a – y;
if (x <0)
a = b*2;
y=x;
z=a-y;
}
a = b * 2;
y = x;
z = a – y;
}
{
a = b*2;
y = x;
z = a - y;
}
else x--;
else if (x < 0) x--;
if (x < 0) x--;
else x = 0;
else x++;
x--;
for(int i=0; i<5; i++)
x += i;
Base on the code block below what will be the output to the console?
int number =11;
if(number >=10) {
System.out.print("New York");
}
else if(number<=5){
System.out.print("California");
}
else System.out.print("Texas");
New York
California
Texas
Nothing
Base on the code block below what will print to the console?
var n =5;
for(int i=1;i<=n;i++){
System.out.println(i);
}
1
2
3
4
5
5
4
3
2
1
1
2
3
4
4
3
2
1
Of the following if statements has the correct syntax for executing three instructions if the condition is true?
if (x < 0)
a = b * 2;
y = x;
z = a – y;
{
if (x <0)
a = b*2;
y=x;
z=a-y;
}
if { (x < 0)
a = b * 2;
y = x;
z = a – y;
}
if (x <0)
{
a = b*2;
y = x;
z = a - y;
}
Which one of these control flow statements have three parameters to it?
switch
while
do-while
for
Which one of these control flow statements does not loop
switch
while
do-while
for
Base on the code block below what will be the output to the console?
int number =2;
if(number >=10) {
System.out.print("New York");
}
else if(number<=5){
System.out.print("California");
}
else System.out.print("Texas");
New York
California
Texas
Nothing
Base on the code block below what will be the output to the console?
int number =8;
if(number >=10) {
System.out.print("New York");
}
else if(number<=5){
System.out.print("California");
}
else System.out.print("Texas");
New York
California
Texas
Nothing
Base on the code block below what will print to the console?
var n =5;
for(int i=1;i<n;i++){
System.out.println(i);
}
1
2
3
4
5
5
4
3
2
1
1
2
3
4
4
3
2
1
Base on the code block below what will be the output to the console?
int n=5;
int c=0;
while(n>=0&&c<=5) {
System.out.println(c+":"+n);
c++;
n--;
}
1:1
2:2
3:3
4:4
5:5
1:4
2:3
3:2
4:1
0:5
1:4
2:3
3:2
4:1
5:0
0:0
1:1
2:2
3:3
4:4
5:5
Which control flow statement provides a compact way to iterate over a range of values.; by allowing a (initialization; termination; increment) condition in its statement.
While
Switch
If
For
Base on the code block below what will print to the console?
int x=10;
do {System.out.println(x*2);
x--;}
while(x>10);
20
infinite loop
200
20000000
What will be the output of the program?
12 15
3 4 5 3 7 5
15 15
3 7 5 3 7 5
What will be the output of the program?
true
false
Compilation fails
An exception is thrown at runtime
What will be the output of the program?
small
huge
tiny
Compilation fails
What will be the output of the program?
small
huge
tiny
Compilation fails
What will be the output of the program?
5 3
6 3
6 4
5 2
What will be the output of the program?
5 3
8 3
8 2
8 5
What will be the output of the program?
0
7
8
14
What will be the output of the program?
ok
ok dokey
dokey
No output is produced
What will be the output of the program?
9 7 7 foo 7 7foo
72 34 34 foo34 34foo
9 7 7 foo34 34foo
72 7 34 foo34 7foo
What will be the output of the program?
7 7
14 0
7 14
14 14
What will be the output of the program?
null null 42
0 0 42
0 42 42
0 0 0
What will be the output of the program?
count = 0
count = 2
count = 3
count = 4
What will be the output of the program?
2
4
8
16
What is the output?
There is a syntax error on line 1.
There are syntax errors on lines 1 and 6.
There are syntax errors on lines 1, 6, and 8.
There is a syntax error on line 6.
What will be the output of the program?
j = -1
j = 0
j = 1
Compilation fails.
What will be the output of the program?
i = 5 and j = 5
i = 6 and j = 5
i = 5 and j = 6
i = 6 and j = 4
What will be the output of the program?
0 2 4
0 2 4 5
0 1 2 3 4
Compilation fails.
What will be the output of the program?
a
b
c
d
