Subject Code: CSF203 Printed Page 1 of 2
DIT UNIVERSITY, DEHRADUN
[Link] (CSE) : END TERM EXAMINATION, ODD SEM 2023-24 (SEM III)
Roll No.
Introduction to Java Programming
Time: 3 Hours Total Marks: 100
Note: All questions are compulsory. No student is allowed to leave the examination hall before the completion of the exam.
______________________________________________________________________________________________________
Q.1) Attempt all Parts :
(a) Explain the principles of exception propagation in Java. Describe how exceptions are passed up the
call stack and how they can be caught and handled at various levels of the program.
(b) What is the difference between array and vector?
(c) Explain the usage of enumerated data type? Give examples.
(d) Define type conversion, type casting with an example?
[4 x 5= 20]
Q.2) Attempt all Parts :
(a) Discuss the hierarchy of exception classes in Java. Explain how the ‘Throwable` class, `Exception`
class, and `RuntimeException` class are related, and provide examples of each.
(b) What is the key difference between a one-dimensional array and a two-dimensional array in Java?
How do you initialize a two-dimensional array in Java?
(c) Write a runtime polymorphism program in Java by using interface reference variable.
(d) What is meant by re-throwing exception? Discuss a suitable scenario for this.
[4 x 5= 20]
Q.3) Attempt any two parts :
(a) Write a program to perform Stack operation using proper class and methods
.
(b) Create a Java program that models a simple banking system. Define classes for Bank, Account, and
Customer. Implement methods for deposit, withdrawal, and account management. Show how
inheritance and encapsulation are used in this program.
(c) Describe the use of the super keyword when invoking an overridden method. What does it
achieve, and when is it necessary?
[2 x 10= 20]
Q.4) Attempt any two parts :
(a) Write a Java program to print the following output:
11111
2222
333
44
5
(b) Design a Java class hierarchy with multiple levels of inheritance. Explore the use of access modifiers
like public, protected, and private in your methods. Discuss the implications of these modifiers on
method overriding.
(c) Write a Java program to implement following inheritance:
Subject Code: CSF203 Printed Page 2 of 2
[2 x 10= 20]
Q.5) Attempt any two parts :
(a) Compare StringBuffer and String class. Write a java program to implement following functions of
String Class (i) Calculate length of string (ii) Compare between strings (iii) Concatenating strings.
(b) What is binary search, and why is it more efficient than linear search for sorted arrays? Write a Java
program to perform binary search on a sorted array.
(c) Write a Java program that includes the following:
1. Account Class: Create an `Account` class with instance variables `accountNumber`,
`accountHolder`, `balance`, and a constant `MIN_BALANCE` representing the minimum allowed
balance. Include a method `withdraw (double amount)` that throws the
`InsufficientFundsException` if the withdrawal would result in a balance below the minimum
threshold.
2. Custom Exception Class: Define the `InsufficientFundsException` class as a custom exception
that extends the `Exception` class. Include a constructor that takes a message parameter to
provide a meaningful error message when the exception is thrown.
3. Main Class: Write a `Main` class that demonstrates the usage of the `Account` class and the
custom exception. In the `Main` class, create an `Account` object, set an initial balance, and
attempt to make withdrawals that exceed the balance, leading to the custom exception being
thrown. Handle the exception and provide appropriate error messages.
[2 x 10= 20]
-----END OF PAPER ----