UNIVERSITY EXAMINATIONS: 2014/2015
ORDINARY EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY
BIT2204 JAVA PROGRAMMING
DATE: DECEMBER, 2014 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO
QUESTION ONE
a) Briefly explain the meaning following programming concepts.
i) Java compiler (2 Marks)
ii) Java Interpreter (2 Marks)
iii)Java runtime environment (JRE) (2 Marks)
b) Consider the following variable names and determine whether they illegal or legal
identifiers of variables in java programming. Justify your answer for each case.
i) Storing_place (2 Marks)
ii) _studentName (2 Marks)
iii) :-staffmember (2 Marks)
iv) question? (2 Marks)
c) Describe the meaning of the following concepts in the context of java
programming and write a sample java code that demonstrates its implementation.
i) Variable declaration (2 Marks)
ii)Variable initialization (2 Marks)
d) Write comments that explains the following java code. (4 Marks)
int position;
position = 5 + 3 * 3;
System.out.println(position +2);
System.out.println(2 * position);
e) Write comments that explains the following java code [3 Marks]
for ( int i = 0; i < maxID; i++ )
{
if ( userID[i] != -1 )
continue;
System.out.print(“UserID”+i+“:”+userID);
}
g) 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 “welcome to kca University”.
g) Explain the meaning of the term ‘byte code’ in the context of java programming
[1mark]
QUESTION TWO
a) Define what is an array [2 Marks]
b) Describe any three characteristics of an array [3 Marks]
c) Write java code that declares an array and puts a value into the array [2 Marks]
d) Explain the steps that a java program of compiling and running a java program.
[4 Marks]
e) Using one statement for each and some explanation, illustrate how the following string
functions are implemented. Write an example java code to illustrate how each function
can be used. [6 Marks]
i) concat
ii) charAt
iii) indexOf
h) Write a sample java code that convert the following alphabets to capital letters.
[2 Marks]
“Welcome! to java programming:”
f). Briefly explain importance of Java virtual machine (JVM) [1 Mark]
QUESTION THREE
a) Write a java program that displays student IDs and first and last names of employees.
[4
Marks]
b) State and explain three main control structures that are used in structured
programming.. Write an sample java code that implements each control structure
[6
Marks]
c) Explain the TWO types of errors encountered in java [4 Marks]
c) Write a java program that implements the following Pseudocode. [6 Marks]
if student’s grade is greater than or equal to 70
Print “A”
else
if student’s grade is greater than or equal to 60
Print “B”
else
if student’s grade is greater than or equal to 50
Print “C”
else
if student’s grade is greater than or equal to 40
Print “D”
else
Print “F”
QUESTION FOUR
a) Define the meaning of the term ‘comment’. Explain three sections of a program
where comments can be used. (4 Marks)
b) Write sample java code that demonstrate usage of comment. (2 Marks)
d) Describe the importance of a constructor. Write a java code that demonstrates
implementation of a constructor. ( 4 Marks)
e) State and explain any four types of java METHODS. (4 Marks)
f) 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
QUESTION FIVE
a) 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 idno, name,
occupation and then display all the values entered by the user (6 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);
}
}
d) Describe the term Type qualifier and briefly explain four examples of type
qualifiers. (6 Marks)
e) Explain the following java features
i) Java Virtual Machine (2 Marks)
ii) package (2 mark)