Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long15 marks

(a) Explain the four fundamental principles of Object-Oriented Programming (encapsulation, inheritance, polymorphism and abstraction) and discuss how each is supported by features of the Java language. (7)

(b) Distinguish between method overloading and method overriding in Java with suitable code examples. Explain the role of the super and this keywords and the use of the final modifier when applied to a method and a class. (8)

java-basicsoopinheritance
2long15 marks

(a) Describe the life cycle of a thread in Java with a neat labelled state-transition diagram, explaining the transitions between the new, runnable, running, blocked/waiting and dead states. (6)

(b) What is meant by thread synchronization? Write a complete multithreaded Java program that implements the classic producer–consumer problem using wait() and notify() on a shared bounded buffer, and explain how your solution avoids race conditions. (9)

multithreadingsynchronizationconcurrency
3long14 marks

(a) List and explain the four types of JDBC drivers, stating one advantage and one disadvantage of each. (6)

(b) Write a complete Java program that connects to a MySQL database, retrieves all records from an Employee(empId, name, salary) table using a PreparedStatement, and prints them. Clearly identify the standard steps of JDBC connectivity used in your program and explain the difference between Statement and PreparedStatement. (8)

jdbcdatabase-connectivity
4long12 marks

(a) Explain the Java event delegation model. Describe the roles of the event source, event object and event listener with reference to handling a button click in Swing. (5)

(b) Design and write a Swing-based GUI application for a simple login form containing two text fields (username and password) and a Login button. When the button is clicked, the program should display a message dialog indicating whether the entered credentials match a hard-coded valid pair. Use an appropriate layout manager. (7)

swingguievent-handling
B

Section B: Short Answer Questions

Attempt all / any as specified.

8 questions
5short8 marks

Differentiate between checked and unchecked exceptions in Java. Explain the use of the try, catch, finally, throw and throws constructs, and write a short program that defines and throws a user-defined (custom) exception.

exception-handling
6short8 marks

Describe the Java Collections Framework hierarchy. Compare ArrayList vs LinkedList and HashMap vs TreeMap in terms of internal structure and performance. Write a short code snippet that uses an Iterator to traverse a generic List<String>.

collections-frameworkgenerics
7short8 marks

Explain the difference between TCP and UDP communication in Java. Write a simple TCP client–server program (server and client code) in which the server echoes back any message sent by the client, using the ServerSocket and Socket classes.

networkingsockets
8short8 marks

Explain the life cycle of a servlet, describing the purpose of the init(), service() and destroy() methods. How does a servlet differ from a JSP page, and at what point is a JSP converted into a servlet?

servletsjspweb
9short6 marks

Differentiate between the String, StringBuffer and StringBuilder classes in Java with respect to mutability and thread safety. Explain why String is said to be immutable and what is meant by the string constant pool.

java-basicsstrings
10short6 marks

Compare the two ways of creating a thread in Java: extending the Thread class versus implementing the Runnable interface. State which approach is generally preferred and justify your answer with an example signature.

multithreadingconcurrency
11short6 marks

Explain the role of the ResultSet interface in JDBC. Differentiate between a forward-only and a scrollable result set, and write code to update a column value through an updatable ResultSet.

jdbcresultset
12short4 marks

What is the difference between an abstract class and an interface in Java? With the introduction of default and static methods, explain how interfaces have evolved since Java 8.

oopinterfaces