2010 Past Paper
2010 Past Paper
2010 Past Paper
IT2204 - Programming I
07th August, 2010
(TWO HOURS)
Important Instructions :
• Each question will have 5 (five) choices with one or more correct answers.
• 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).
• 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
1) Select from among the following, the correct options which can be considered as packages
that come under the Java standard library.
2) Consider the following name which is appearing in the home directory of a windows
environment.
jdk1.5.0_01
Select from among the following, the release version number which can be seen in the
above directory name.
3) Select from among the following, the file name/s which can be qualified as (a) Java source
file(s).
5) Select from among the following, what can be considered as key words available in Java.
“A programmer needs to avoid the execution of some codes from the program.”
Select from among the following, the correct operator(s) which is/are valid in Java to achieve the
wish of the programmer.
2
Use the following declarations and initializations to evaluate the Java expressions given in
questions 7 - 11. Assume that each expression is evaluated separately in the program.
long x = 10,y = 15,z = 20;
int m = 0;
short k = 10;
char ch = 'B' // note that the ASCII value of B is 66
7) System.out.println(m = x);
8) System.out.println(k = k * 100);
9) System.out.println(m = ch);
11) System.out.println( z = k + ch );
class A{
private int var1;
private float value1 = 34.5f;
private static value2;
A(c){
value2 = c;
}
3
12) When the program was compiling, errors were generated showing the following messages in the
command prompt.
Select from among the following, the programming statement/s which could be the cause/s for the
error generated indicated as the error number 5.
13) In order to correct the error generated, statements in the program can be replaced with new
statements as shown in the following table.
Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.
4
14) After successfully correcting the error in question number 12, the program was compiled again. The
following message was displayed in the command prompt.
Select from among the following, the programming statement/s which could be the cause/s for the
error generated.
15) In order to correct the error generated in the question number 14, statements in the program can be
replaced with new statements as shown in the following table.
Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.
16) After correcting the erroneous code traced in question number 15, the program was compiled again.
The following message was displayed in the command prompt showing an error.
Select from among the following, the programming statement/s which could be the cause/s for the
error generated indicated as the error number 16.
5
17) In order to correct the error generated in question number 16, statements in the program can be
replaced with new statements as shown in the following table.
Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.
18) After correcting the erroneous code traced in question number 17, the program was compiled again.
The following message was displayed again in the command prompt indicating an error.
Select from among the following, the programming statement/s which could be the cause/s for the
error generated.
19) In order to correct the error generated in question number 18, statements in the program can be
replaced with new statements as shown in the following table.
Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.
6
20) After debugging the erroneous situation in question number 19, the program was complied
successfully. But still, one can see a problematic code in the program which can affect the proper
execution of the program. Consider the following situation regarding the existing statement and the
new statement.
Select from among the following, the correct row number/s which is/are suitable for eliminating the
error.
21) Select from among the following, the valid array declarations that are allowed in Java.
(a) int ar[]= new ar[]; (b) int[] ar= new int[7];
(c) int ar = new int[85] ; (d) int ar[] = new int[];
(e) int ar[45] = new ar[];
7
Use the following declarations and initializations to evaluate the Java expressions given in
questions 23 - 24. Assume that each expression is evaluated separately in the program.
byte a = 10;
float y = 5.0f;
int m = 55;
else
(a) year + " is a leap year" (b) year + " is not a leap year"
(c) 2004 + " is a leap year" (d) 2004 is a leap year
(e) 2004 is not a leap year
if(ar[i] == 3)
break;
else
System.out.print(ar[i]);
8
27) Consider the following segment of a program written in Java.
System.out.println(num1+" "+num2);
9
29) Consider the following program written in Java.
class WhileDemo {
public static void main(String[] args){
int count = 5;
while (count > 3) {
System.out.print(count);
count--;
}
}
}
30) Select from among the following, statement/s which can be seen in the program that can be
considered as not valid in Java.
31) Select from among the following, the key words which cannot be seen in the program but required
for the completeness of it.
32) When the above program was complied, some errors were reported in the command prompt. Select
from among the following, the cause/s for those errors generated. They were generated due to
(a) missing catch key word. (b) missing while key word.
(c) the case 2-5: programming code (d) the public class Switch statement.
(e) the switch(number < 7) code
10
33) Select from among the following, the correct option/s that can be considered as common
characteristics of sub routines and functions.
(a) They are invoked by stating their names together with any required parameters.
(b) Sub routines and functions may call themselves.
(c) They may themselves call other sub-procedures, but may not call the main procedure.
(d) Once they are called, their results are communicated as global data or passed parameters.
(e) When they are invoked, the program control passes to the called sub procedure and
resumes at the first executable statement in that procedure.
34) There are some guiding principles introduced for decomposition of a program into sub procedures
and eliminating duplication of codes is one such a principle. Select from among the following, the
correct statement/s which describe/s the need of eliminating duplication of codes.
(a) It provides the ability for original programmer or others who follow him to be able
to understand the nature of the program
(b) No task should be coded in more than one place in any program.
(c) Divide the project into small self-contained procedures and allocate procedures among the
programmers to develop.
(d) After decomposition each procedure should perform one and only one task.
(e) Process which has already been coded and known to work correctly in one program can be
copied into another program which requires the same functionality.
Select from among the following, the correct option which can be used to fill the blank.
36) Select from among the following, the package in which most of the types that make up the
collection framework are stored.
String str1=”Vimukthi”;
String str2+=” likes playing wrestling”;
11
38) Consider the following program written in Java.
class Str{
public static void main(String args[]){
double value1 = 10000;
float value2 = 35.0f;
String str = String.valueOf(value1);
System.out.println(str + value2);
}
}
class Abc{
public static void main(String args[]){
String str1 = "Anuradhapura";
String str2 = "Anuradhapura";
System.out.print(str1.equals(str2));
}
}
class Compare{
public static void main(String args[]){
String str1 = "Sigiriya";
String str2 = "Jaffna";
System.out.print(str1.compareTo(str2));
}
}
41) Select from among the following, key words which have a direct relationship with the object
oriented concept called data hiding.
42) Select from among the following, the stream type/s which is/are supported by the java.io package.
12
43) FilterInputStream class has nine direct subclasses that provide more specialized ways of
transforming data from an input stream. The following statement gives a description to one such
class inherited from the class FilterInputStream.
Select from among the following, the correct subclass which matches with the above description.
44) Select from among the following, different items of information that can be expected from an
object of type throwable class about an exception.
(a) A message which has been initialized by a constructor denoting the exception
(b) A way to clean up garbage generated at the end of executing a try block
(c) A record for the execution stack at the time the object was created
(d) A message informing a standard exception after rethrowing and object of type throw
(e) A message informing a wrong usage of an input device
45) Consider the following message which can be expected in the command prompt when a program
statement is executed.
Select from among the following, the programming statements which can be cause the generator of
such a message in the command prompt.
*********
13