You are on page 1of 14

Template for generation of Questions

Date:
Module: J2SE
Session No. 1
Q. No. 1

What is the output of this program?


class bitwise_operator {
publicstaticvoid main(String args[])
{
int var1 =42;
int var2 = ~var1;
System.out.print(var1 +" "+ var2);
}
}

A. 42 42

B. 43 43

C. 42 -43

D. 42 43

Difficulty Level: Easy

Q. No. 2

What is the output of this program?


class Output {
publicstaticvoid main(String args[])
{
int a =1;
int b =2;
int c =3;
a |=4;
b >>=1;
c <<=1;
a ^= c;
System.out.println(a +" "+ b +" "+ c);
}
}

A. 3 1 6

B. 2 2 3
C. 2 3 4

D. 3 3 6

Difficulty Level: Intermediate

Session No. 2
Q. No. 3

Which function is used to perform some action when the object is to be destroyed?

A. finalize()

B. delete()

C. main()

D. None of the mentioned

Difficulty Level: Easy

Q. No. 4

Which of these statement is incorrect?

A. Every class must contain a main() method.

B. Applets do not require a main() method at all.

C. There can be only one main() method in a program.

D. main() method must be made public.

Difficulty Level: Intermediate

Session No. 3

Q. No. 5

Which operator is used by Java run time implementations to free the memory of an
object when it is no longer needed?

A. Delete

B. free

C. new

D. None of the mentioned

Difficulty Level: Easy


Q. No. 6

What happens when we declare main() as private?


A. It will show compile time error.
B. It will show Runtime error main method not public.
C. It will show Runtime error java.lang.NoSuchMethodError.
D. None of the Above.

Difficulty Level: Intermediate

Session No. 4

Q. No. 7

What is the output of below java code?


public class Test {
public static void main(String[] args) {
try{ int num[] = new int[2]; num[3]= 10;
System.out.println("In Try block");
}catch (ArithmeticException e) {
System.out.println("ArithmeticException");
}catch (Exception e) { System.out.println("Exception");
}finally { System.out.println("In finally block"); } } }
A. In Try block
In finally block
B. In Try block
ArithmeticException
Exception
In finally block
C. Exception
In finally block
D. ArithmeticException
Exception
In finally block
Difficulty Level: Intermediate

Q. No. 8

Which error will be thrown when JVM cant allocate memory to object?
A. java.lang.OutOfMemoryError
B. java.lang.LinkageError
C. java.lang.StackOverflowError
D. java.lang.UnknownError

Session No. 5

Q. No. 9
Which of the following statements declare class Sample to belong to the
payroll.admindept package?

A. package payroll; package admindept

B. import payroll.*

C. package payroll.admindept.Sample;

D. package payroll.admindept;

Difficulty Level: Intermediate

Q. No. 10

Which of these is used to access member of class before object of that class is created?
A. public

B. private

C. static

D. protected

Difficulty Level: Intermediate

Session No. 6

Q. No. 11

What will be output after running below main method?


public static void main(String[] args) {
TreeSet treeSet = new TreeSet();
String three = null; treeSet.add("one");
treeSet.add("two"); treeSet.add(three);
Iterator itr = treeSet.iterator();
while(itr.hasNext()){ System.out.println(itr.next()); } }
A. null
one
two
B. one
two
C. compilation fail
D. null pointer exception

Difficulty Level: Intermediate

Q. No. 12

Why we use Externalizable interface?


A. When we do not want to serialize some data.
B. When we want to customize serialization process.
C. When we require deserialization.
D. None of above.

Difficulty Level: Difficult

Session No. 7

Q. No. 13

What happens if we call start() again on the same thread?

A. Compilation fail

B. IllegalThreadStateException occurs

C. IllegalAccessException occurs

D. Thread processing not impacted and it will run normally.

Difficulty Level: Easy

Q. No. 14

Which method is not defined in Thread class?


A. yield()
B. join()
C. start()
D. wait()

Difficulty Level: Easy

Session No. 8

Q. No. 15

What will be output after running below main method?


public static void main(String[] args) {
List<String> numbers = new ArrayList<>();
numbers.add("One"); numbers.add("Two");
numbers.forEach(number -> System.out.println(numbers)); }
A. [One, Two]
[One, Two]
B. Compilation Fail
C. Run time Exception
D. Code compiles and runs properly without any output.

Difficulty Level: Intermediate

Q. No. 16

Which of these is the interface of legacy?

A. Map

B. Enumeration

C. HashMap

D. Hashtable

Difficulty Level: Intermediate


Session No. 9

Q. No. 17

Following are the interfaces defined by java.lang ?

A. Serializable,Cloneable,Runnable
B. Cloneable,Comparable,Runnable
C. Serializable,Bubble,Runnable
D. Serializable, Serializer,Cloneable
Q. No. 18
Which statement is true about Compact Profiles?
A. Compact Profiles are used for minimizing space requirements of Java runtime.
B. Compact Profiles does not minimize space requirements of the application.
C. In java 8 we have to always configure full JRE APIs which includes all the Java SE
classes.
D. All of Above

Difficulty Level: easy

Session No. 10

Q. No. 19

Choose the correct statement from the following:


A. @RequestBody
B. @RequestParam
C. @RequestMapping
D. @ResponseBody Difficulty Level: Intermediate

Q. No. 20

Which of the following is event listener for session creation?


A. The notifyAll() method must be called from a synchronized context
B. To call wait(), an object must own the lock on the thread
C. The notify() method is defined in class java.lang.Thread
D. The notify() method causes a thread to immediately release its lock
Difficulty Level: Intermediate

