UNIVERSITY EXAMINATIONS: 2011/2012
SECOND YEAR EXAMINATION FOR THE BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
BIT 2204A JAVA PROGRAMMING
DATE: AUGUST, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO
QUESTION ONE
a. Explain the steps that a java program of compiling and running a java program
[4 Marks]
b. Write java code statements to accomplish the following [4 Marks]
i) If the variable “Num” is not equal to 7, print “value not 7”.
ii) Print the message “this is a java program”.
c. Using one statement for each and some explanation, illustrate how the following string
functions are implemented [6 Marks]
i) Substring
ii) indexOf
iii) concat
d. Computer programs are very closely tied to the specific hardware and operating system
they run. A Windows program will not run on a computer that only runs DOS. A Mac
application can’t run on a UNIX workstation. VMS code can’t be executed on an IBM
mainframe, and so on. How does java resolve this platform problem? [2 Marks]
e. Write a java program that displays employee IDs and first and last names of
employees. [4 Marks]
f. Define the term decision control structures [2 Marks]
g. Explain the TWO types of errors encountered in java [4 Marks]
h. Convert the following Pseudocode to java switch structure [4 Marks]
if student’s grade is greater than or equal to 90
Print “A”
else
if student’s grade is greater than or equal to 80
Print “B”
else
if student’s grade is greater than or equal to 70
Print “C”
else
if student’s grade is greater than or equal to 60
Print “D”
else
Print “F”
QUESTION TWO
a) Explain the properties of a constructor [4 Marks]
b) Outline three characteristics of java METHODS [3 Marks]
c) In your own understanding, explain how to pass variables in methods .Giving
examples [6 Marks]
d) Explain the purpose of the following codes
i) BufferedReader dataIn = new BufferedReader(new
InputStreamReader( System.in) );
[2 Marks]
ii) try{
name = dataIn.readLine();
}catch( IOException e ){
System.out.println(“Error!”);
} [2 Marks]
e) Explain the scope of a variable [3 Marks]
QUESTION THREE
a) Define the meaning of the term ‘comment’. Explain three sections of a program
where comments can be used [4 Marks]
b) Explain the operation of the following program and predict its output [4 Marks]
Public class example
{
public static void main(String[] args)
{
String firstName = “Amr”;
String middleName = “Ahmed”;
String lastName = “Al-Ghamdi”;
int age = 20;
String initials = firstName.substring(0,1) +
middleName.substring(0,1) +
lastName.substring(0,1);
String password = initials.toLowerCase() + age;
System.out.println(“Your Password = ” + password);
}
}
c)What is the purpose of the following keywords as used Java Programming? Give
examples to support your answer. [6 Marks]
i. extends
ii. exception
iii. throws
d)Write a class named employee that instantiates a kcau_emp object from the class you
created. Prompt the a user to enter personal details such as id no, name, occupation and
then display all the values entered by the us [6 Marks]
QUESTION FOUR
a) Using examples describe the different types of access modifiers used in java
programming [12 Marks]
b) Explain the importance of interface as applied in java programming [4 Marks]
c) Explain the following java features
i. Java Virtual Machine [2 Marks]
ii. Garbage Collection [2 Marks]
QUESTION FIVE
a) Describe with examples the syntax of the following java programming terms
i) Package [2 Marks]
ii) Polymorphism [2 Marks]
b) Define the term ‘multiple inheritance’. Describe how multiple Inheritance can be
achieved in java programming language. Give the syntax used to implement
concept. [4 Marks]
c) Consider the following java code instructions and explain the purpose of the
single line statements appearing in bold. [4 Marks]
private static void createAndShowGUI()
{
JFrame frame = new JFrame(“Hi..”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(“Hello World”);
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
d) Briefly explain importance of using ‘LayoutManager’ when developing
programs using n swing with graphical interface. Write a sample java code
utilizing LayoutManager. [4 Marks]
e) Differentiate between over ridding and overloading as used in objected oriented
programming languages such as java. Give an example java code implementing
for each case. [4 Marks]