1) In order for a source code file, containing the public class Test, to successfully compile,
which of the following must be true?
a. It must have a package statement
b. It must be named [Link]
c. It must import [Link]
d. It must declare a public class named Test
What is the range of the char type?
1. 0 to 216
2. 0 to 215
3. 0 to 216 - 1
4. 0 to 215 - 1
2. How many objects and reference variables are created by the following lines of
code?
Employee emp1, emp2;
emp1 = new Employee() ;
Employee emp3 = new Employee() ;
A: Two objects and three reference variables.
B: Three objects and two reference variables.
C:Four objects and two reference variables.
D: Two objects and two reference variables.
2) Which of the following statements correctly describes the relation between an object
and the instance variable it stores?
a. Each new object has its own distinctive set of instance variables
b. Each object has a copy of the instance variables of its class
c. The instance variable of each object are separate from the variables of other
objects
d. All of the above
3) What is garbage collection in the context of Java?
A: The operating system periodically deletes all of the java files available on the
system.
B: Any package imported in a program and not used is automatically deleted.
C: When all references to an object are gone, the memory used by the object is
automatically reclaimed.
D: The JVM checks the output of any Java program and deletes anything that
doesn't make sense.
1. Given the following class definition, which of the following methods could be legally placed after the
comment?
public class Test{
public static void myMethod(int i, String s){}
//Here
}
A. public void myMethod(String s, int i){}
B. public int myMethod(int i, String s){}
C. public void myMethod(int i, String mystring){}
D. none
2. Which of the following statement is true about defining method?
A. Transient is a valid modifier.
B. Methods with no access modifier can be called from main() method.
C. Abstract methods have no implementation in the class where they are defined.
D. none
4. Which statement is false regarding Abstract class?
a) We can call an abstract method from a Non abstract method in a Java abstract class.
b) Abstract classes will provide the basic functionality of your application.
c) A class may implement several interfaces also in case of abstract class a class may extend many
abstract classes
d) Child class, which inherited this class, will provide the functionality of the abstract methods in
abstract class.
40. How can we initialize an applet?
a) No we can not initialize it b) Using constructor
c) Use the init method d) Both 2 and 3
4) Which of the following is not a wrapper class?
a. String
b. Integer
c. Boolean
d. Character
44. public class MyOuter {
public static class MyInner {
public static void hello() { }
which statement, if placed in a class other than myOuter or myInner, instantiates an instance of the
nested class?
a) [Link] m = new [Link](); b) [Link] mi = new MyInner();
c) MyOuter m = new MyOuter(); d) MyInner mi = new [Link]();
Can we create one or more package declaration per source file?
a) No you can have only one package declaration per file
b) Yes specify multiple package declaration at starting of the program
c) Yes you can use scope braces to show which package definition holds good for respected blocks
d) None of the above
3. Which of the following statements is not true?
A. Inner classes cannot be defined private
B. An anonymous class can be subclass of another explicit class
C. An anonymous class can implement single interface
D. An anonymous class cannot be both explicit subclass and implement an interface
4. What is the result of the following code when you compile and run?
public class ThrowDemo {
static void demoMethod() {
try {
throw new NullPointerException("demo");
} catch(NullPointerException e) {
[Link]("Caught inside demoMethod.");
throw e; // re-throw the exception
}
}
public static void main(String args[]) {
try {
demoMethod();
} catch(NullPointerException e) {
[Link]("Recaught: " + e);
}
}
}
A. Compilation error
B. Runtime error
C. Compile successfully, nothing is printed.
D. Caught inside demoMethod. followed by Recaught: [Link]: demo
. Exceptions which must be caught using try.. catch() block or we should throw the exception using
throws clause is called as_________.
a) Checked Exceptions b) Unchecked Exceptions
c) Both 1 and 2 d) None of the above
5. What is the result of compiling the following code?
class MyExp {
void MyMethod() throws IOException, EOFException {
//............
}
}
class MyExp1 extends MyExp {
void MyMethod() {
//..........
}
}
public class MyExp2 extends MyExp1 {
void MyMethod() throws IOException {
//.........
}
}
A. Compile time error B. No compile time error
C. Run-Time error D. MyMethod() can throw an exception in
MyExp2 class
6. What will be the output of the following program?
public class TestFC {
public static void main(String args[]) {
[Link]([Link](145.1));
[Link]([Link](-145.4));
}
}
A. 145.0 followed by -145.0 B. 150.0 followed by -150.0
C. 145.1 followed by -145.4 D. null
5) Which of the following methods cause the string object referenced by s to be changed?
a. [Link]()
b. [Link]()
c. [Link]()
d. none of the above
16. String s1=”hello”; String s2=”hello”; which one will return true?
a) s1==s2 b) sa)equals(s2)
c) Both 1 and 2 d) None of the above
1. Elements are indexed and duplicates are allowed in _________________.
a) [Link]
b) [Link]
c) [Link]
d) *java .[Link]
36. The most suitable choice for maintaining an ordered sequence of objects,when objects are
frequently
inserted and removed from the middle of the sequence is_________.
a) HashMap b) HashSet
c) TreeMap d) LinkedList
19. What should be done to execute a thread for an object derived from the Thread class?
a) The run() method should be directly invoked on the Object.
b) The start() method should be directly invoked on the Object.
c) The init() method should be directly invoked on the Object.
d) The creation of the object using the new operator would create a new thread and invoke its run()
method.
Assume the following method is properly synchronized and called from a thread A on an object B:
wait(2000); After calling this method, when will the thread A become a candidate to get another turn
at the CPU?
a) After thread A is notified, or after two seconds b) After the lock on B is released, or after two
seconds.
c) Two seconds after thread A is notified. d) Two seconds after lock B is released.
49. Which statement is correct regarding Synchronization?
a) Methods as well as variables can be Synchronized.
b) All methods in a class must be Synchronized.
c) If two methods are Synchronized in a class, only one thread can be accessing one of the two
methods.
d) If a thread goes to sleep, it releases its locks.
7. Which of the following statements is not true?
A. Thread start() method makes it eligible to run. B. Thread dies after the run() method returns
C. A dead Thread can be started again. D. A stop() method kills the currently running Thread
8. Which of the following are false?
A TextField object may generate an ActionEvent
A TextArea object may generate an ActionEvent
A Button object may generate an ActionEvent
A MenuItem object may generate an ActionEvent
9. Which of the following are correct, if you try to compile the following code?
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
[Link](0);
}
public static void main(String args[]) {
CloseWindow CW = new CloseWindow();
}
}
A. Compile time error
B. Runtime error
C. Code compiles but Frames does not listen to WindowEvents
D. Compile and runs successfully.
42. int button Count=0;
Panel centerPanel = new Panel();
void addButton() {
++buttonCount;
centerPanel .add(new Button(“button” +
buttonCount));
[Link]();
}
In above code what is the purpose of using validate method?
a) It activates its layout manager to take the new component into account.
b) It deactivates its layout manager to take the new component into account.
c) To add more buttons in to panel
d) None of the above
39. What will we do to put more than one applet in a web page?
a) No we can not do this
b) Include a separate APPLET tag for each applet we wish to put on our web page.
c) In single APPLET tag we will add all applet.
d) None of the above
18. If you are not in a paint() method ,how do you create Graphics class reference
a) new Graphics()
b) Graphics class has got all static methods, hence no need to create the reference of Graphics class
c) GetPaint()
d) getGraphics() of component class
The means by which the browser and the applet communicates is
AppletSkeleton interface
AppletApplication interface
AppletStub interface
AppletWindow interface
What are the interfaces to deal with Applet applications?
AppletContext, AppletConfig
AppletContext, AppletStub, AudioClip
AppletConfig, AppletStub, AudioClip
AppletConfit,AppletStub, VideoClip
How to get a particular class field by name?
a. getFields(String name);
b. GetFields(string name);
c. getField(String name);
d. None of the Above
If we were trying to get below method while runtime:
public int doSomething(String stuff, int times, int max){
//code
}
a. getMethod(“doSomething”, [Link], [Link], [Link]);
b. getMethods([Link], [Link], “doSomething”, [Link]);
c. GetMethod([Link], [Link], “doSomething”, [Link]);
d. All ob Above
A socket provides ______________.
a. a physical connection/link between sender
and receiver
c. a virtual circuit through which data is
transferred
b. an interface via which communicating
applications can send/receive data
d. a mechanism for connecting two end
systems
The two parameters that must be specified in order to instantiate a Java “Socket” are
______________.
a. a destination host id and a destination port
number
c. source and destination IP addresses
b. source and a destination port numbers d. the destination IP address and the
destination socket id number
How to constructs a datagram packet for sending packets of length len to the specified port
number on the specified host?
a. DatagramPacket((byte[] buf, int len, InetAddress addr, int port)
b. DatagramPacker(byte[] buf, int off, int len, InetAddress addr, int port)
c. DatagramPacket(byte[] buf, int off, int len, SocketAddress addr)
d. Both b & c
Datagram packet has a fixed size of data?
a. 65530
b. 65535
c. 65555
d. 65536
A Remote interface must throw following Exceptions:
a. must throw [Link]
b. must throw [Link]
c. must throw [Link]
d. must throw [Link]
RMI will automatically create a _____ on the client side and ________ on the server side.
a. Skeleton and stub
b. Stub and interface
c. Stub and skeleton
d. Remote object and stub
Call ______ to get reference of Remote object.
a. [Link]()
b. Lookup()
c. [Link]()
d. None of Above
2. The server process registers a reference of its remote object with the local
_______ registry by binding it with a well known name.
a) JVM
b) JRMP
c) RMI
d) Stub
Question: Which of the following is TRUE?
A: In java, an instance field declared public generates a compilation error.
B: int is the name of a class available in the package [Link]
C: Instance variable names may only contain letters and digits.
e) D: A class has always a constructor (possibly automatically supplied by the java
f) compiler).
g)
h) Q. No. 2
i) Question: What is garbage collection in the context of Java?
j) A: The operating system periodically deletes all of the java files available on the
k) system.
l) B: Any package imported in a program and not used is automatically deleted.
m) C: When all references to an object are gone, the memory used by the object is
n) automatically reclaimed.
o) D: The JVM checks the output of any Java program and deletes anything that
p) doesn't make sense.
q)
r) Q. No. 3
s) Question: How many objects and reference variables are created by the
following lines of code?
t) Employee emp1, emp2;
u) emp1 = new Employee() ;
v) Employee emp3 = new Employee() ;
A: Two objects and three reference variables.
B: Three objects and two reference variables.
C:Four objects and two reference variables.
D: Two objects and two reference variables.
w)
x) Q. No. 4
y) Question: What is byte code in the context of Java?
z) A: The type of code generated by a Java compiler
aa)B: The type of code generated by a Java Virtual Machine
bb)C: It is another name for a Java source file
cc) D: It is the code written within the instance methods of a class.
dd)
ee)
ff)
gg)