Session No. 11

Q. No. 21

What will be the output of following code:


import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20,20);
}
}
A. A Simple Applet
B. A Simple Applet 20 20
C. Compilation Error
D. Runtime Error

Difficulty Level: Intermediate

Q. No. 22

Which of these standard collection classes implements a linked list data structure?
A. AbstractList
B. LinkedList
C. HashSet
D. AbstractSet

Session No. 12

Q. No. 23

Which of the following is valid functional interface as per Java SE 8?


1. public interface A {
double calc(int a,int b);
}
2. public interface B extends A
{
default double calc(int a,int b)
{
return a+b;
}
}
3. public interface C extends A
{
void show();
}
4. public interface D
{
}

Q. No. 24

The client in socket programming must know which of the following?

A. IPaddress of Server
B. Port number
C. Both 1 & 2
D. None of the above

Session No. 13

Q. No. 25

Which of these is a class ,uses String as a key to store the value in object?
A. Array
B. ArrayList
C. Dictionary
D. Properties
Q. No. 26

Which of the following constructs an anonymous

inner class instance?

1. Runnable r = new Runnable() { };

2. Runnable r = new Runnable(public void run()

{ });

3. Runnable r = new Runnable { public void

run(){}};

4. System.out.println(new Runnable() {public

void run() { }});

Q. No. 27

Which function of pre defined class Thread is used to check whether current
thread is still running?

A. isAlive()
B. Join()
C. isRunning()
D. Alive()

Q. No. 28

Which is true about a method-local inner class?

A. It must be marked final.


B. It can be marked abstract.
C. It can be marked public.
D. It can be marked static.

Q. No. 29

The_______ and_____ classes are abstract classes that support reading and writing
of byte streams.

A. reader, writer
B. inputstream, outputstream
C. objectinputstream, objectoutputstream
D. None

Q. No. 30
The ActionListener interface is used for handling action
events,Forexample,it's used by
A. JButton
B. JCheckbox
C. JMenuItem
D. All of these

Q. No. 31
Which is default layout manager for JFrame?
A. Flow Layout
B. Grid Layout
C. Border Layout
D. Card Layout

Q. No. 32

Which of these values is returned by read() method is end of file (EOF) is encountered?
A. 0

B. 1

C. -1

D. null

Difficulty Level: difficult

Session No. 17

Q. No. 33

What is the output of this program?


importjava.io.*;
class files {
publicstaticvoid main(String args[]){
File obj =newFile("/java/system");
System.out.print(obj.getName());
}
}

A. Java

B. System

C. java/system

D. /java/system

Difficulty Level: difficult


Q. No. 34
What will this code print?
int arr[] = new int [5];
System.out.print(arr);
a) 0
b) value stored in arr[0].
c) 00000
d) Garbage value

Q. No. 35

Which of these is an incorrect Statement?


a) It is necessary to use new operator to initialize an array.
b) Array can be initialized using comma separated expressions surrounded by curly braces.
c) Array can be initialized when they are declared.
d) None of the mentioned

Q. No. 36

What is the process of defining a method in subclass having same name & type signature as a
method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned

Q. No. 37

Which of these is correct way of calling a constructor having no parameters, of superclass A by


subclass B?
a) super(void);
b) superclass.();
c) super.A();
d) super();

Q. No. 38

Which of the following statements are incorrect?


a) public members of class can be accessed by any code in the program.
b) private members of class can only be accessed by other members of the class.
c) private members of class can be inherited by a sub class, and become protected members in
sub class.
d) protected members of a class can be inherited by a sub class, and become private members
of the sub class.

Q. No. 39

Which of these method of class StringBuffer is used to concatenate the string representation to
the end of invoking string?
a) concat()
b) append()
c) join()
d) concatenate()

Q. No. 40

What is the string contained in s after following lines of code?


StringBuffer s new StringBuffer(Hello);
s.deleteCharAt(0);
a) Hell
b) ello
c) Hel
d) llo

Q. No. 41

Which of the following statement is correct?


a) reverse() method reverses all characters.
b) reverseall() method reverses all characters.
c) replace() method replaces first occurrence of a character in invoking string with another
character.
d) replace() method replaces last occurrence of a character in invoking string with another
character.

Q. No. 42

Which of these is a process of writing the state of an object to a byte stream?


a) Serialization
b) Externalization
c) File Filtering
d) All of the mentioned

Q. No. 43

Which of these is an interface for control over serialization and deserialization?


a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput

Q. No. 44
Which of the following is a method having same name as that of its class?
a) finalize
b) delete
c) class
d) constructor

Q. No. 45

Which function is used to perform some action when the object is to be destroyed?
a) finalize()
b) delete()
c) main()
d) None of the mentioned

Q. No. 46

Which of these cannot be declared static?


a) class
b) object
c) variable
d) method

Q. No. 47

Which of the following statements are incorrect?


a) static methods can call other static methods only.
b) static methods must only access static data.
c) static methods can not refer to this or super in any way.
d) when object of class is declared, each object contains its own copy of static variables.

Q. No. 48

Which of the following statements are incorrect?


a) Variables declared as final occupy memory.
b) final variable must be initialized at the time of declaration.
c) Arrays in java are implemented as an object.
d) All arrays contain an attribute-length which contains the number of elements stored in the
array.

Q. No. 49

Which of these process occur automatically by java run time system?


a) Serialization
b) Memory allocation
c) Deserialization
d) All of the mentioned

Q. No. 50

Which of these is a method of ObjectInput interface used to deserialize an object from a stream?
a) int read()
b) void close()
c) Object readObject()
d) Object WriteObject()

You might also like