Font size
WorksheetsJava Concepts Challenge
Total questions: 87
Worksheet time: 1hrs 24mins
What is the primary purpose of the StringBuilder class?
To efficiently create and manipulate strings.
To store immutable strings.
To convert strings to integers.
To manage string formatting only.
What is the difference between an interface and an abstract class?
An interface can have implemented methods and supports single inheritance.
An abstract class cannot have any methods and supports multiple inheritance.
An interface can only be used in a single class and cannot extend other interfaces.
An interface cannot have any implementation and supports multiple inheritance, while an abstract class can have some implemented methods and supports single inheritance.
Which of the following is a valid way to declare a package in Java?
import com.example;
package:com.example;
com.example.package;
package com.example;
What exception is thrown when an array is accessed with an illegal index?
IllegalArgumentException
NullPointerException
ArrayIndexOutOfBoundsException
IndexOutOfRangeException
Which collection class allows duplicate elements?
LinkedList
TreeMap
HashSet
ArrayList
What is the purpose of the Wrapper classes in Java?
To provide additional methods for mathematical operations.
To store multiple values in a single object.
The purpose of Wrapper classes in Java is to convert primitive data types into objects.
To enhance the performance of primitive data types.
Which of the following is true about Java I/O streams?
Java I/O streams only handle binary data.
Java I/O streams cannot be used for text files.
Java I/O streams are limited to network communication.
Java I/O streams can be categorized into byte streams and character streams.
Predict the output:
[PJP, Java]
[Python, PJP, Java]
[PJP, Java]
Compile time error
Run time error
None of the above
Predict the output:
Prints nothing
Compile Time Error: variable x is already defined
9
8
Predict the output:
Prints nothing
0
null
OutOfBoundsException
Predict the output:
Child display..
Child display..Parent display..
Parent display..Child display..
Compile Time Error
Predict the output:
true false
true true
false true
false false
Predict the output:
a = 0
Divide by zero error
a = 0
inside the finally block
a = 0
Divide by zero error
inside the finally block
Divide by zero error
inside the finally block
What is the output of the below Java code snippet?
char ch = 'A';//ASCII 65
int a = ch + 1;
ch = (char)a;
System.out.println(ch);
A) 66
B) A
C) B
D) 65
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
class increment {
public static void main(String args[]) {
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4); } }
1 1
0 1.5
1.5 1
1 1.5
class increment {
public static void main(String args[]) {
int g = 3;
System.out.print(++g * 8); } }
24
32
25
34
class Output {
public static void main(String args[]) {
int a = 1; int b = 2; int c; int d;
c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + " " + b + " " + c); } }
4 4 3
3 3 4
3 4 4
4 3 3
class bitwise_operator {
public static void main(String args[]) {
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2); } }
42 42
42 -43
43 42
43 -42
class bitwise_operator {
public static void main(String args[]) {
int a = 3;
int b = 6;
int c = a | b;
int d = a & b;
System.out.println(c + " " + d); } }
7 2
7 5
5 7
7 7
class rightshift_operator {
public static void main(String args[]) {
int x; x = 10;
x = x >> 1;
System.out.println(x); } }
2
7
5
10
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
Which of these interface declares core method that all collections will have?
Collection
EventListner
Comparator
Set
List
What implementation of Iterator can traverse a collection in both directions?
Iterator
ListIterator
SetIterator
MapIterator
Which interface does java.util.Hashtable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
The default capacity of a Vector is:
10
12
8
0
Which of these is synchronized?
TreeMap
HashMap
Hashtable
All of the above
How can you sort given HashMap on basis of values
Implement Comparator interface and override its compare method
It is not possible
Implement Comparator interface and override its compareTo method
Implement Comparator interface and override its comparable method
-Entries are not organized as key/value pairs.
-Duplicate entries are rejected.
Which interface of the java.util package offers the specified behavior?
List
Map
Set
None of the above
[Computer, Network, Networks, Programming, Security]
[Computer, Programming, Network, Networks, Programming, Security]
[Computer, Programming, Computer, Networks, Network, Security]
[Computer, Networks, Network, Programming, Security]
Which of the following is/are correct statements?
HashSet class implements the Set interface
HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.
HashSet permits to have a single null value.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap and HashSet are threadsafe
Which of the following statement(s) is/are TRUE?
Both HashMap and HashSet are not synchronized.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap permits single null key and any number of null values.
Both HashMap and HashSet are synchronized.
{"Computer", "Programming","Networks","null"}
{"Computer", "Programming","Networks",null,"null"}
Line 11 : Genetates NullPointer Exception
Line12: Generates NullPointerException
List listNames = new ArrayList();
listNames.add("Tom");
listNames.add("Mary");
listNames.add("Peter");
String name2 = (String) listNames.get(1);
System.out.println(name2);
What is the output of the above code
Tom
Mary
Peter
raises Exception
int x = 5;
int y = 6
int z = 50;
System.out.println(x + y + z);
What will be the output?
61
5650
66
x + y + z
Which of the following is the right way of defining char variable?
char myGrade = 'B';
char myGrade = "B";
char myGrade 'B';
char myGrade = "B"
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
What is the output of the below Java program?
int hours = 10;
String message=null;
switch(hours)
{
case 10: message ="TEN";
case 11: message ="TEN AGAIN";
default: message ="TEN AS USUAL";
}
System.out.println(message);
TEN
TEN AGAIN
TEN AS USUAL
TEN
TEN AS USUAL
Which of the following use the correct syntax for a traditional for loop?
for(x=0; x<10; x++) {System.out.println(x);}
for(int x=0; x<10; x++) {System.out.println(x);}
for(x=0, x<10, x++){System.out.println(x);}
for(int x=0: x<10: x++){System.out.println(x);}
Which of the following use the correct syntax for an enhanced for loop?
for(int x=0; x<10; x++) {System.out.println(x);}
for(int x : numbers) {System.out.println(x);}
for(x=0, x<10, x++){System.out.println(x);}
for(int x=0: int numbers=10){System.out.println(x);}
Base on the code block below what will print to the console?
String Days[]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
for(int i=6;i>=0;i--) {
System.out.println(Days[i] );
}
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
Saturday
Friday
Thursday
Wednesday
Tuesday
Monday
Sunday
What would be outputted if you inputted "B"?
1
2
3
What would print if the following code was inserted on line 9.
System.out.print(num1);
5
10
15
nothing, this will trigger a error.
What will be outputted from this code?
5
6
nothing, this will trigger an error.
10
What is the output of this program?
0
2
6
8
10
0
2
4
2
4
Nothing, this program will not compile.
What is the output of the following code:
System.out.prinltn(Integer.SIZE);
2
16
4
32
What is type coercion
is an implicit type casting
It is explicit type casting
It is related to boxing
It is not related to type casting
How many wrapper classes are available in Java
8
7
6
9
How to find out whether the given character is alphabet or not in java
By using Character.isAlpha()
By using Character.isLetter()
By using Character.isAlphabet()
By using isletter()
How to convert character into string in java
using String.valueOf()
using "" with conatenation
using toString() method
using charAt() function
Which of these class is used to read characters and strings in Java from console?
StringReader
BufferedReader
InputStreamReader
BufferedStreamReader
Which of these stream contains the classes which can work on character stream?
InputStream
OutputStream
Character Stream
All of the mentioned
Which of these is a type of stream in Java?
Integer stream
Byte Stream
Short Stream
Long Stream
Which of these classes are used by character streams for input and output operations?
InputStream
InputOutputStream
ReadStream
Writer
To find the corect declaration of long data type in java?
long num=09876654;
long num=-1223733L;
long num=1223333l;
int num=099987;
2. Class at the top of exception class hierarchy?
ArithmeticException
Throwable
Object
Exception
3. In which of the following package, Exception class exist?
java.util
java.io
java.lang
java.file
Why is data abstraction important in Java?
Data abstraction helps in hiding the implementation details and showing only the necessary features of an object.
Data abstraction is not important in Java
Data abstraction makes the code more complex
Data abstraction slows down the program
How can we achieve multiple inheritance in Java using interfaces?
Implementing multiple interfaces in a single class
Implementing multiple classes in a single interface
Using abstract classes instead of interfaces
Extending multiple classes in a single class
Which one of the following are essential features of an object-oriented programming language?
Abstraction and encapsulation
Strictly-typedness
Polymorphism in the presence of inheritance
Type-safe property coupled with sub-type rule
What is serialization in Java?
It is a process of converting Object data into sequence of bytes
It is the process of converting Sequence of bytes into Objects
Used to transform data in serial form
No serialization in java
what is the purpose of 'transient' keyword in serialization
used to provide security to the data
It is not used with serialization
These transient members prints primitive type default values at the time of de-serialization
These transient members prints garbage values at the time of de-serialization
The following class(es) is/are used in serialization and deserialization process
ObjectOutputStream
ObjectInputStream()
DataOuptutStream
BufferedReader
Serialization throws an error
when two classes combined with HAS-A relationship
when two classes combined with IS-A relationship
Both HAS-A and IS-A gives error
either HAS-A or IS-A gives error
What is/are the possible exception(s) in De-serialization
IOException
ClassNotFoundException
ClassCastException
SerializationNotSupportedException
What is the name of marker interface used in Serialization
Serializable
Serial
Cloneable
Serialization
What is the Syntax of DeSerialization
Class_name Obj=(Class_name)objinputStream_obj.readObject();
Class_name Obj=(Class_name)objinputStream_obj.read();
Class_name Obj=(Class_name)objinputStream_obj.readObject(file);
Objinputstream =(Class_name)obj.readObject();
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)
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
Select correct code to create an array of "double" datatype of length 5.
double arr = double[5];
double{} arr = new double{5};
double[5] arr = new double[];
double[] arr = new double[5];
How many objects will be created?
String a = new String("Examveda");
String b = new String("Examveda");
String c = "Examveda";
String d = "Examveda";
4
3
2
none of these
What is the most appropriate way to check if two Strings are identical?
string1 == string2
string1.equals(string2)
string1.same(string2)
string1.equalsIgnorecase(string2)
