BIT 2204A JAVA PROGRAMMING KCA Past Paper

UNIVERSITY EXAMINATIONS: 2012/2013
SECOND YEAR EXAMINATION FOR THE BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
BIT 2204A JAVA PROGRAMMING
DATE: DECEMBER, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Distinguish between java compiler and java virtual machine [2 Marks]
b) Write java code statements to accomplish the following [4 Marks]
If the variable “results” has a value is equal or greater than 50 , display “passed”.
Otherwise display “fail”.
c) Display message “welcome to java program”.
d) Write a java program that displays employee IDs and first and last names of
employees. [4 Marks]
e) Explain the meaning of the following keywords [2 Marks]
i. Final
ii. New
f) Describe with examples the syntax of the following program flow controls and advice
when to use them [4 Marks]
i. While
ii. Do while
g) 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”
h) Using one statement for each and some explanation, illustrate how the following
string functions are implemented [6 Marks]
i. Substring
ii. Indexof
iii. Concat
h. 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]
i) Distinguish between static and non static methods in the context of java programming
[2 Marks]
QUESTION TWO
a) Briefly explain the meaning of the following terms as used in java programming.
Give java code example for each case [6 Marks]
i. Class
ii. Variable
iii. Syntax error:
b) Define what you understand by JVM and explain its importance in Java Programming
[4 Marks]
c) Describe with explanation the structure of a Java program [4 Marks]
d) Write a well commented java program that prints the following output. [4 Marks]
i. Age is 20
ii. Name is peter
iii. Course is Bscit
e) Explain the meaning of the term „array‟. Give one example of a java code for creating
an array [2 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 idno, name, occupation
and then display all the values entered by the user. [6 Marks]
QUESTION FOUR
a) Explain the meaning of the following keywords
i. Final [2 Marks]
ii. Encapsulation [2 Marks]
iii) Inheritance [2 Marks]
b) Describe the meaning of the term „constructor‟. Write a sample java code that
implements a constructor [4 Marks]
c) Describe the following selection escape statements
i. Continue [2 Marks]
ii. Break [2 Marks]
d) Define the term „applet‟. Write an example code of an applet displaying the string
„hello world‟. [4 Marks]
e) Describe the key word „import‟ as used in java. Write a single line java code
illustrating how „import‟ can be used in java programming [2 Marks]
QUESTION FIVE
a) Briefly explain the meaning of the term „ polymorphism‟ as used in java
programming [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]
f) Describe the term interface as used in java programming language [2 Marks]

(Visited 144 times, 1 visits today)
Share this:

Written by