WBUT or West Bengal university of technology is conducted MCA along with various technical courses. According to their MCA syllabus, students learn JAVA in the 5th semester. We are trying to give some guidance to the WBUT students by previous year solved papers. Here we discuss the Java paper of 2010.
Time Allotted: 3 Hours Full Marks: 70
The figures in the margin indicate full marks. Candidates are required to give their answers in their own words as far as practicable.
1. Choose the correct alternatives for the following : 10 × 1 = 10
i)
int j;
for (int i=0;i<14;i++)
{
if (i<10)
{
j = 2 + i;
}
System.out.println ("j:" + j + "i:" + i);
}
What is WRONG with the above code ?
a) Integer "j" is not initialized b) Nothing
c) You cannot declare integer i inside the for-loop declaration
d) The syntax of the "if " statement is incorrect
e) You cannot print integer values without converting them to strings.
ii) Which one of the following is a valid declaration of an applet ?
a) public class MyApplet extends java.applet.Applet {
b) public Applet MyApplet {
c) public class MyApplet extends applet implements Runnable {
d) abstract class MyApplet extends java.applet.Applet {
e) class MyApplet implements Applet {
iii) int values [] = { 1, 2, 3, 4, 5, 6, 7, 8 };
for (int i=0;i<X; ++i)
System.out.println (values [i]);
Referring to the above, what value for X will print all members of array "values" ?
a) 1
b) 7
c) 8
d) 9
e) None, since there is a syntax error in the array declaration.
iv)
public int m1(int x)
{
int count = 1;
try
{
count +=x;
count +=m2(count);
count ++;
}
catch (Exception e)
{
count –= x;
}
return count;
}
Referring to the above, when m1(2) is invoked, m2 () throws an Arithmetic Exception and m1() returns which one of the following ?
a) 1
b) 2
c) 3
d) 4
e) The system will exit.
v) Which one of the following statements is FALSE ?
a) Java supports multi-threaded programming.
b) Threads in a single program can have different priorities.
c) Multiple threads can manipulate files and get user input at the same time.
d) Two threads can never act on the same object at the same time.
e) Threads are created and started with different methods.
vi) 1 public static void main (String [] s) {
2 String n1, n2, n3;
3 n1 = "n1";
4 n2 = "n2";
5 n3 = "n3";
6 {
7 String n4 = "inner";
8 n2 = n1;
9 }
10 n3 = null;
11 }
How many instances of the String will be eligible for garbage collection after line 10 in the above code snippet is executed ?
a) 0
b) 1
c) 2
d) 3
e) The code will not compile.
vii) Which code declares class A to belong to the mypackage. financial package ?
a) package mypackage; package financial;
b) import mypackage.*;
c) package mypackage.finanical.A;
d) import mypackage.financial.*;
e) package mypackage. financial;
viii) JVM is
a) A java package b) A java compiler
c) A system software d) A java interface
e) None of these.
ix)Size of Unicode is
a) 2 bits b) 8 bits
c) 16 bits d) 15 bits
e) none of these.
x) Delegation model is associated with
a) Exception Handling b) Garbage Collection
c) AWT d) Event Handling
e) None of these.
Answer any three of the following. 3 × 5 = 15
2. What is the difference between the PATH and CLASSPATH ? What is Java Virtual Machine ( JVM ) ? 2 + 3
Ans.
3. How can a programmer define a class that cannot be inherited ? Give an example. 5
Ans.
4. What is the checked and unchecked exception ? Describe with proper examples. 5
Ans.
5. What is the difference between the final, finally, and finalize ? 5
Ans.
6. What is applet ? Describe the life cycle of the applet. What are demerits of the applet ?
1 + 3 + 1
Ans.
Answer any three of the following. 3 × 15 = 45
7. a) What is thread ? How to create a thread in Java ?
b) What is the need of synchronized block ? Illustrate with an example.
c) How to override the equal functions ? ( 2 + 2 ) + 7 + 4
8. a) “Programmer can call a constructor from another constructor.” Explain with an example.
b) Write a GUI program in Java that will have two buttons viz., RED and GREEN. If user clicks on RED button the background of the GUI will be painted in red or if user clicks on GREEN button the background of the GUI will be painted green. 5 + 10
9. What is polymorphism ? What are the types of polymorphism present in Java ? Compare and contrast overloading and overriding methods with proper examples.
2 + 5 + 8
Ans.
10. a) What is AWT ? Differentiate between component class and container class.
Ans.
b) What is an event ? What is event handling ? What is the role of event listeners in this regard ?
Ans.
c) Show by writing a complete code along with the output how multiple inheritance is implemented in Java. Explain static import. 2 + 2 + 1 + 1 + 2 + 6 + 1
Ans.
11. Write short notes on any three of the following : 3 × 5
a) Interface
b) Package
c) Container class
d) Exception handler.