CSC419 · TU past paper
Advanced Java Programming 2076 question paper
The complete TU 2076 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.
- 110 marksHandling ExceptionsHideAnswer
What is exception handling? Discuss the use of each keyword (try, catch, throw, throws and finally) with suitable Java program.[10]
Exception handling is a mechanism in Java that allows a program to handle runtime errors (exceptional conditions) in a controlled manner, so that the normal flow of the program can be maintained and the program does not crash abruptly. W...
- 210 marksHandling Action Events, Key Events, Focus HideAnswer
Write a Java program to find the sum of two numbers using swing components. Use text fields for input and output. Your program displays output if you press any key in keyboard. Use key adapter to handle events.[10]
This program uses Swing components (JTextField, JLabel, JFrame) for GUI and a KeyAdapter to handle keyboard events. Whenever the user presses any key in either input field, the sum is automatically calculated and displayed in the output ...
- 310 marksWeb Container, Introduction to Servlets, LHideAnswer
Define servlet. Discuss life cycle of servlet. Differentiate servlet with JSP. Write a simple JSP file to display 'IOST' 20 times.[10]
--- A servlet is a small program that executes on the server side of a Web connection. Just as applets dynamically extend the functionality of a web browser, servlets dynamically extend the capabilities of a web server. It is a Java prog...
- 45 marksClass and ObjectHideAnswer
Define class. How do you create a class in Java? Differentiate class with interface. [5]
Class in Java: Definition, Creation, and Difference with Interface
Definition of Class
A class in Java is a blueprint or template from which objects are created. It defines the properties (fields/attributes) and behaviors (methods) that the objects of that class will have. A class encapsulates data and the methods that operate on that data into a single unit.
Syntax:
class ClassName { // fields (attributes) // methods (behaviors) }
Creating a Class in Java
A class is created using the
classkeyword followed by the class name. It can contain:- Fields (variables to store data)
- Methods (functions to define behavior)
- Constructors (to initialize objects)
Example:
class Student { // Fields int rollNo; String name; // Constructor Student(int r, String n) { rollNo = r; name = n; } // Method void display() { System.out.println("Roll No: " + rollNo + ", Name: " + name); } } // Using the class public class Main { public static void main(String[] args) { Student s = new Student(1, "Ram"); // object creation s.display(); } }
Difference Between Class and Interface
Basis Class Interface Keyword Declared using classkeywordDeclared using interfacekeywordMethods Can have both abstract and concrete (implemented) methods All methods are abstract by default (empty body) Fields Can have instance variables of any type All fields are public,static, andfinalby defaultInstantiation Objects can be created directly from a class Cannot be instantiated directly Inheritance Supports single inheritance ( extends)Supports multiple inheritance (a class can implementmultiple interfaces)Access Modifiers Methods can have any access modifier Methods are publicandabstractby defaultConstructor Can have constructors Cannot have constructors Purpose Used to define object structure and behavior Used to achieve abstraction and loose coupling Implementation A class uses extendsto inherit another classA class uses implementsto use an interface
Key Note
An interface is a blueprint of a class used to achieve:
- Abstraction
- Multiple inheritance (not supported directly with classes in Java)
- Loose coupling
A class that implements an interface must implement all the methods declared in that interface.
- 55 marksWorking with FilesHideAnswer
Write a simple Java program that reads a file named 'Test.txt' and displays its contents. [5]
Java provides the java.io package for file handling. To read a file, we use FileReader wrapped with BufferedReader for efficient line-by-line reading. If the file is not found or cannot be read, an exception is thrown, which must be hand...
- 65 marksLayout ManagementHideAnswer
Why do we need layout management? What is GridBag layout? [5]
In Java, when we build a GUI application, we place multiple components (buttons, labels, text fields, etc.) inside a container (like a Frame or Panel). Layout management is needed for the following reasons: 1. Platform Independence: Java...
- 75 marksIntroduction to Java Web FrameworksHideAnswer
Discuss MVC design pattern with example. [5]
MVC (Model-View-Controller) is a software architectural/design pattern that separates an application into three interconnected components. This separation helps in organizing code, improving maintainability, and allowing independent deve...
- 85 marksDDL and DML Operations using Java, PrepareHideAnswer
What are the benefits of using JDBC? What is prepared statement? [5]
--- JDBC (Java Database Connectivity) is a Java API that enables Java applications to interact with databases. The key benefits are: 1. Platform Independence / Cross-Platform: JDBC is cross-platform, meaning Java applications using JDBC ...
- 95 marksSocket programming using TCP, Socket progrHideAnswer
Write Java programs using TCP sockets that communicate with each other in a computer network. [5]
A socket is one endpoint of a two-way communication link between two programs running on the network. It is bound to a port number so that the TCP layer can identify the application data to be sent to the destination. The java.net packag...
- 105 marksCompiling and Running Java ProgramsHideAnswer
Define Java Bean. How is it different from other Java programs? What is design pattern? [5]
A Java Bean is a reusable software component written in Java that follows a specific set of conventions (rules). It is essentially a Java class that encapsulates multiple objects into a single object (the bean). - The class must be publi...
- 115 marksWeb Container, Introduction to Servlets, LHideAnswer
How do you handle HTTP request (GET) using servlet? [5]
A Servlet handles HTTP GET requests by overriding the doGet() method provided by the HttpServlet class. When a client sends a GET request (e.g., by submitting an HTML form with method="GET" or typing a URL), the web container invokes the...
- 125 marksIntroduction of RMI, Architecture of RMI, HideAnswer
What are different layers of RMI architecture? Explain. [5]
RMI (Remote Method Invocation) is a Java API that allows an object running in one Java Virtual Machine (JVM) to invoke methods on an object running in another JVM, enabling distributed application development. --- RMI architecture consis...
- 135 marksWeb Container, Introduction to Servlets, LHideAnswer
Write short notes on: a. Servlet API b. RMI vs CORBA [2.5+2.5]
--- The Servlet API is a set of Java classes and interfaces provided in the javax.servlet and javax.servlet.http packages that define the contract between a servlet and the servlet container (e.g., Apache Tomcat). Component Type Descript...