Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long12 marks

Object-oriented programming forms the foundation of Java.

(a) Differentiate between method overloading and method overriding with suitable code examples. (5)

(b) Explain the four pillars of OOP (encapsulation, inheritance, polymorphism, and abstraction). Write a Java program that defines an abstract class Shape with an abstract method area(), and two subclasses Circle and Rectangle that provide their own implementations. Demonstrate runtime polymorphism using a reference of type Shape. (7)

java-basicsoopinheritance
2long14 marks

Multithreading allows concurrent execution of two or more parts of a program.

(a) Describe the life cycle of a thread in Java with a neat state-transition diagram. (4)

(b) Compare the two ways of creating threads in Java: extending the Thread class versus implementing the Runnable interface. State which one you would prefer and why. (4)

(c) What is a race condition? Write a Java program that simulates a shared bank account being accessed by multiple threads, and use the synchronized keyword to prevent inconsistent withdrawals. (6)

multithreadingsynchronization
3long12 marks

JDBC provides an API for connecting Java applications to relational databases.

(a) Explain the steps involved in connecting a Java program to a database using JDBC. (4)

(b) Differentiate between Statement, PreparedStatement, and CallableStatement. Why is PreparedStatement preferred to prevent SQL injection? (4)

(c) Write a complete JDBC program that connects to a Student(roll, name, marks) table in MySQL, inserts a new record, and then retrieves and displays all records whose marks are greater than 60. (4)

jdbcdatabase-connectivity
4long10 marks

Swing is used to build platform-independent graphical user interfaces in Java.

(a) Explain the delegation event model in Java with the roles of event source, event listener, and event object. (4)

(b) Design a Swing-based simple login form containing a username field, a password field, and a Login button. When the button is clicked, the program should display "Login Successful" if the username is admin and password is 1234; otherwise display "Invalid Credentials". Write the complete code including the appropriate event handler. (6)

guiswingevent-handling
B

Section B: Short Answer Questions

Attempt all / any as specified.

7 questions
5short8 marks

(a) Differentiate between checked and unchecked exceptions with one example of each. (3)

(b) Explain the use of the try, catch, finally, and throw keywords. Write a program that defines a custom exception InvalidAgeException and throws it when an entered age is less than 18. (5)

exception-handling
6short8 marks

(a) Distinguish between ArrayList and LinkedList in terms of internal structure and performance. (3)

(b) Write a Java program using the Collections framework that stores a list of student names in an ArrayList, removes duplicates by converting it to a HashSet, and finally prints the unique names in sorted order using a TreeSet. (5)

collections-frameworkgenerics
7short8 marks

(a) Differentiate between TCP and UDP communication in Java. Which classes are used for each? (3)

(b) Write a simple client-server program using ServerSocket and Socket where the client sends a message to the server and the server echoes the message back to the client. (5)

networkingsockets
8short6 marks

(a) Explain the servlet life cycle with the role of the init(), service(), and destroy() methods. (3)

(b) Differentiate between a Servlet and a JSP. State two advantages of JSP over servlets. (3)

servletsjsp
9short6 marks

(a) Differentiate between String, StringBuffer, and StringBuilder with respect to mutability and thread safety. (3)

(b) Write a Java program that accepts a string from the user and checks whether it is a palindrome without using any built-in reverse method. (3)

java-basicsstrings
10short6 marks

(a) What is inter-thread communication? Explain the role of the wait(), notify(), and notifyAll() methods. (3)

(b) Briefly describe the producer-consumer problem and how it can be solved in Java. (3)

multithreadinginter-thread-communication
11short6 marks

Write short notes on any two of the following: (3+3)

(a) Layout managers in Swing (FlowLayout, BorderLayout, GridLayout)

(b) Difference between AWT and Swing

(c) Stage, Scene, and Node hierarchy in JavaFX

guijavafxlayout-managers