2011 Past Paper
2011 Past Paper
2011 Past Paper
IT2204 - Programming I
30th July 2011
(TWO HOURS)
Important Instructions :
The duration of the paper is 2 (two) hours.
The medium of instruction and questions is English.
The paper has 45 questions and 12 pages.
All questions are of the MCQ (Multiple Choice Questions) type.
All questions should be answered.
Each question will have 5 (five) choices with one or more correct answers.
All questions will carry equal marks.
There will be a penalty for incorrect responses to discourage guessing.
The mark given for a question will vary from 0 (All the incorrect choices are
marked & no correct choices are marked) to +1 (All the correct choices are
marked & no incorrect choices are marked).
Answers should be marked on the special answer sheet provided.
Note that questions appear on both sides of the paper.
If a page is not printed, please inform the supervisor immediately.
Mark the correct choices on the question paper first and then transfer them
to the given answer sheet which will be machine marked. Please
completely read and follow the instructions given on the other side
of the answer sheet before you shade your correct choices.
1) Select from among the following, the correct option/s, that can be considered as (a) key
word/s in Java.
C:\Program Files\Java\jdk1.5.0_22\bin
Then consider the following working folder and its path of a student called Vimukthi
Jayaweera and assume that all his Java source files are saved in his working folder. Further
assume that Vimukthi has no administrative privileges in the computer.
C:\vimukthijayaweera\
Select from among the following, (a) suitable place/s, which can be used to write the set
path command in order to compile a Java file written by Vimukthi Jayaweera.
3) One has typed the following command in the command prompt in a windows based
computer where Java software is installed.
java
Select from among the following, the output which can be seen in the command prompt as a list.
4) Select from among the following, the option/s which can be considered as reference data
type/s in Java.
5) Select from among the following, valid assignments allowed in Java. Assume that all the variables
are properly declared.
(a) int value = value + 55; (b) a =+ 55; (c) mark = mark + 45;
(d) result += 56; (e) value = 78;
2
6) Consider the following program written in Java.
System.out.println("Vimukthi Jayaweera");
}
}
Select from among the following, the correct option/s on modifying the above program without
making compilation errors.
7) Select from among the following, the correct statement/s considering Windows and Linux
Operating systems and Java programming language.
(a) In Windows Operating system, one can use Notepad editor and in Linux one cannot
find Notepad editor to write the source code.
(b) When saving the source code in Windows, java file extension is required to type but in the
Linux environment it is not necessary to type the file extension.
(c) javac command is not a valid command in Linux but in Windows, it is a valid command in
compiling the Java source code.
(d) In a Linux Operating system, one cannot find eclipse or net beans like IDEs similar to
Windows Operating system.
(e) In a Linux operating system, the Java bytecode file will have the file extension .obj unlike
in Windows operating systems where one can see the file extension .oak.
8) Select from among the following, the operator/s which can be categorized as bit-wise operators in
Java programming language.
9) Select from among the following, the name/s which have an impact on development of the Java
programming language.
3
Use the following declarations and initializations to evaluate the Java expressions given in
questions 10 - 14. Assume that each expression is evaluated separately in the program.
int a = 10,b = 15,c = 20;
byte m = 1;
float k = 10.0f;
char ch = 'A'; // note that the ASCII value of A is 65
Consider the following pool of Java statements to answer questions 15 – 20. Note that each
statement is given a unique number as an identifier. In each question a problem is given and
in order to solve that problem one has to write segments of Java programs according to the
given instructions. It is not required to consider writing the class name or main method in the
program. Then in the answer each option is given a list of identifier numbers indicating the
program statements.
4
12 if( i / 2 == 0)
13 System.out.println(i);
14 int total=0;
15 for(int i = 50 ; i <= 60 ; i++)
16 for(int i = 50 ; i < 60 ; i++)
17 if( i % 2 = 0)
18 total = total + i;
19 System.out.println(total);
20 int number1 = 10 , number2 = 20 , number3 = 30;
21 if(number1 > number2 && number1 > number3)
22 System.out.println(number1);
23 else if(number2 > number3)
24 System.out.println(number2);
25 else
26 System.out.println(number3);
27 int num1 = 1, num2 = 5;
28 char op = '+';
29 switch(op)
30 case '+': System.out.println(num1 + num2); break;
31 case +: System.out.println(num1 + num2); break;
32 case '-': System.out.println(num1 - num2); break;
33 case -: System.out.println(num1 - num2); break;
34 case '/': if(num2 != 0)
System.out.println(num1 / num2);
break;
35 case /: if(num2 != 0)
System.out.println(num1 / num2);
break;
36 case '*': System.out.println(num1 * num2); break;
37 case *: System.out.println(num1 * num2); break;
38 default:System.out.println("Wrong Operator");
39 break:System.out.println("Wrong Operator");
40 total +=i;
41 for(int i = 50 ; i < 61 ; i++)
42 if(number2 > number1 && number2 > number3)
43 else if(number1 > number3)
15) Write a Java program to print the number series from 1 to 10 in the command prompt vertically.
The control variable name should be i and it should be initialized to 0. Using a for control structure
one has to write the program.
class Ex15{
public static void main(String args[]){ blank } }
5
16) Write a Java program to show number series 10 to 1 in the command prompt vertically. (10 9 8 7 6
5 4 3 2 1). Name of the control variable should be i and initialized it to 10. Using a for control
structure one has to write the program.
class Ex16{
public static void main(String args[]){ blank } }
17) Write a Java program to find all the even numbers (numbers which can be divided by 2 without any
remainders) from the number series 100 to 0 in the command prompt. Numbers should be printed in
the reverse order. E.g. 100 98…0. Using a for control structure one has to resolve the problem.
Name the control variable as i.
class Ex17{
public static void main(String args[]){ blank } }
18) Write a Java program to get the total of even numbers in the number series 50 to 60 including 50
and 60. The program has 2 variables. One variable named i is suppose to control flow. The other
variable is total to retain the total of all even numbers in the specified range. The program should
output only 330 as the total. One has to solve the problem using a for control structure.
class Ex18{
public static void main(String args[]){ blank } }
(a) 13, 14, 1, 16, 19, 2, 20 (b) 11, 12, 1, 15, 16, 2, 19
(c) 14, 41, 1, 11, 40, 2, 19 (d) 14, 15, 1, 11, 18, 2, 19
(e) 9, 11, 1, 15, 2, 14, 19
19) Write a Java program to find the largest number out of 3 given numbers. The three numbers are 10,
20 and 30. One has to declare 3 variables namely number1, number2 and number3 to store those
whole numbers. Using nested if control structure one has to evaluate the problem.
class Ex19{
public static void main(String args[]){ blank } }
(a) 20, 11, 12, 23, 2, 25, 26 (b) 2, 28, 1, 33, 34, 35, 36
(c) 28, 1, 12, 23, 2, 21 (d) 20, 42, 24, 43, 22, 25, 26
(e) 20, 21, 22, 23, 24, 25, 26
6
20) Write a Java program to simulate a simple calculator. The calculator has 2 numbers declared,
namely num1 and num2 and initialized with whole numbers 1 and 5. The operator is stored in a
variable having the name op and assigned with an operator +. The program should simulate
addition, subtraction, division and multiplication tasks. When division functionality is coded,
division by zero error should be considered. Using the switch control statement one has to solve the
problem.
class Ex20{
public static void main(String args[]){ blank } }
(a) 26, 27, 28, 29, 30, 31,32, 33, 34 (b) 25, 26, 27, 28, 29, 34,30 31, 32
(c) 27, 28, 29, 1, 30, 32, 34, 36, 38, 2 (d) 27, 28, 29, 1, 31, 33, 35, 37, 39, 2
(e) 1, 5, 23, 24, 25, 26, 27, 2, 12
21) Select from among the following, the notation/s which is/are common to both Nassi-shneidernan
diagrams and Flow Charts.
(a) (b)
(c) (d)
(e)
“The data items Total and Counter must already have been defined within the program”
Select from among the following the kind of data definition which is mentioned in the above
observation.
23) Select from among the following, (a) correct statement/s which describe/s the kind of a collection
called Maps.
(a) A Map is an object that one can use once to retrieve all the objects in a collection one by
one.
(b) In an entry of a Map, a pair of objects is involved.
(c) In Java collection framework, a Map is implemented as a priority queue.
(d) The key determination process in a Map is called hashing.
(e) A Map, linked list, Vector and a queue can be considered as lists in collection framework.
7
24) Consider the following diagram noting the outer circles with roman numbers. The diagram
illustrates to use some basic set of criteria for selecting notations to be used in algorithm
specification.
(i)
Rules for
(iv) choosing
notations in
algorithm
specification
(ii)
(iii)
Select from among the following, the valid options to fill the circles numbered i – iv in roman.
(a) (i) conciseness, (ii) unambiguity, (iii) capable in machine execution, (iv)
promoting the elegance in the solution.
(b) (i) Modular, (ii) Art form, (iii) Structured,(iv) Object orientation
(c) (i) Nassi-shneidernan, (ii) Pseudocode, (iii) Flow Chart, (iv) NS diagram
(d) (i) Process, (ii) Decision, (iii) Termination, (iv) Flow of Logic
(e) (i) Input employee details, (ii) Compute gross pay, (iii) Compute tax, (iv)
Compute net pay.
25) Select from among the following, the valid method/s which is/are bundled with Stack storage
collection.
8
Consider the following class declarations to answer questions 26 – 35.
abstract class J{
private int varA1;
private int varA2;
J(){}
public final void methodA1(int x){
varA1=x;
}
public abstract void methodA2(int y){
varA2=y;
}
}
K(){}
public abstract void methodB1(String z){
varB1=z;
}
public final String methodB2(){
return varB1;
}
}
class M extends K{
private static char varK1;
M(){}j
public void methodM1(char h){
varK1 = h;
}
}
class DriverProgram{
public static void main(String args[]){
}
}
26) Select from among the following, direct child class/classes of the class J according to the above
declarations.
(a) Class J only (b) Class K only (c) Classes J and K only
(d) Classes L and M only (e) Classes M only
(a) Class K only (b) Class M only (c) Classes J and M only
(d) Classes L and K only (e) Class L only
9
28) Select from among the following, illegal class declaration/s which can be seen in the segment of
code.
(a) Class J only (b) Classes J and K only (c) Classes J, K and M only
(d) Class L only (e) All the classes
29) Select from among the following, valid constructor method/s available in the given code.
30) Consider the class J and select from among the following, the valid option/s which can be
considered as similar examples for class J.
31) Consider the class J and select from among the following, the valid class/classes which can be
considered as similar examples as class K.
32) Select from among the following, the valid option/s which can be considered as (an) instance
variable(s).
33) Select from among the following, the valid option/s which can be considered as (a) class variable(s)
34) Select from among the following, the valid class declaration/s assuming that the body of each class
is not written in the following options.
35) Select from among the following, the valid statement/s illustrating object creation.
10
36) Read the following statement noting the blank indicated as blank.
“The direct two subclasses of the _____blank_____ class are class Error and class Exception.”
Select from among the following, the correct option to fill the blank.
37) Select from among the following, the package in which the RuntimeException class is defined.
int ar[]={1,2,3,4,5,6};
int i= ar.length - 1;
int ar[]={1,2,3,4,5,6};
int i= ar.length - 1;
11
41) Consider the following segment of program written in Java.
String names[]={"Kandy","Dubai"};
System.out.print(names);
}
}
Select from among the following, the invalid option/s regarding the above program.
System.out.print(str1 + str2);
43) Read the following statement on Streams in Java noting the blank indicated as blank.
“A block of memory that is used to batch up the data that is transferred to or form an external
device, a ___blank______ can be used.”
Select from among the following, the correct option to fill the blank.
44) Select from among the following, direct sub classes which come under InputStream class.
45) Select from among the following, type of character set which is supported by Java.
*********
12