CSC419 · TU past paper
Advanced Java Programming 2077 question paper
The complete TU 2077 exam paper for Advanced Java Programming (CSC419), all 13 questions with solved model answers written to the mark scheme.
Tap a question to open its answer.
- Q1.10 marksIntroduction of RMI, Architecture of RMI, HideAnswer
What is the significance of stub and skeleton in RMI? Create a RMI application such that a client sends an Integer number to the server and the server return the factorial value of that integer. Give a clear specification for every step.[10]
- Q2.10 marksDDL and DML Operations using Java, PrepareHideAnswer
You are hired by a reputed software company which is going to design an application for 'Movie Rental System'. Your responsibility is to design a schema named MRS and create a table named Movie(id, Title, Genre, Language, Length). Write a program to design a GUI form to take input for this table and insert the data into table after clicking the OK button.[10]
- Q3.10 marksWorking with FilesHideAnswer
Describe the responsibility of Serializable interface. Write a program to read an input string from the user and write the vowels of that string in VOWEL.TXT and consonants in CONSONANT.TXT.[10]
- Q4.5 marksNumericalArraysHideAnswer
A non-empty array A of length n is called an array of all possibilities if it contains all numbers between 0 and A.length-1 inclusive. Write a method named isAllPossibilities that accepts an integer array and returns 1 if the array is an array of all possibilities, otherwise it returns 0. [5]
isAllPossibilitiesMethodGiven data
- Input: a non-empty integer array
Aof lengthn. - Condition:
Amust contain all integers from0ton-1inclusive. - Output: return
1if the condition holds, otherwise0.
(No specific test arrays are mandated by the question; behaviour must be general.)
Concept
An array of length
nqualifies if and only if it is a permutation of ${0, 1, 2, \dots, n-1}$. Since the array has exactlynslots and must holdndistinct values all in range $[0, n-1]$, it suffices to check:- every element lies in $[0, n-1]$, and
- no value repeats.
If both hold across
nelements, each of thendistinct values must appear exactly once (pigeonhole principle).Java Code
public static int isAllPossibilities(int[] A) { int n = A.length; boolean[] visited = new boolean[n]; // track which numbers seen for (int i = 0; i < n; i++) { // out of range check if (A[i] < 0 || A[i] >= n) { return 0; } // duplicate check if (visited[A[i]]) { return 0; } visited[A[i]] = true; } return 1; // all values 0..n-1 present exactly once }Dry Run
Array n Result Reason {0,1,2,3}4 1Permutation of 0..3 {3,0,2,1}4 1Same set, reordered {1,2,3,4}4 04 >= nout of range{0,0,1,2}4 0Duplicate 0detected{-1,0,1,2}4 0-1 < 0out of rangeComplexity
- Time: $O(n)$ - single pass.
- Space: $O(n)$ - visited array.
- Input: a non-empty integer array
- Q5.5 marksEvent Handling Concept, Listener InterfaceHideAnswer
Define event delegation model. Why do we need adapter class in event handling? [5]
Event Delegation Model and Adapter Classes in Java
Event Delegation Model (2 marks)
The Event Delegation Model is the standard event handling mechanism used in Java AWT and Swing. In this model, the task of handling an event is delegated from the source (component that generates the event) to a separate object called the listener (or handler).
Key Components:
Component Role Event Source The UI component that generates the event (e.g., Button, TextField) Event Object Encapsulates information about the event (e.g., ActionEvent, KeyEvent) Event Listener The object that receives and handles the event How it Works:
User Action --> Event Source --> Event Object --> Event Listener --> Handler Method (e.g., click) (Button) (ActionEvent) (ActionListener) (actionPerformed())Steps in Event Delegation:
- Implement the appropriate listener interface (e.g.,
ActionListener,KeyListener) - Register the listener with the source using
addXxxListener(this) - Override the required handler method(s)
Example (from notes):
class AEvent extends Frame implements ActionListener { Button b = new Button("click me"); b.addActionListener(this); // Step 2: Register listener public void actionPerformed(ActionEvent e) { // Step 3: Handle event tf.setText("Welcome"); } }
Why We Need Adapter Classes (3 marks)
The Problem:
Some listener interfaces in Java contain multiple abstract methods that must ALL be overridden when implementing the interface, even if we only need one or two of them.
For example,
KeyListenerhas 3 methods:keyPressed(KeyEvent e)keyReleased(KeyEvent e)keyTyped(KeyEvent e)
If we implement
KeyListenerdirectly, we are forced to provide the body of all 3 methods, even if we only care aboutkeyPressed. This leads to unnecessary, cluttered code:// Without Adapter - must override ALL methods (messy) class MyClass extends Frame implements KeyListener { public void keyPressed(KeyEvent e) { /* actual code */ } public void keyReleased(KeyEvent e) { /* empty - not needed */ } public void keyTyped(KeyEvent e) { /* empty - not needed */ } }The Solution - Adapter Classes:
An Adapter class is a pre-built class that implements a listener interface with empty method bodies. We simply extend the adapter class and override only the methods we need.
// With Adapter - override ONLY what is needed (clean) class KeyChecker extends KeyAdapter { @Override public void keyPressed(KeyEvent e) { // only this method is needed } // No need to write keyReleased() or keyTyped() }MouseAdapter Example (from notes):
public class MouseAdapterExample extends MouseAdapter { // Only mouseClicked() is overridden - no other methods needed public void mouseClicked(MouseEvent e) { Graphics g = f.getGraphics(); g.setColor(Color.BLUE); g.fillOval(e.getX(), e.getY(), 30, 30); } }Common Adapter Classes:
Adapter Class Corresponding Listener Interface KeyAdapterKeyListenerMouseAdapterMouseListenerWindowAdapterWindowListenerFocusAdapterFocusListenerSummary:
Adapter classes reduce code complexity by providing default (empty) implementations of all methods in a listener interface, allowing the programmer to override only the required methods.
- Implement the appropriate listener interface (e.g.,
- Q6.5 marksLayout ManagementHideAnswer
What is the task of Layout manager? Describe about default layout manager. [5]
- Q7.5 marksHandling ExceptionsHideAnswer
When does the finally block is mandatory in while handling exception? Describe with a suitable scenario. [5]
- Q8.5 marksWeb Container, Introduction to Servlets, LHideAnswer
Explain the life cycle of a servlet. [5]
- Q9.5 marksPackagesHideAnswer
What is the task of manifest file? Write the procedure to create it. [5]
- Q10.5 marksInheritanceHideAnswer
Why multiple inheritance is not allowed in Java using classes? Give an example. [5]
- Q11.5 marksServlet vs JSP, JSP Access Model, JSP SyntHideAnswer
How forms can be created and processed using JSP? Make it clear with your own assumptions. [5]
- Q12.5 marksConcurrencyHideAnswer
Why synchronization is essential in multithreading? Describe. [5]
- Q13.5 marksIntroduction to Java Web FrameworksHideAnswer
Write short notes on: a. JAVA beans and JAR file b. MVC design pattern [2.5+2.5]