Professional Documents
Culture Documents
Past Papers
Past Papers
Past Papers
(TWO HOURS)
Important Instructions :
The duration of the paper is 2 (two) hours.
The medium of instruction and questions is English.
The paper has 40 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.
Calculators are not allowed.
All Rights Reserved.
1
1) Select from among the following, the programming language(s) that Java was directly related to during
its development.
2) Select from among the following, the valid option(s), that can be considered as keywords of the Java
programming language.
3) Select from among the following, the valid floating point primitive type(s) available in the Java
programming language.
4) Select from among the following, the valid variable initialization(s) allowed in the Java programming
language.
(a) int value1 = 3; (b) byte value2 = 1000; (c) float value3 = 23;
(d) double value4 = 25; (e) char value5 = “ Thisara ”;
5) Select from among the following, the valid option(s) that can be considered as steps in writing a computer
program.
6) Select from among the following, the valid features of Object Orientation.
7) Select from among the following. the valid access control modifier(s) allowed in the Java programming
language.
2
8) Select from among the following, the package where the Scanner class is stored in Java.
9) Consider the following statements, written about Applets in the Java programming language.
Select from among the following, the valid option(s) that can be considered as drawback(s) of Applets in
Java.
10) Select from among the following, classes which are stored in the java.sql package.
Use the following declarations and initializations to evaluate the Java expressions given in questions
11 - 15. Assume that expressions are evaluated separately in a separate program.
int num1=070,num2=0b00101010;
float x=20.0f;
int var=12_00_000;
char ch='A';//note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the evaluations 11 – 15.
11) System.out.println(x>>1);
12) System.out.println(ch>>1);
3
13) System.out.println(num1>2 & num1<35);
for(int i=0;i<=5;i++){
System.out.print(i);
break;
}
(a) 1.0 2.0 3.0 4.0 3.4 4.4 (b) 1 2 3 4 3.4 4.4 (c) 1.0 2.0 3.0 4.0 3.4f 4.4f
(d) 1.0, 2.0, 3.0, 4.0, 3.4, 4.4 (e) error
4
18) Consider the following runtime error generated during an execution of a Java program.
Select from among the following, a valid option of a Java statement by which the above error would
have been generated.
19) Consider the following runtime error generated during an execution of a Java program.
Select from among the following, a valid option of a Java statement by which the above error would have
been generated.
Select from among the following a suitable option to identify the process of the above expression.
5
21) Consider the following runtime error generated during an execution of a Java program.
Select from among the following, a valid option of a Java statement by which the above error would have
been generated.
22) Consider the following program written in Notepad and saved in a working folder called programs.
package MyData;
class MyName{
String name;
MyName(){
name=null;
}
void show(){
System.out.println(name);
}
}
public class DP{
public static void main(String args[]){
MyName ob=new MyName();
ob.show();
}
}
After saving into the program folder and successfully compiling, the java DP command was issued. Select
from among the following the outcome of the program execution.
6
23) Consider the following segment of code written in the Java programming language with a major syntactic
error.
class A {
public interface MyInterface {
boolean isNotNegative(int x); } }
class B implements MyInterface{
}
Select from among the following the code(s) which accounts for this major syntactic error.
24) Consider the following segment of a program written in Java noting a/some missing important part(s).
class Gen {
T ob;
Gen(T value) {
ob = value;
}
T getOb() {
return ob;
}
Select from among the following, the acceptable part(s) of the program after introducing the missing
part(s).
(a) class Gen( T ) (b) T getOb( int value) (c) value * ob;
(d) int getOb() (e) class Gen <T>
25) Annotation retention policy determines at what point an annotation is discarded. Which of the following
is/are part of an annotation retention policy?
7
27) Select from among the following, valid file related methods available in Java.
28) Select from among the following, valid byte streams available in Java.
public class Ex {
public static class Thread1 extends Thread {
public void run() {
System.out.println("A");
System.out.println("B");
}
}
public static class Thread2 extends Thread {
public void run() {
System.out.println("1");
System.out.println("2");
}
}
public static void main(String[] args) {
new Thread1().start();
new Thread2().start();
}
}
29) Select from among the following, similar methods as start() available in Thread class.
30) What would the output of the program be when the program executed several times?
8
Consider the following table having two columns in it. The first column has line numbers and the
second has different programing statements and expressions. Using this table answer questions 31 –
38 having two parts in it. Part A and Part B. The way that one has to answer these two parts are
different.
Further assume that when answering the questions the following packages are also imported into
the programming environment.
import javax.swing.*; import java.awt.*; import java.awt.event.*;
Part A
Answer the questions 31 – 35 by selecting the valid answer(s) based on the table.
31) Select from among the following, valid class names that can be seen in the table given.
32) Select from among the following, valid object names that can be seen in the table given.
33) Select from among the following, valid user defined methods shown in the table given.
34) Select from among the following, valid access modifiers available in Java.
9
35) Select from among the following, valid constructor methods illustrated in the table.
Part B
Questions 36 – 38 give an expected output to be obtained. In these questions, the class declarations
and their main method are also written partially. One is required to select from this table the
relevant statement number(s) required to obtain the expected output.
10
38) Expected output:
39) Consider the following program written in the Java programming language.
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
public class Main extends JFrame {
JCheckBox check = new JCheckBox("Checkbox", false);
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
check.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.out.println("Checked? " + check.isSelected());
}
});
getContentPane().add(check);
pack();
setVisible(true);
}
public static void main(String arg[]) {
new Main();
}
}
Select from among the following, the changes required to the program for event handling in Java, if the
software engineer uses a button instead of a check box in the program.
11
40) Select from among the following, valid method(s) which are related to the JFrame class.
(a) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
(b) setVisible(true);
(c) setTitle(“Play a game”)
(d) setText(“Welcome”);
(e) setSize(200,300);
*****
12
Bachelor of Information Technology
Academic Year 2020– 1st Year Examination – Semester 1
IT1406 – Answers
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2205 - Programming I
02nd November, 2019
(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 11 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
auroracs.lk
Consider the following program to answer questions 1 – 4.
1) Select from among the following keyword(s) that can be seen in the program.
2) Select from among the following valid file name(s) to save the above program.
3) Select from among the following valid command(s) to compile the program.
4) Select from among the following valid option(s) that can be used to execute the Java
program.
6) Select from among the following, valid comments in the Java programming language.
2
auroracs.lk
7) Select from among the following, correct option(s) which illustrate(s) primitive data types in Java.
8) Select from among the following, correct option(s) which illustrate(s) reference data types in Java.
b=(byte)i;
i=(int)d;
b=(byte)d;
Select from among the following, correct option(s) to name the above conversion process practiced
in the expressions.
11) Select from among the following, valid variable names in Java.
12) Select from among the following, valid logical operators in Java.
3
auroracs.lk
13) Consider the following program written in Java.
Consider the following program to answer questions 14 – 15 noting the blank1, blank2 and
blank3.
14) When the program is executed successfully, the following output is displayed on the console.
Programming
i fun"
Select from among the following, valid literals to fill the blanks.
15) Select from among the following, the valid name(s) for the selected literal category.
Select from among the following the correct option(s) to fill the blank in the sentence.
4
auroracs.lk
Use the following declarations and initializations to evaluate the Java expressions given in
questions 17 - 22. Assume that expressions are evaluated separately in a separate program.
int num1=070,num2=0b00101010;
float x=20.0f;
int var=12_00_000;
char ch='A';//note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the evaluations 17 – 22.
17) System.out.println(var);
18) System.out.println(num1);
19) System.out.println(num2);
20) System.out.println(x+var);
21) System.out.println(x>num1);
22) System.out.println(ch+x);
23) Select from among the following, valid exception class(es) which is/are referenced when a division
by zero error occurs.
(a) NumberFormatException
(b) ArithmaticException
(c) IOException
(d) NullPointerException
(e) ArrayIndexOutOfBoundException
5
auroracs.lk
24) Select from among the following, valid exception class(es) which can be categorized as unchecked
exceptions.
(a) NumberFormatException
(b) ArithmaticException
(c) IOException
(d) NullPointerException
(e) ArrayIndexOutOfBoundException
25) Select from among the following, valid exception class(es) which can be categorized as checked
exceptions.
(a) NumberFormatException
(b) ArithmaticException
(c) IOException
(d) NullPointerException
(e) ArrayIndexOutOfBoundException
26) Select from among the given options, the correct output of the program.
27) Select from among the following, the valid option(s) that can be categorized under the key words try
and catch which are used for exception handling in Java.
6
auroracs.lk
Consider the following table having two columns in it. The first column has line numbers and
the second has different programing statements and expressions. Using this table answer
questions 28 – 31.
Each question gives an expected output to be obtained. It also gives the class declarations and
its main method. One is required to select from this table the relevant statement number(s)
required to obtain the expected output.
Select from among the following, the correct statement number sequence(s) to obtain the pattern
shown above.
public class Ex28{
public static void main(String args[]){
(a) 6,1,4,8 (b) 3,1,6,8 (c) 6,1,5,8,9,23
(d) 4,1,6,8 (e) 6,1,6,8,23,2
System.out.println();
}
}
}
7
auroracs.lk
29) Expected output:
A***
*A**
**A*
***A
Select from among the following, the correct statement number sequence(s) to obtain the pattern
shown above.
public class Ex29{
public static void main(String args[]){
(a) 6,1,4,11,8,13,14 (b) 6,1,6,11,8,,13,14 (c) 4,1,6,11,8,13,14
(d) 6,1,5,11,8,13,14,9,2 (e) 3,1,6,11,8,13,14
System.out.println();
}
}
}
31) After seeing the pattern shown in question number 30), the software engineer changed the coding of
the program to obtain the following pattern.
A
A
A
A
Select from among the following, the correct statement number sequence(s)to obtain the pattern
shown above.
public class Ex31{
public static void main(String args[]){
(a) 6,1,4,25,14,13,16 (b) 27,1,4,2,9,18,27 (c) 7,1,8,9,2,11,25,26,27,2
(d) 7,2,8,8,2,10 (e) 6,1,9,17,18,1
System.out.println();
}
}
}
8
auroracs.lk
32) Select from among the following, correct option(s) where the applet class is located.
33) Select from among the following, the sub class(es) of the Reader class.
class Car{
private int carNo;
class Engine{
int engineNo;
}
}
class Ex36 {
public static void main(String args[]){
Car obj1=new Car();
Car.Engine obj2=obj1.new Engine();
System.out.println(obj2.engineNo);
}
}
9
auroracs.lk
36) What would the output of the program be?
37) Select from among the following, name(s) of (the) byte code(s) which has/have been generated after
compiling the program successfully.
Employee
38) Select from among the following, the valid option(s) that can be considered as super classes in the
given diagram.
39) Select from among the following, the valid option(s) that can be considered as child classes in the
given diagram.
40) Select from among the following, valid option(s) where one can apply the key word abstract during
class declaration considering the given scenario.
41) Select from among the following, valid option(s) where one can apply the key word final during class
declaration considering the given scenario.
42) A software engineer has written the following method signatures in the class Clerk.
Clerk()
Clerk(String name, String address)
Select from among the following suitable name/s to identify the methods.
10
auroracs.lk
43) Consider the following partially written programs in Java.
class A{ }
class B { }
interface In1{}
Interface In2{}
Interface In3{}
Interface In4{}
Select from among the following the valid programming statement(s) in Java.
45) Select from among the following, the valid object oriented feature(s) used in the program.
*******
11
auroracs.lk
Bachelor of Information Technology
Academic Year 2019 – 1st Year Examination – Semester 2
IT2205 Programming 1 – Answers
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2205 - Programming I
22nd September, 2018
(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 13 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.
Calculators are not allowed.
1
auroracs.lk
1) Which of the following are keywords in Java?
BLANK number = 5;
Select valid option(s) to replace the term BLANK in this statement, from among the
following.
System.out.print(value);
}
}
2
auroracs.lk
5) Consider the following code written in Java.
6) Select from among the following, those which can be considered as comments allowed in Java.
7) Select from among the following, correct option(s) which illustrates escape sequence(s) allowed in
Java.
8) Select from among the following, the default character encoding used in Java programming language.
enum Colour
{
RED, GREEN, BLUE;
}
3
auroracs.lk
10) Consider the following code written in Java.
class Ex11 {
public static void main(String args[]){
double a,b,c;
a = 3.0/0;
b = 0/4.0;
c = 0/0.0;
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
Use the following declarations and initializations to evaluate the Java expressions given in
questions 12 - 17. Assume that each expression is evaluated separately in the program.
int a=-1,b=2;
float x=10.0f;
char ch='A';//note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the evaluations 12 – 17.
12) System.out.println(a<<<1);
13) System.out.println(b>>>1);
14) System.out.println(x>>1);
4
auroracs.lk
15) System.out.println(x<<1);
16) System.out.println(ch<<1);
17) System.out.println(ch>>1);
Consider the following table having two columns in it. First column has line numbers and the
second has different programing statements and expressions. Using this table answer questions
18 – 22. Each question gives an expected output to be obtained. It also gives the class
declarations and its main method. You are required to select from this table the relevant
statement number(s) required to obtain the expected output.
*
*
*
*
*
*
*
Select from among the following, the correct option(s) to obtain the pattern shown above.
5
auroracs.lk
public class Ex18{
public static void main(String args[]){
(a) 1,3,1,2,4,2 (b) 3,4 (c) 3,5
(d) 8,4 (e) 3,1,4,2
}
}
******
Select from among the following, the correct option(s) to obtain the pattern shown above.
******
******
******
******
******
******
Select from among the following, the correct option(s) to obtain the pattern shown above.
21) After seeing the pattern shown in question number 20), the software engineer changed the coding of
the program to obtain the following pattern.
******
*****
****
***
**
*
Select from among the following, the correct option(s) to obtain the pattern shown above.
6
auroracs.lk
public class Ex21{
public static void main(String args[]){
(a) 6,1,11,5,10,2 (b) 3,1,4,2,9 (c) 7,1,8,9,2,11
(d) 7,2,8,8,2,10 (e) 6,1,9,10,5,2
}
}
22) After seeing the pattern shown in the question number 20), the software engineer changed the coding
of the program to obtain the following pattern.
*
*
*
*
*
*
Select from among the following, the correct option(s) to obtain the pattern shown above.
class Ex24 {
public static void main(String args[]){
int ar[]=new int[2];
System.out.println(ar[0]+ar[1]);
}
}
7
auroracs.lk
25) Consider the following program written in Java.
class Ex25 {
public static void main(String args[]){
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
n = arr[arr[n] / 2];
System.out.println(arr[n] / 2);
}
}
class Ex26 {
public static void main(String args[]){
int ar1[] = new int[] {0,1, 2, 3};
System.out.println(ar1);
}
}
class Ex27 {
public static void main(String args[]){
int ar1[][] = {{ 1, 2, 3},
{ 4 , 5, 6},
{ 7, 8, 9}};
int sum = 0;
8
auroracs.lk
28) Select from among the following, the valid option(s) that can be used for naming classes, variables
or methods in the Java programming language.
29) A process that involves recognizing and focusing on the important characteristics of a situation or
object, as an object oriented feature is known as:
30) In object oriented programming new classes can be defined by extending existing classes. In object
orientation, this is referred to as:
31) Select from among the following, correct object oriented feature which describes the process of
wrapping up of data and functions into a single unit.
32) Select from among the following, the valid object oriented feature(s) which show(s) the ability of
two or more objects belonging to different classes to respond to exactly the same method in different
classes.
static int i = 1;
9
auroracs.lk
34) Consider the following program written in Java.
public class Ex34{
static int i = 1;
class Test{
void method(int i, int j){
i *= 2;
j /= 2;
}
}
class Ex35{
public static void main(String args[]){
Test ob = new Test();
int a = 15, b = 20;
System.out.println(a +" " + b);
ob.method(a,b);
System.out.println(a + " " +b);
}
}
What would the argument passing method be which is used by the above program?
36) Select from among the following, the valid option(s) to which the @Deprecated annotation can be
applied.
10
auroracs.lk
37) Consider the following program written in Java.
class A{
protected int a;
A(){a=7;}
}
class B extends A{
private int b;
B(){b=3;}
public void show(){
System.out.println(a+" "+b);
}
}
interface Calculate{
void cal(int item);
}
class Ex40{
public static void main(String args[]){
Display arr = new Display();
arr.x = 0;
arr.cal(2);
System.out.print(arr.x);
}
}
38) Select from among the following, the valid option(s) to fill blank1.
11
auroracs.lk
39) Consider the following statement written in the above program.
Select from among the following, invalid alternative way(s) of implementing the above statement in
an interface.
40) What would the output of the program be, if the software engineer has filled the blank1 with the
right option in a syntactically correct manner?
class Ex41{
public static void main(String args[]){
String obj = "ILIKEJAVA";
System.out.println(obj.charAt(7));
}
}
class Ex42{
public static void main(String args[]){
String obj = "ILIKEJAVA";
System.out.println(obj.length());
}
}
12
auroracs.lk
43) Consider the following program written in Java.
class Ex4{
public static void main(String args[]){
String s1 = "Hello";
String s2 = s1.replace('l','w');
System.out.println(s2);
}
}
What would the output of the program be?
44) Select from among the following, valid interface(s) in the collection framework, which must contain
unique elements in it.
45) Select from among the following, the valid keyword(s) used for exception handling in Java.
*******
13
auroracs.lk
Bachelor of Information Technology
Academic Year 2018 – 1st Year Examination – Semester 2
IT2205 – Answers
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2205 - Programming I
11th November, 2017
(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 11 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
auroracs.lk
1) Select from among the following, correct options which can be considered as logical
operators in Java.
}
}
4) Select from among the following, the valid option which explains the conversion occur here
in the program.
(a) connect many household machines. (b) perform operations on the Internet.
(c) create high performance OS. (d) send the path finder to the mars.
(e) compete with Android.
2
auroracs.lk
6) Select from among the following, those which cannot be considered as primitive data types in Java.
7) Select from among the following, correct option(s) which illustrate/s correct long type literals in Java.
(a) Code will not compile and will give "Duplicate main() method declaration" error.
(b) Code will compile correctly but will give a runtime exception.
(c) Code will compile correctly and will print "In first main()" (without quotes) when it is
run.
(d) Code will compile correctly and will print "a" (without quotes) when it is run.
(e) Source code cannot be saved since there are two main methods in the program.
(a) all the packages. (b) all the methods. (c) only within the package.
(d) only within the class. (e) all the systems.
3
auroracs.lk
11) Select from among the following, the operator(s) used to invert all the digits in a binary representation
number.
Use the following declarations and initializations to evaluate the Java expressions given in
questions 12 - 17. Assume that each expression is evaluated separately in the program.
Select from among the given options, the correct output for each of the evaluations 12 – 17.
12) System.out.println(str+ch);
13) System.out.println(ch+value1);
14) System.out.println(ch<str);
16) System.out.println(str++);
17) System.out.println(!(num1+ch));
18) Select from among the following, the key word(s) which is/are not a part of exception handling in
Java programming language.
4
auroracs.lk
19) Consider the following program written in Java.
}
catch(ArithmeticException e) {
System.out.print("0");
}
System.out.print(sum);
}
}
20) Select from among the following, (a) valid key word(s) which prevent(s) overriding methods in the
super class.
21) What will be the version which is referred, when an overridden method is called from within a
subclass?
Applicants are advised to read questions 22 – 27 keeping in mind that these questions have
connections to another.
Select from among the following, the valid statement(s) allowed within the class Employee.
5
auroracs.lk
23) Consider the following segment of Java class declaration.
Select from among the following, valid option(s) that must be selected in the class declaration which
is required by the compiler.
24) Select from among the following, valid option(s), which can be considered logically within the class
declaration Teacher which is a sub class of the Employee class. Even though the given programming
statement(s) are correct one has to consider the suitability of them concerning Object oriented
features.
After that one has created an object of the class PayrollClerk as follows.
At the time of compiling, an error was generated. Select from among the following, valid option(s)
which shows the most close reason(s) for the error generated.
Select from among the following, the invalid object oriented feature, which has been tried to
introduce in the above class declaration.
6
auroracs.lk
27) Select from among the following, the valid object declaration(s) which is/are valid in Java
programming language.
28) Select from among the following conditions that are not allowed in Java programming language
assuming var1, var2 and var3 variables are declared correctly in the program.
(a) var1 == var2 (b) var1 =< var3 (c) var1 > var2 > var3
(d) var2 => var3 (e) var1++
} } }
7
auroracs.lk
31) Consider the following program written in Java.
class Ex31{
public static void main(String args[]){
String s1 = "Hello i love java";
String s2 = new String(s1);
System.out.println((s1 == s2) + " " + s1.equals(s2));
}
}
8
auroracs.lk
34) Consider the following program written in Java.
35) Select from among the following, the valid key word(s) which is/are used by an interface to use
another interface which is defined previously.
36) Select from among the following, (a) valid abstract method declaration/s in an abstract class.
37) Select from among the following, the correct method to display a string in an applet.
9
auroracs.lk
Consider the following program written in Java to answer questions 38 – 39.
class Test {
public static void main(String[] args) {
String chars[] = { "A", "B"};
39) Assume that one needs to get the output of the program as A and B (A B). Select from among the
following, the programing statement(s) which is/are needed to be changed.
(a) for (int sample: chars) (b) class Test (c) String chars[]
(d) System.out.print(sample); (e) { "A", "B"};
40) Select from among the following, the valid option(s) which store(s) all the standard classes like
String, System in Java.
41) Select from among the following, valid escape sequences in Java.
42) Select from among the following, (a) valid option(s) which is/are not interfaces in Java collection
framework.
43) Select from among the following, the valid definition(s) of the @Deprecated annotation.
10
auroracs.lk
44) Consider the following program written in Java.
When the program is compiled, there were errors generated. Select from among the following, the
valid option(s) which caused the generation of those errors.
(a) final class (b) public static <T> (c) return x > y ? x : y;
(d) max(T x, T y) (e) Type safety
*******
11
auroracs.lk
Bachelor of Information Technology
Academic Year 2017 – 1st Year Examination – Semester 2
IT2205 – Answers
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2205 - Programming I
22nd October, 2016
(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 13 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
auroracs.lk
1) Select from among the following, the first name given for Java.
2) Select from among the following, valid features which are supported by Java.
4) Select from among the following, valid output generated after a Java source file is
successfully compiled.
5) Java is an Object Oriented Programming language. Select from among the following
correct option(s) which show(s) how Java achieve common information sharing.
6) Select from among the following, valid reference data types available in Java.
float value1=10.0f,value2=20.0f;
int valueOne = 30,valueTwo=40;
}
}
2
auroracs.lk
7) Select from among the following, correct option(s) which illustrate/s output of the program when
it is executed.
8) Assume that the following statement is written in the program removing the symbols // in the
program
9) Select from among the following, valid symbol(s) available in Java programming language which
has the similar functionalities as the symbol // illustrated in the above program.
10) Select from among the following, names which are given to each operator used in the program.
11) Select from among the following, valid option(s) which shows the same operator(s) belong to
the same category as the operators & and ^.
Use the following declarations and initializations to evaluate the Java expressions given in
questions 12 - 17. Assume that each expression is evaluated separately in the program.
float x = 10.0f;
int num1=20,num2=30;
double num4 = 100;
boolean value5 = true;
char ch = 'B'; // note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the questions 12 –19.
12) System.out.println("Answer"+value5+num1);
13) System.out.println(value5+ch);
3
auroracs.lk
14) System.out.println(x*ch);
20) Select from among the following, correct operator(s) which use(s) to allocate memory to an array
variable.
4
auroracs.lk
22) Consider the following illustration.
* * * *
* * * *
* * * *
* * * *
Select from among the following, the valid program segment, by which the above illustration can
be derived as an output in the command line.
5
auroracs.lk
23) Consider the following illustration.
* * * *
* * *
* *
*
Select from among the following, the valid program segment, by which the above illustration can
be derived as an output in the command line.
6
auroracs.lk
24) Consider the following illustration.
*
*
*
*
Select from among the following, the valid program segment, by which the above illustration can
be derived as an output in the command line.
7
auroracs.lk
25) Consider the following illustration.
*
**
***
****
Select from among the following, the valid program segment, by which the above illustration can
be derived as an output in the command line.
8
auroracs.lk
26) Consider the following illustration.
****
***
**
*
Select from among the following, the valid program segment, by which the above illustration can
be derived as an output in the command line.
27) Select from among the following, correct statements on access specifies available in Java.
(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
(e) default members are defined by using the default key word in Java
9
auroracs.lk
Consider the following program written in Java to answer question 28 – 29.
28) Select from among the following, how many array declarations are written in the program.
class A {
private int i;
public void display() {
System.out.println(i);
}
}
class B extends A {
private int j;
public void display() {
System.out.println(j);
}
}
class DP {
public static void main(String args[]){
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
10
auroracs.lk
30) Select from among the following, valid description(s) which can be used to name the class
denoted as B in the program.
31) Select from among the following, valid description(s) which can be used to name the class
denoted as A in the program.
32) When the program was compiled, there were errors generated. Select from among the following,
the statement(s) which caused to generate those errors.
(a) private int i; (b) private int j; (c) B obj = new B();
(d) class DP (e) B obj = new B();
33) When the program is interpreted, the programmer needs to get an output in the command prompt.
Then the program needs modification. Select from among the following, valid modifications that
can be applied to the program.
34) Consider the following segment of code which is appearing in the program.
class B extends A
Select from among the following, valid option(s) which shows the object oriented feature which
has been achieved by the given segment of code.
35) In the program one can see the following segment of program in two places.
public void display() { }
Select from among the following, the object oriented feature(s) which has been achieved through
the program segment.
36) Select from among the following, valid option which shows the super class of all the exceptional
types.
37) Select from among the following, valid option(s) which can be used to manually throw an
exception.
11
auroracs.lk
38) Select from among the following, the exception which occur when JVM runs out of memory.
40) Select from among the following, valid access modifiers allowed in Java interfaces.
42) Select from among the following, (the) class/es which used for input and output operations when
work with bytes.
43) Select from among the following, valid annotations used in Java.
12
auroracs.lk
44) Select from among the following, valid escape sequences used in Java.
class Ex45{
public static void main(String args[]){
int x = 2;
int y = 0;
for ( ; y < 10; ++y) {
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
*******
13
auroracs.lk
Bachelor of Information Technology
Academic Year 2016 – 1st Year Examination – Semester 2
IT2205 – Answers
Year 2016
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2205 - Programming I
25th July, 2015
(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 11 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
auroracs.lk
1) Select from among the following, correct options which can be considered as key words in
Java.
3) Select from among the following, correct statement(s) on Java programming language.
Java is:
(a) case sensitive. (b) strongly typed.
(c) supportive in Internet programming. (d) simple in syntaxes.
(e) a fully object oriented language.
var1=8;
When the program was compiled, there were errors generated. Select from among the following
correct statement(s), which will describe the underlying concept behind the erroneous situation.
Select from among the following, incorrect statement(s) regarding the program.
(a) It will generate compile time errors. (b) final is a key word to define constants.
(c) At run time number variable will (d) number is a key word in Java
hold 45.4f.
(e) At run time the program will output
45.4.
6) Select from among the following, data types which can be considered as reference data types.
2
auroracs.lk
7) Select from among the following, correct option(s) which illustrate/s String literals in Java.
(a) val+" "+str+" "+flag (b) 0 null false (c) 0 null true
(d) 0 0 0 (e) error
9) Select from among the following, valid variable name(s) which is/are used in Java.
After compiling successfully, the program was executed by issuing the following command.
java Ex10 4 1
222222222222L
Select from among the following, option(s) which cannot be used to hold the above value as it is.
3
auroracs.lk
Use the following declarations and initializations to evaluate the Java expressions given in
questions 12 - 17. Assume that each expression is evaluated separately in the program.
int value1 = 2;
short num1 = 10;
double num2 = 100;
char ch = 'A'; // note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the questions 12 – 17.
12) System.out.println(value1*(num1+num2));
13) System.out.println(ch>value1);
15) System.out.println((int)(ch=ch++));
4
auroracs.lk
19) Consider the following program written in Java.
21) Select from among the following, relevant key words, which describe the object orientation feature
called data hiding.
22) Select from among the following, valid option(s), which can be considered as (a) class (es),
considering a school system.
23) Select from among the following, valid option(s), which can be considered as (an) object (s),
5
auroracs.lk
considering a school system.
Consider the following class declaration written in Java to answer questions 24 – 29.
24) Select from among the following, valid instance variable/s written in the program.
25) When the class was compiled, there were errors generated. The programmer noticed that get
methods were not written correctly. Select from among the following, valid get method signatures
to be introduced in the class declaration.
26) When the class was compiled, there were errors generated. The programmer noticed that set
methods were not written correctly. Select from among the following, valid set method signatures
to be introduced in the class declaration.
27) The programmer has identified another two programming statements causing confusion to read.
6
auroracs.lk
They are illustrated below.
count1=count1;
count2=count2;
Select from among the following, valid option(s) that can be used to modify the program to
increase the readability of the program.
28) After correcting all the errors and confusions which existed in the Ex21 class, one has written the
following program and compiled.
class DP{
public static void main(String args[]){
Ex21 ob= new Ex21;
count1=21;
System.out.println(count1);
}
}
When the program was Compiled, errors were generated. Select from among the following, correct
option(s) to substitute the programming statement(s) to avoid errors.
29) Consider the following program written in Java with new programming statements.
class DP{
public static void main(String args[]){
Ex21 ob= new Ex21();
ob.count2=80;
System.out.println(ob.count2);
}
}
When the program was compiled, errors were generated. Select from among the following correct
option(s) to avoid errors generated.
7
auroracs.lk
class What{
public void work(int value){
if(value>0){
System.out.print(value+"");
work(value - 1);
}
}
}
class Ex30{
public static void main(String args[]){
What ob= new What();
ob.work(3);
}
}
31) One has created the package having the name MyPack in the following path in windows
environment.
C:\MyPrograms\Java\MyPack
Select from among the following, valid option(s) to be included in the package path in the
CLASSPATH environment variable.
32) Select from among the following, correct option(s) to specify the class path in the command prompt
while interacting with a Java program.
When the program is executed an exception is generated. Select from among the following, the
exception that has been generated during the execution of the above program.
8
auroracs.lk
interface MyInterface{
public int value=9;
void walk();
void eat();
}
34) Select from among the following, valid statement(s) which can be used with the above programs.
35) When the above programs were compiled, compile time errors were generated. Select from among
the following valid option(s) which can cause the generation of those errors.
36) Select among the following, valid option(s) that can be considered unchecked exceptions defined in
the java.lang package.
enum Kingdoms {
Kotte, Polonnaruwa, Seethawaka, Kandy, Anuradhapura
}
class Ex34 {
public static void main(String args[])
{
Kingdoms ap;
ap = Kingdoms.valueOf("Kandy");
System.out.println(ap);
}
}
9
auroracs.lk
38) Consider the following programming statements written in Java.
Select from among the following, (a) valid option(s) which describe the Obj = 100; statement
methodically.
39) Select from among the following the package in which the Annotation interface is declared.
40) One can write generalized classes, interfaces or methods referring to the Object class in the Java
API. But that practice lead to programming problems and nowadays programmers use generics to
avoid such problems in a standard manner. Select from among the following, the programming
problem caused when the Object class is used and averted due to the proper usage of generics in
Java.
}
}
What would have been the output of the program when it was executed at the time of paper setting?
10
auroracs.lk
43) Select from among the following, valid interfaces defined in the Collection Framework of Java.
44) Select from among the following, valid method(s), which yield a boolean output related to the
Scanner class.
import java.io.*;
class Ex45 {
public static void main(String args[]) throws IOException
{
char c;
BufferedReader br = new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter characters, 'q' to quit.");
do {
c = (char) br.read();
System.out.print(c);
} while(c != 'q');
}
}
When the program was executed the following message was displayed in the command prompt.
ABCq
*******
11
auroracs.lk
Bachelor of Information Technology
Academic Year 2014/2015 – 1st Year Examination – Semester 2
IT2205 – Answers
Year 2015
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2205 - Programming I
26th July, 2014
(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
auroracs.lk
1) Consider the following program written in Java.
Select from among the following, key words that can be seen in the program.
2) Select from among the following, (a) possible identifier(s) that can be used in saving the
above Java file which is written in a notepad in Windows environment.
3) Select from among the following, the full name of the bytecode file which could be
generated, after compiling the above program successfully.
4) Select from among the following the correct option/s which show/s the output of the given
Java program.
Select from among the following, the name which can be given to that category of
notations.
2
auroracs.lk
6) Select from among the following, similar and (a) valid notation/s like the notation \n illustrated in
the above program.
8) What would the output of the program be, if the // notation which is marked in the program is
removed?
9) Select from among the following, similar and (a) valid notation/s like // which is/are used in Java.
10) One has replaced the following statement without changing the other statements shown in the
program.
System.out.println("value of num1"+num1);
System.out.print("value of num1"+num1);
11) Select from among the following, programming languages which has/ve a close relationship with
the development phase of the Java programming language.
3
auroracs.lk
12) Consider the following program written in Java.
System.out.println(value);
}
}
System.out.println(value);
}
}
System.out.println(value);
}
}
4
auroracs.lk
15) What would the output of the program be?
16) Consider the following programming statements written in a table where the column A is marked
with serial numbers. The column B shows the existing codes and in C new programming statements
are introduced to replace with the existing ones.
Select from among the following, the correct option/s to see the output of the program as 18.
Use the following declarations and initializations to evaluate the Java expressions given in
questions 17 - 21. Assume that each expression is evaluated separately in the program.
int value1 = 1;
float num1 = 5.0f;
byte num2 = 10;
char ch = 'A'; // note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the questions 17 – 21.
5
auroracs.lk
Consider the following class declaration written in Java to answer questions 22 – 28.
class X{
private int v1;
private int v2;
public X(){
System.out.println("Class X");
v1=1;
v2=2;
}
}
class Y extends X{
private int v3;
private static int v4;
public Y(){
System.out.println("Class Y");
v3=3;
v4=4;
}
}
22) Select from among the following, (a) valid option/s which can be considered as (an) instance
variable(s).
23) Select among the following, (a) valid option/s that can be considered as class variables.
24) Select from among the following, (a) valid object orientation feature/s which is/are related with the
word extends.
25) Consider the following program written in Java with the main method in it and saved in the same
folder where the above class declarations are saved.
}
}
What would the output of the program be when the program is executed?
6
auroracs.lk
26) Consider the following program with the main method noting the modifications to the program of
question no 25.
What would the output of the program be when the program is executed?
27) Consider the following program written in Java with the main method and new modifications.
System.out.println(obj1.v1);
}
}
28) Consider the following program written in Java with the main method and new modifications.
System.out.println(obj1.v4);
}
}
29) In Java, elements of an array are automatically initialized to some default value.
What is the default value for the elements of an array of integers?
7
auroracs.lk
30) Consider the following program written in Java.
Select from among the following, the number of times the phrase In the loop is printed in the
command prompt, when the program is executed.
8
auroracs.lk
33) Consider the following program written in Java.
class Access{
static int x;
void increment(){
x++;
}
}
class Ex15 {
public static void main(String args[])
{
Access obj1 = new Access();
Access obj2 = new Access();
obj1.x = 0;
obj1.increment();
obj2.increment();
}
}
class Ex16 {
public static void main (String args[]) {
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
}
After compiling the program successfully, the program was executed by issuing the following
command and related arguments.
35) Select from among the following, (a) valid method/s available in an Applet.
9
auroracs.lk
36) Consider the following program written in Java.
import java.awt.*;
import java.applet.*;
public class myApplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20, 20);
}
}
class Ex17 {
public static void main(String args[]) {
try {
System.out.print("Hello" + " " + 1 / 0);
}
finally {
System.out.print("World");
}
}
}
(a) Hello
(b) World
(c) WorldException in thread "main" java.lang.ArithmeticException: / by zero
(d) Exception in thread "main" java.lang.ArithmeticException: / by zero
(e) Hello 1/0
38) Select from among the following, (a) valid key word/s that can be used to manually throw an
exception.
10
auroracs.lk
40) Consider the following program written in Java.
class Pair<T>{
private T first;
private T second;
41) Select from among the following, (a) valid operation/s/ to concatenate two more string objects.
class Ex21 {
public static void main(String args[]) {
char chars[] = {'f', 'g', 'h'};
String s = new String(chars);
System.out.println(s);
}
}
11
auroracs.lk
43) Consider the following program written in Java.
class Ex22 {
public static void main(String args[])
{
String obj = "UNIVERSITY";
System.out.println(obj.charAt(3));
}
}
“In Java …................. package is used by compiler itself. So it does not need to be imported for
use”
Select from among the following correct option to fill the blank.
45) Select from among the following, the key word which can be used by a class to use an interface
which has been defined previously.
*******
12
auroracs.lk
Bachelor of Information Technology
Academic Year 2013/2014 – 1st Year Examination – Semester 2
IT2205– Answers
Year 2014
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2204 - Programming I
27th July, 2013
(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
auroracs.lk
1) Consider the following program written in Java.
Select from among the following, (a) suitable editor(s) that can be used to write the
program in the windows environments.
2) Select from among the following, (a) possible identifier(s) that can be used in naming
variable in Java.
3) Select from among the following, valid escape sequences used in Java.
Sigiriya
Nuwaraeliya
Select from among the following, (a) valid Java statement(s) which can be used to get those
lines printed.
5) One has saved a Java source file giving the following file name.
Student.java
Select from among the following, the class name which has been used in the file.
2
auroracs.lk
6) One has saved a Java source file giving the following name.
Customer.java
Select from among the following, the correct option(s) that can used to create a documentation of
the Customer class as web page.
7) Select from among the following, the valid option(s) which can be considered as comments in Java.
9) Select from among the following, (a) incorrect statement(s) related to number literals.
(a) int num1 = ‘A’; (b) float num 2= 4.5; (c) double num3= 100.8D;
(d) long num4 = 100L; (e) short num5 = 100S;
Consider the following program written in Java to answer questions 10 and 11.
10) Select from among the following, the valid option(s) that can be considered to prove that a Java is
an Object Oriented programming language.
11) Select from among the following, what can be considered as keywords in Java.
12) Select from among the following, the company where the Java language was initially developed.
3
auroracs.lk
Use the following declarations and initializations to evaluate the Java expressions given in
questions 13 - 17. Assume that each expression is evaluated separately in the program.
int num1 = 10,num2 = 15,num3 = 20;
char ch = 'A'; // note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the questions 13 – 17.
16) System.out.println( ch );
Consider the following pool of Java statements to answer questions 18 – 23. 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. Answers for each option of questions 18 to 23 is given as a list of identifier numbers
indicating the program statements.
4
auroracs.lk
16 double kilograms = pounds = 0.45359237;
17 for(int i = 0; i<= 3 ; i++)
18 for(int k = i ; k<= 3 ; k++)
19 for(int k = 0 ; k<= 3 ; k++)
20 System.out.print("* ");
21 System.out.println();
22 else if(average != 65.0)
23 if(average != 75.0)
24 double average = 67.0;
25 if(average >= 75.0)
26 System.out.println("B");
27 else if(average >= 65.0)
28 System.out.println("A");
29 else if(average >= 45.0)
30 System.out.println("C");
31 if(average => 75.0)
32 Else
33 else if(average => 65.0)
34 System.out.println("F");
35 else if(average => 45.0)
36 int area = base* (height/2);
37 System.out.println(area);
38 System.out.println("Area of Triangle is" + area);
39 int area = (base* height)/2;
40 int height = 12;
41 int base = 4;
42 System.out.println(i);
43 if(i%2==1)
44 if(i%2==0)
45 for(int i = 50; i <= 100 ; i++)
46 double kilograms = pounds * poundsToKg;
47 final double poundsToKg = 0.45359237;
48 System.out.println( "You entered: " + pounds + " pounds,
which is equivalent to " +kilograms+ " kilograms.");
49 double kilograms = pounds * 0.45359237;
50 double pounds = 100;
18) It is required to write a Java program to convert 100 pounds to kilograms considering that one
pound is equal to 0.45359237 kilogram.
The blank space in the following Java program is to be filled with the identifiers from the table.
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
5
auroracs.lk
19) Write a Java program to print all the odd numbers in the number range 50 to 100 horizontally in the
command prompt. One has to use the for control structure in writing the program and the name of
the control variable is i.
The blank space in the following Java program is to be filled with the identifiers from the table.
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
20) It is required to write a Java program to calculate an area of a triangle. Area of a triangle is
calculated using the following expression.
Area = ½ X b X h
Here b is the base of the triangle and h is the height of the triangle. Assume that the value of b is 4
and the value of h is 12.
The blank space in the following Java program is to be filled with the identifiers from the table.
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
21) It is required to write a Java program to evaluate the grade of a candidate using if statement. When
the average of the candidate is given according to the following table the grade has to be evaluated.
The blank space in the following Java program is to be filled with the identifiers from the table.
class GradeEvaluation{
public static void main(String args[]){ blank } }
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
6
auroracs.lk
22) Consider the following style below.
* * * *
* * * *
* * * *
* * * *
It is required to write a Java program to illustrate the given style using for control structures.
The blank space in the following Java program is to be filled with the identifiers in the table.
class Ex19{
public static void main(String args[]){ blank } }
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
* * * *
* * *
* *
*
It is required to write a Java program to illustrate the given style using for control structure.
The blank space in the following Java program is to be filled with the identifiers in the table.
class Ex20{
public static void main(String args[]){ blank } }
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
Consider the following program written in Java to answer questions 24 and 25.
class What
{
public static void main(String args[])
{
String s="malayalam";
int i;
int n=s.length();
String str="";
for(i=n-1;i>=0;i--)
str=str+s.charAt(i);
System.out.println(str);
}
}
7
auroracs.lk
24) What would the output of the program be?
25) Assume that one has changed the String s="malayalam"; statement as follows.
26) Select from among the following, (a) valid option(s) that can be considered as packages in Java.
“Environment variables can be set by right clicking blank icon and then selecting the properties
menu in the Windows Operating System”
Select from among the following the suitable option to substitute for the word blank in the above
statement.
8
auroracs.lk
29) Consider the following program written in Java.
9
auroracs.lk
32) Consider the following program written in Java.
for(int i : array[i])
System.out.print(i);
}
}
class Student{
private String name;
private int age;
public static String city;
Student(){ }
10
auroracs.lk
34) When considering the features of object orientation, which feature(s) is/are shown clearly in the
program?
35) Assume that the following program is also going to be written in the same notepad where the
Student class also has been written.
Select from among the following, a suitable file name to save the notepad.
36) Select from among the following, (a) variable(s) that can be considered as (an) instance variable(s).
37) Select from among the following, (a) variable(s) that can be considered as (a) class variable(s).
38) Select from among the following, (a) method(s) which can be considered as (a) constructor(s).
39) Assume that one has written the following statements within the main method in the DriverProgram
class.
11
auroracs.lk
40) Assume that one has written the following statements within the main method in the DriverProgram class.
Now one can see only these statements within the main method.
42) Select from among the following, valid types of exceptions that can be seen in Java.
44) Select from among the following the package in which the majority types that make up the
collection framework are defined.
45) The notations used for algorithm specification must conform to a specific set of criteria. Select from
among the following, the valid option(s) that can be considered as criteria for algorithm
specifications.
***********
12
auroracs.lk
Bachelor of Information Technology
Academic Year 2012/2013 – 1st Year Examination – Semester 2
IT2204 – Answers
Year 2013
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
IT2204 - Programming I
28th July, 2012
(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
auroracs.lk
1) Consider the following streams of bits noting the blank indicated as BLANK. A bitwise
operator which is denoted as BLANK applies to the input bit stream and then the output bit
stream is generated.
Select from among the following, the valid operator which has been applied for the above
operation.
2) Consider the following two numbers and bitwise operator indicated as BLANK. When the
operator was applied as number1 operator number2, the following output number has been
generated.
Select from among the following, valid operator which has been applied for the operation.
3) Consider the following number and bitwise operator indicated as BLANK. When the
operator was applied as number operator, the following output number has been generated.
Select from among the following, valid operator which has been applied for the operation.
4) Consider the following two numbers and bitwise operator indicated as BLANK. When the
operator was applied as number1 operator number 2, the following output number has been
generated.
Select from among the following, valid operator which has been applied for the operation.
2
auroracs.lk
5) Consider the following number and bitwise operator indicated as BLANK. When the
operator was applied as number operator, the following output number has been generated.
Select from among the following, valid operator which has been applied for the operation.
6) Select from among the following, valid operator(s) which can be categorized as unary type.
7) Select from among the following, valid option(s) which can be considered keywords in Java.
8) Select from among the following, the company which bought the ownership of Java in 2010.
System.out.println("Chamara Madushanka\n");
}
}
Select from among the following, incorrect statement(s) related to the given program.
(a) The given program can be written in any text editor and execute.
(b) White spaces which appear in the program are ignored by the compiler.
(c) main() method composed of the words namely main, String and args,
(d) \n represents single line comments in Java.
(e) Program should be saved by giving the file name Chamara Madushanka.
3
auroracs.lk
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 x = 0,y = 5,c = 4;
char ch = 'A'; // note that the ASCII value of A is 65
Select from among the given options, the correct output for each of the questions 10 – 14.
11) System.out.println(++ch);
12) System.out.println(ch++);
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. Answers for each option of questions 15 to 20 is given as a list of identifier numbers
indicating the program statements.
4
auroracs.lk
13 int p = 100;
14 float r = 0.05F;
15 float r = 5%; int p = “Rs.” +100;
16 int t = 1;
17 float i = p * r * t;
18 System.out.println("Rs."+ i);
19 int month = 2;
20 case 12:
case 1:
case 2:
21 case 3:
case 4:
case 5:
22 case 6:
case 7:
case 8:
23 case 9:
case 10:
case 11:
24 break;
25 switch ( month )
26 System.out.println("Winter");
27 System.out.println("Spring");
28 System.out.println("Summer");
29 System.out.println("Autumn");
30 while(t <= 10 )
31 System.out.println(t);
32 t++;
33 int num1 = 1; int num2 = 7;
34 if( num1 < num2)
35 System.out.println(num1);
36 System.out.println(num2);
37 double MarathonInKM = (miles + yards /
yardsDivisor) * kMConvertor;
38 final float kMConvertor = 1.609F;
39 final float yardsDivisor = 1760.0F;
40 float miles = 26.0F;
41 float yards = 385.0F;
42 double MarathonInKM = (miles + yards / 1760) *
1.609;
43 System.out.println(MarathonInKM);
44 else
45 while(t >= 10 )
46 if( num1 > num2)
47 int p = 100F;
48 float final kMConvertor = 1.609.0;
49 float final yardsDivisor = 1760.0;
50 System.out.println(“MarathonInKM”);
5
auroracs.lk
15) A marathon is a long-distance foot race with an official distance of 42.18596875 kilometers (or 26
miles 385 yards, or exactly 26 7⁄32 miles). Write a Java program to convert the distance of a
marathon in miles and yards to kilo meters and output the kilo meter value. Miles can be converted
to kilo meters by multiplying it with 1.609. Yards can be converted to miles by dividing it with
1760. Miles and yards can be assigned to variables with the names miles and yards respectively.
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
16) Write a Java program to calculate the area of a circle. The formula for calculating area of a circle is
= π • radius of the circle² (or PI * r²) assuming the PI value as 3.14. Consider that the radius as 5.
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
17) Write a Java program to calculate the simple interest. The simple interest calculation formula is
I=P * r * t. (I = interest, P = Principle value, r = rate and t represents time). For example, if one
invest Rs.100 (the Principal) at a 5% annual rate for 1 year then the simple interest calculation is:
Rs.5 = Rs.100 x 5 % x 1 yr. One has to use the same values and variable in the program.
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
6
auroracs.lk
18) Write a Java program print number series from 1 to 10 in the console using while loop. One has to
initialize the control variable with the name t equals to 1.
class Ex18{
public static void main(String args[]){ blank } }
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
19) Write a Java program using switch statement to determine which season a particular month is in if
the month is given as a number (1 for January, 2 for February etc.).
Months 12,1,2 Season =Winter
Months 3,4,5 Season =Spring
Months 6,7,8 Season =Summer
Months 9,10,11 Season =Autumn
Otherwise Bogus month
In the program there should be a variable having the name month with the value 2.
class Ex19{
public static void main(String args[]){ blank } }
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
(a) 19,25,1,20,24,26,24,21,24,27,24,22,24
(b) 13,14,15,17,18,19
(c) 19,25,1,20,24,26,24,21,24,27,24,22,24,28,24,23,24,29,24,2
(d) 19,25,1,20,26,24,21,27,24,22,28,24,23,29,24,2
(e) 13,14,15,17,18,20
20) Write a Java program to find the smallest number out of given two numbers. Numbers should be
whole numbers with names num1 and num2. Variable should be filled with literals 1 and 7. Using if
statement one has to write the program.
class Ex20{
public static void main(String args[]){ blank } }
Which of the following list(s) of identified numbers from the given Java program segments could
be selected for the blank space?
7
auroracs.lk
Consider the following paragraph to answer questions 21 – 22.
“In the early days of programming, the main preoccupation was with the correctness of the solution.
Precisely how that solution was derived was very much subordinate to the actual solution itself”
21) Select from among the following, the era which has been described by the given paragraph.
22) Select from among the following, the design tool(s) which was/were emerged during this period.
23) Select from among the following, which can be considered as guiding principles for the
decomposition of a program into sub-procedures.
24) Select from among the following, correct statement on Java programming language.
25) Select from among the following, the valid class/es which is/are bundled with java.lang package in
Java.
26) Consider the following output which has been generated when a program was executed.
java.lang.ArrayIndexOutOfBoundsException: 3
Select from among the following, possible option(s), which can be (a) candidate(s) to generate such
an output.
8
auroracs.lk
Consider the following diagram to answer questions 26 – 35 noting identifiers given for each
box. Assume that the diagram illustrates a hierarchy of classes and their relationships.
B C D E
27) Select from among the following, generic names in general, which can be given to identify the class
having the identifier A.
28) Select from among the following, generic names which can be given to identify the class having the
identifier C when consider the relationship with the class A.
29) Select from among the following, legal class declaration(s) which can be expected.
30) Select from among the following, valid relationship(s) in Java that are shown in the diagram.
31) When consider the features of object orientation, which feature(s) is/are shown clearly in the
diagram?
32) Select from among the following, suitable example(s) which can be given for class A.
33) Select from among the following, suitable example(s) which can be given for class B.
9
auroracs.lk
34) Consider that the class A has been applied with the modifier abstract in a class declaration. Select
from among the following, option(s) which are not allowed.
35) Consider that the class C has been applied with the modifier final in a class declaration. Select from
among the following, option(s) which are not allowed.
B ()
B(int a, int b)
Select from among the following, object orientation feature(s) used in the above class.
37) Select from among the following, the common name which can be given for method overloading
and method overriding as a whole.
38) Select from among the following, the keywords which can be used implement in Java the object
orientation feature called information hiding.
39) Consider the following table with some random values. One needs to keep those values in a
computer to process them.
2 5 6
6 17 2
Select from among the following, valid way(s) of keeping data in a computer by using Java.
10
auroracs.lk
40) Consider the following skeleton of program noting the blanks indicated as BLANK1, BLANK2
and BLANK3.
try
{
BLANK1
}catch(BLANK2)
{
BLANK3
}
Then consider the following candidate phrases which can be used to fill those blanks.
I protected code
II Exception object
III Catch block
IV Stream buffer
Select from among the following, (a) valid option(s) which can be consider for filling the blanks.
41) Select from among the following, valid classes which comes with java.util package supporting set
collection.
43) Select from among the following, standard streams that are accessible through members of System
class in Java.
11
auroracs.lk
44) Read the following statement which explains one of the subclasses of FilterInputStream class.
Select from among the following, the sub class which matches with the above description.
*********
12
auroracs.lk
Bachelor of Information Technology
Academic Year 2011/2012 – 1st Year Examination – Semester 2
IT2204 – Programming I - Answers
Year 2012
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
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.
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
Bachelor of Information Technology
Academic Year 2010/2011 – 1st Year Examination – Semester 2
IT2204 – Programming I - Answers
Year 2011
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk
UNIVERSITY OF COLOMBO, SRI LANKA
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
27) Consider the following segment of a program written in Java.
System.out.println(num1+" "+num2);
9
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
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
auroracs.lk
Bachelor of Information Technology
Academic Year 2009/2010 – 1st Year Examination – Semester 2
IT2204 – Programming I - Answers
Year 2010
1 a b c d e 21 a b c d e 41 a b c d e
2 a b c d e 22 a b c d e 42 a b c d e
3 a b c d e 23 a b c d e 43 a b c d e
4 a b c d e 24 a b c d e 44 a b c d e
5 a b c d e 25 a b c d e 45 a b c d e
6 a b c d e 26 a b c d e 46 a b c d e
7 a b c d e 27 a b c d e 47 a b c d e
8 a b c d e 28 a b c d e 48 a b c d e
9 a b c d e 29 a b c d e 49 a b c d e
10 a b c d e 30 a b c d e 50 a b c d e
11 a b c d e 31 a b c d e 51 a b c d e
12 a b c d e 32 a b c d e 52 a b c d e
13 a b c d e 33 a b c d e 53 a b c d e
14 a b c d e 34 a b c d e 54 a b c d e
15 a b c d e 35 a b c d e 55 a b c d e
16 a b c d e 36 a b c d e 56 a b c d e
17 a b c d e 37 a b c d e 57 a b c d e
18 a b c d e 38 a b c d e 58 a b c d e
19 a b c d e 39 a b c d e 59 a b c d e
20 a b c d e 40 a b c d e 60 a b c d e
http://www.ucsc.lk http://www.bit.lk
auroracs.lk