Questionnaire
What is the numerical range of a char data type in Java?
Which of these coding types is used for data type characters in Java?
Which of these values can a boolean variable contain?
Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
Which one is a valid declaration of a boolean
What is the order of variables in Enum?
Can we create an instance of Enum outside of Enum itself?
What will be the output of the following Java code?
enum Season
{
If weWINTER,
try to add Enum constants
SPRING, SUMMER,to a TreeSet, what sorting order will it use?
FALL
};
What will be the output of the following Java code snippet?
System.out.println(Season.WINTER.ordinal());
class A
{
}
enum Enums extends A
{
ABC, BCD, CDE, DEF;
}
What will be the output of the following Java code snippet?
enum Levels
{
private TOP,
public MEDIUM,
protected BOTTOM;
}
Which method returns the elements of Enum class?
Which of the following is the advantage of BigDecimal over double?
Which of the below data type doesn’t support overloaded methods for +,-,*
What will be the output of the following Java code snippet?
double a = 0.02;
double b = 0.03;
double c = b - a;
System.out.println(c);
BigDecimal _a = new BigDecimal("0.02");
BigDecimal _b = new BigDecimal("0.03");
BigDecimal _c = b.subtract(_a);
System.out.println(_c);
How to format date from one form to another?
How to convert Date object to String?
How to convert a String to a Date object?
Is SimpleDateFormat thread safe?
How to identify if a timezone is eligible for DayLight Saving?
How is Date stored in database?
How to get difference between two dates?
What will be the output of the following Java program?
class evaluate
{
public static void main(String args[])
{
int a[] = {1,2,3,4,5};
What will=be
int d[] a; the output of the following Java program?
int sum = 0;
class
forarray_output
(int j = 0; j < 3; ++j)
{ sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
public static void main(String args[])
System.out.println(sum);
{
What} will be the output of
int array_variable [] =the
newfollowing
int[10];Java program?
} variable_scope
class
for (int i = 0; i < 10; ++i) {
{ array_variable[i] = i/2;
public static void main(String args[])
array_variable[i]++;
{ System.out.print(array_variable[i] + " ");
inti++;
x;
x} = 5;
Which{of these is an incorrect string literal?
}int y = 6;
WhatSystem.out.print(x
} will be the error in+the " " following
+ y); Java code?
byte b }= 50;
b = bSystem.out.println(x
* 50; + " " + y);
}
}
ion contains double, int, float, long, then the whole expression will be promoted into which of these data types?
What will be the output of the following Java code?
class char_increment
{
public static void main(String args[])
{
char c1 = 'D';
char c2 = 84;
c2++;
c1++;
System.out.println(c1 + " " + c2);
}
}
What will be the output of the following Java code?
class conversion
{
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
What willbytebed the
= (byte) b; of the following Java code?
output
class A System.out.println(c + " " + d);
{ }
} final public int calculate(int a, int b) { return 1; }
}
class B extends A
{
public int calculate(int a, int b) { return 2; }
}
public class output
{
Whatpublic static
will be the void main(String
output args[]) Java program, if we run as “java
of the following
{
main_arguments 1 2 3”?
B object = new B();
class main_arguments
{ System.out.print("b is " + b.calculate(0, 1));
}public static void main(String [] args)
} {
String [][] argument = new String[2][2];
int x;
argument[0] = args;
Which xof=these is an incorrect array declaration?
argument[0].length;
for (int y = 0; y < x; y++)
System.out.print(" " + argument[0][y]);
Which } of these is an incorrect Statement?
}
Which of the following is a superclass of every class in Java?
What will be the output of the following Java code?
class Output
{
Whatpublic
will bestatic
the void main(String
output args[]) Java code snippet?
of the following
{
import double x = 3.14;
java.util.*;
class Arraylists Math.ceil(x);
int y = (int)
{ System.out.print(y);
}
public static void main(String args[])
} {
ArrayLists obj = new ArrayLists();
obj.add("A");
obj.add("B");
obj.add("C");
obj.add(1, "D");
System.out.println(obj);
}
}
What will be the output of the following Java code?
class newthread extends Thread
{
Thread t;
newthread()
{
Which one of
t1 = new the following is not an access modifier?
Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run()
{
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
Option A Option B Option C
-128 to 127 0 to 256 0 to 32767
ASCII ISO-LATIN-1 UNICODE
True & False 0&1 Any integer value
ed for characters in Java?
boolean b1 = 1; boolean b2 = ‘false’; boolean b3 = false;
Ascending order Descending order Random order
1 0
0 1 2
Sorted in the order of declaration of Enums
Sorted in alphabetical order of Enums
Sorted based on order() method
Runtime Error Compilation Error It runs successfully
Runtime Error EnumNotDefined Exception It runs successfully
getEnums() getEnumConstants() getEnumList()
Syntax Memory usage Garbage creation
int float double
0.00999999999999999
0.01 0.01
0.01
0.00999999999999999 0.01
SimpleDateFormat DateFormat SimpleFormat
SimpleDateFormat sdf = new SimpleDateFormat sdf = new SimpleDateFormat sdf = new
SimpleDateFormat("yyyy-mm- SimpleDateFormat("yyyy-mm-
SimpleDateFormat("yyyy-mm-dd");
sdf.parse(new Date()); dd"); dd");
sdf.format(new Date()); new Date().parse();
SimpleDateFormat sdf = new SimpleDateFormat sdf = new
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm- SimpleDateFormat("yyyy-mm-
SimpleDateFormat("yyyy-mm-dd");
sdf.parse(new Date()); dd"); dd");
sdf.format(new Date()); new Date().parse();
1 0
useDaylightTime() of Time class useDaylightTime() of Date classuseDaylightTime() of TimeZone class
java.sql.Date java.util.Date java.sql.DateTime
Date diffInMilli =
long diffInMilli = long diffInMilli =
java.time.Duration.between(d
java.time.Duration.between java.time.difference(dateTime1, ateTime1,
(dateTime1, dateTime2).toMillis(); dateTime2).toMillis();
dateTime2).toMillis();
38 39 40
02468 12345 0123456789
5656 565 Runtime error
“Hello World” “Hello\nWorld” “\”Hello World\””
* operator has converted b * 50
b cannot contain value 100, limited
into int, which can not be b cannot contain value 50
by its range
converted to byte without casting
long int double
EU UE VE
38 43 39 44 295 300
b is : 2 b is : 1 Compilation Error
1 1 1 0 1 0 3
int arr[] = new int[5] int [] arr = new int[5] int arr[] = new int[5]
It is necessary to use new operator to Array can be initialized using Array can be initialized when
comma separated expressions
initialize an array they are declared
surrounded by curly braces
ArrayList Abstract class Object class
3 0 4
[A, D, C] [A, B, C] [A, B, C, D]
truetrue falsefalse 1
Protected Void Public
Option D Answer Explanation
0 to 65535 D
None of the mentioned C
1 A
boolean b4 = ‘true’ C
Depends on the order() method D
B
3 A
Sorted in descending order of names of Enums A
EnumNotDefined Exception B
Compilation Error D
getEnum() B
Precision D
Bigdecimal D
0.009999999999999998
A
0.009999999999999998
DateConverter A
SimpleDateFormat sdf = new
SimpleDateFormat("yyyy-mm-dd"); B
new Date().format();
SimpleDateFormat sdf = new
SimpleDateFormat("yyyy-mm-dd"); A
new Date().format();
B
useDaylightTime() of DateTime class C
java.util.DateTime A
Time diffInMilli =
java.time.Duration.between(dateTime1, A
dateTime2).toMillis();
41 C
1 2 3 4 5 6 7 8 9 10 B
Compilation error D
"Hello All string literals must begin
world" D and end in the same line.
No error in this code While evaluating an expression containing int,
bytes or shorts, the whole expression is
converted to int then evaluated and the result
B is also of type int
float If any operand is double the result of an
C expression is double
UF A
B Type casting a larger variable into a smaller
variable results in modulo of larger variable by
range of smaller variable. b contains 300 which
is larger than byte’s range i:e -128 to 127
295.04 300 hence d contains 300 modulo 256 i:e 44.
The code does not compile because the
An exception is thrown at runtime method calculate() in class A is final and so
cannot be overridden by method of class b.
In argument[0] = args;, the reference variable
arg[0], which was referring to an array with
1 2 3 D
two elements, is reassigned to an array (args)
with three elements
Operator new must be succeeded by array
int arr[] = int [5] new D
type and array size.
Array can be initialized using both new and
comma separated expressions surrounded by
None of the mentioned A
curly braces example : int arr[5] = new int[5];
and int arr[] = { 0, 1, 2, 3, 4};
String Object class is superclass of every class in Java
C
3 ciel(double X) returns the smallest whole
number greater than or equal to variable x.
C
obj is an object of class ArrayLists hence it is an
dynamic array which can increase and
decrease its size. obj.add(“X”) adds to the array
element X and obj.add(1,”X”) adds element x
at index position 1 in the list, Hence
[A, D, B, C] D obj.add(1,”D”) stores D at index position 1 of
obj and shifts the previous value stored at that
position by 1
This program was previously done by using
Runnable interface, here we have used Thread
class. This shows both the method are
0 B equivalent, we can use any of them to create a
thread
Public, private, protected and default are the
Private access modifiers.
B
Questions Option A Option B
What will be the output of the following Java program?
class array_output {
public static void main(String args[]) iiiii 0 1 2 3 4
{
char array_variable [] = new char[10];
What for will
(intbe
i = the
0; i output of the
< 10; ++i) { following Java program?
class mainclass {
array_variable[i] = 'i';
publicSystem.out.print(array_variable[i]
static void main(String args[]) + "" ); 66 67
{ i++;
char
} a = 'A';
} a++;
}System.out.print((int)a);
What}will be the output of the following Java program?
class
} mainclass {
public static void main(String args[])
{
boolean var1 = true;
boolean var2 = false;
if (var1) 0 1
System.out.println(var1);
else
System.out.println(var2);
}
}
What will be the output of the following Java code?
class booloperators {
public static void main(String args[])
{ 0 1
boolean var1 = true;
boolean var2 = false;
System.out.println((var1 & var2));
}
}
What will be the output of the following Java code?
class asciicodes {
public static void main(String args[])
{ 162 65 97
char var1 = 'A';
char var2 = 'a';
System.out.println((int)var1 + " " + (int)var2);
}
}
result = func (n - 1);
return result;
}
}
class Output
{
public static void main(String args[])
{
recursion obj = new recursion() ; 1 120
System.out.print(obj.func(5));
}
}
What will be the output of the following Java code?
class Output
{ 257 256
public static void main(String args[])
{
Integer
What will i = new
be the Integer(257);
output of the following Java program?
byte x = i.byteValue();
System.out.print(x);
final class A
{ }
} int i; 22 33
}
class B extends A
{
int j; ServerRea
System.out.println(j + " " + i); Server
der
}
Which class provides system independent server side implementation?
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.display();
}
}
Option C Option D Answer Explanation
ijklm None of the
A
mentioned
65 64 A
1 0 C
1 0 D
67 95 66 98 B
None of the
0 A
mentioned
i.byteValue() method returns the value of wrapper i as
a byte value. i is 257, range of byte is 256 therefore i
value exceeds byte range by 1 hence 1 is returned and
1 0 C stored in x.
class A has been declared final hence it cannot be
inherited by any other class. Hence class B does not
have member i, giving compilation error
Runtime Compilation
D
Error Error
ServerSocket is a java.net class which provides system
Socket ServerSocket D independent implementation of server side socket
connection.