BE Computer Engineering (Pokhara University) Advanced Programming with Java (PU, CMP 228) Question Paper 2078
This is the official BE Computer Engineering (Pokhara University) Advanced Programming with Java (PU, CMP 228) question paper for 2078, as set in the regular annual examination. It carries 100 full marks and a time allowance of 180 minutes, across 11 questions. On Kekkei you can attempt this Advanced Programming with Java (PU, CMP 228) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BE Computer Engineering (Pokhara University) Advanced Programming with Java (PU, CMP 228) exam or solving previous years' question papers, this 2078 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all / any as specified.
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)
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)
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)
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)
Section B: Short Answer Questions
Attempt all / any as specified.
(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)
(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)
(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)
(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)
(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)
(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)
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