IT1406 - Introduction To Programming: University of Colombo, Sri Lanka
IT1406 - Introduction To Programming: University of Colombo, Sri Lanka
IT1406 - Introduction To Programming: University of Colombo, Sri Lanka
(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