Savitribai Phule Pune University
M.C.A. Semester II - Live Examination
Subject: Java Programming
Time: 2 Hours Max. Marks: 50
Q1) Solve any two of the following: (2 x 5 = 10 Marks)
a) Define a class Product with data members id, name, and price. Write a Java program to create and display
product details using a constructor. [5]
b) Explain method overriding with an example. Create a base class Animal and subclass Dog that overrides
the sound() method. [5]
c) What is abstraction in Java? Explain how it is achieved using abstract classes. Give one real-life example.
[5]
Q2) Solve any two of the following: (2 x 5 = 10 Marks)
a) Write a Java program to demonstrate creation and traversal of a HashSet containing names of cities. [5]
b) Explain inter-thread communication in Java. Write a program using wait() and notify() methods. [5]
c) Define and explain the use of user-defined exceptions. Write a program to throw InvalidAgeException if
age is less than 18. [5]
Q3) Solve any one of the following: (1 x 10 = 10 Marks)
a) Write a Java Servlet to accept username and password from a login form and validate the input. If correct,
display "Welcome [username]", otherwise show an error message. [10]
b) Explain the use of HTTP Servlet Request and Response objects. Demonstrate how parameters are
retrieved using getParameter() with code example. [10]
Q4) Solve any one of the following: (1 x 10 = 10 Marks)
a) What are Cookies in Java Servlet? Write a servlet to store user's preferred theme color in a cookie and
display it on the next visit. [10]
b) Develop a Java Servlet to count and display the number of times a user has visited a page using Session
Tracking. [10]
Q5) Attempt any five short answers: (5 x 2 = 10 Marks)
a) State any two advantages of Java
Savitribai Phule Pune University
M.C.A. Semester II - Live Examination
Subject: Java Programming
Time: 2 Hours Max. Marks: 50
b) What is the role of the this keyword?
c) Give syntax and use of static block
d) What is the difference between ArrayList and Vector?
e) Define garbage collection
f) What is the use of finally block in exception handling?