2026 question paper
Introduction To Java Programming Language
28 questions
1(a). Which component makes Java bytecode executable on a particular operating system? (i) JVM (ii) Javadoc (iii) JDK (iv) Java compiler20262m
Module 1: Introduction to Java
View this question on its own page →Which component makes Java bytecode executable on a particular operating system?
(i) JVM
(ii) Javadoc
(iii) JDK
(iv) Java compilerWorked SolutionAnswer: (i) JVM
The Java Virtual Machine (JVM) executes Java bytecode on the host operating system. The compiler converts
.javasource into platform-independent.classbytecode; a compatible JVM interprets or JIT-compiles it for that platform.MermaidDiagramRendering diagram…1(b). A constructor is automatically invoked when: (i) A method is called (ii) A package is imported (iii) An object is created (iv) A class is inherited20262m
Module 2: Arrays and Strings
View this question on its own page →A constructor is automatically invoked when:
(i) A method is called
(ii) A package is imported
(iii) An object is created
(iv) A class is inheritedWorked SolutionAnswer: (iii) An object is created
A constructor runs when an object is instantiated with
new(or through another constructor). It initializes the new object's state. Constructors have the class name and no return type.class Student { Student() { System.out.println("Created"); } } Student s = new Student(); // invokes constructor1(c). Which statement terminates the current iteration of a loop and proceeds with the next iteration? (i) break (ii) return (iii) continue (iv) exit20262m
Module 1: Introduction to Java
View this question on its own page →Which statement terminates the current iteration of a loop and proceeds with the next iteration?
(i) break
(ii) return
(iii) continue
(iv) exitWorked SolutionAnswer: (iii)
continuecontinueskips the remaining statements in the current loop iteration and moves to the next iteration.breakexits the loop;returnexits the current method.for (int i = 1; i <= 5; i++) { if (i == 3) continue; System.out.print(i + " "); // 1 2 4 5 }1(d). Which keyword refers to the current object? (i) super (ii) current (iii) this (iv) self20262m
Module 3: Methods of Java
View this question on its own page →Which keyword refers to the current object?
(i) super
(ii) current
(iii) this
(iv) selfWorked SolutionAnswer: (iii)
thisthisrefers to the current object instance. It is often used to distinguish instance fields from parameters or to call another constructor usingthis(...).class Student { int id; Student(int id) { this.id = id; } }1(e). Runtime polymorphism in Java is primarily achieved through: (i) Method overriding (ii) Constructor overloading (iii) Method overloading (iv) Static variables20262m
Module 3: Methods of Java
View this question on its own page →Runtime polymorphism in Java is primarily achieved through:
(i) Method overriding
(ii) Constructor overloading
(iii) Method overloading
(iv) Static variablesWorked SolutionAnswer: (i) Method overriding
Runtime polymorphism occurs when a superclass reference refers to a subclass object and an overridden instance method is selected according to the object's actual type at runtime.
class Animal { void sound() { System.out.println("sound"); } } class Dog extends Animal { @Override void sound() { System.out.println("bark"); } } Animal a = new Dog(); a.sound(); // bark1(f). Which keyword explicitly generates an exception? (i) throws (ii) exception (iii) throw (iv) catch20262m
Module 4: Exception Handling
View this question on its own page →Which keyword explicitly generates an exception?
(i) throws
(ii) exception
(iii) throw
(iv) catchWorked SolutionAnswer: (iii)
throwthrowexplicitly throws an exception object.throwsappears in a method declaration to announce exceptions that may propagate to the caller.if (age < 18) throw new IllegalArgumentException("Underage");1(g). Event handling in Java commonly follows the: (i) Delegation event model (ii) Sequential event model (iii) Inheritance event model (iv) Compilation event model20262m
Module 5: Introduction to AWT and Applets
View this question on its own page →Event handling in Java commonly follows the:
(i) Delegation event model
(ii) Sequential event model
(iii) Inheritance event model
(iv) Compilation event modelWorked SolutionAnswer: (i) Delegation event model
In Java GUI programming, an event source (such as a button) generates an event and delegates handling to registered listener objects. The listener implements an interface such as
ActionListener.MermaidDiagramRendering diagram…1(h). JDBC is primarily used for: (i) Network routing (ii) Thread synchronization (iii) Database connectivity (iv) Graphics programming20262m
Module 6: Introduction to Java Database Connectivity
View this question on its own page →JDBC is primarily used for:
(i) Network routing
(ii) Thread synchronization
(iii) Database connectivity
(iv) Graphics programmingWorked SolutionAnswer: (iii) Database connectivity
JDBC (Java Database Connectivity) is a Java API for connecting to relational databases, executing SQL statements, and processing results using interfaces such as
Connection,PreparedStatement, andResultSet.1(i). AWT stands for: (i) Advanced Window Technology (ii) Application Window Tool (iii) Abstract Window Toolkit (iv) Abstract Web Toolkit20262m
Module 5: Introduction to AWT and Applets
View this question on its own page →AWT stands for:
(i) Advanced Window Technology
(ii) Application Window Tool
(iii) Abstract Window Toolkit
(iv) Abstract Web ToolkitWorked SolutionAnswer: (iii) Abstract Window Toolkit
AWT is Java's Abstract Window Toolkit, a GUI library providing components such as
Frame,Button,Label, andTextField. Many AWT components use native operating-system peers.1(j). Which JDBC driver type is commonly called the thin driver? (i) Type 1 (ii) Type 2 (iii) Type 3 (iv) Type 420262m
Module 6: Introduction to Java Database Connectivity
View this question on its own page →Which JDBC driver type is commonly called the thin driver?
(i) Type 1
(ii) Type 2
(iii) Type 3
(iv) Type 4Worked SolutionAnswer: (iv) Type 4
A Type 4 JDBC driver (thin driver) translates JDBC calls directly into the database's network protocol. It is generally pure Java and does not require native client libraries.
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
2(a). Compare Java and C++ with respect to memory management, pointers, inheritance, platform independence, exception handling and object-oriented features. Identify the design choices that make Java different from C++.20267m
Module 1: Introduction to Java
View this question on its own page →Compare Java and C++ with respect to memory management, pointers, inheritance, platform independence, exception handling and object-oriented features. Identify the design choices that make Java different from C++.
Worked SolutionJava vs C++ (7-mark answer)
Aspect Java C++ Memory Automatic garbage collection Manual management and RAII/smart pointers Pointers No general pointer arithmetic exposed Supports pointers and pointer arithmetic Inheritance A class extends one class; multiple interfaces allowed Multiple class inheritance supported Portability Bytecode runs on compatible JVMs Usually compiled to native platform code Exceptions Checked and unchecked exceptions Primarily unchecked exception model Operator overloading Generally not supported for user classes Supported Generic types Generics, mostly type-erased Templates Java emphasizes managed memory, safety and JVM portability; C++ offers more low-level control and often direct native performance. Both support object-oriented programming, encapsulation, inheritance and polymorphism.
MermaidDiagramRendering diagram…2(b). A Java program is required to run on different operating systems without recompilation of the source code. Analyse the role of bytecode, JVM and JDK in achieving Java's platform-independent execution model.20267m
Module 1: Introduction to Java
View this question on its own page →A Java program is required to run on different operating systems without recompilation of the source code. Analyse the role of bytecode, JVM and JDK in achieving Java's platform-independent execution model.
Worked SolutionBytecode, JVM and JDK
- Source: The programmer writes
.javafiles. - Compiler:
javac(part of the JDK) compiles source into bytecode in.classfiles. - JVM: A platform-specific JVM loads, verifies and executes bytecode, interpreting it or compiling hot code with a JIT compiler.
- JDK: The Java Development Kit contains development tools such as
javac, runtime components and debugging/documentation tools. The JVM is the execution engine, not the compiler.
MermaidDiagramRendering diagram…Thus Java source generally need not be recompiled for each OS, provided a compatible JVM and required libraries are available.
- Source: The programmer writes
3(a). Analyse Java's primitive data types and type conversion mechanisms. Construct suitable examples showing implicit widening and explicit narrowing conversion, including one case where data loss occurs.20267m
Module 1: Introduction to Java
View this question on its own page →Analyse Java's primitive data types and type conversion mechanisms. Construct suitable examples showing implicit widening and explicit narrowing conversion, including one case where data loss occurs.
Worked SolutionPrimitive types and conversion
Java has eight primitive types:
byte,short,int,long,float,double,char, andboolean. Numeric types differ in range and precision;booleanrepresents true/false and is not numeric.Widening converts a type to a type with a broader range, usually implicitly:
int count = 25; double value = count; // 25.0, no narrowing lossNarrowing converts to a smaller or less precise type and requires a cast:
double price = 19.95; int whole = (int) price; // 19: fractional part lost int n = 130; byte b = (byte) n; // wraps to -126 for 8-bit signed byteA cast permits the conversion; it does not guarantee that the original value is preserved. Use appropriate types and validate ranges.
3(b). Construct a Java program that prints a triangular pattern of numbers and analyse how the for loop controls the number of rows and columns.20267m
Module 1: Introduction to Java
View this question on its own page →Construct a Java program that prints a triangular pattern of numbers and analyse how the for loop controls the number of rows and columns.
Worked SolutionNumber triangle using nested
forloopspublic class Triangle { public static void main(String[] args) { int rows = 5; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } }Output:
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5The outer loop controls rows (
i = 1torows). The inner loop printsinumbers on rowi;println()moves to the next line. There are (1+2+\cdots+n=n(n+1)/2) printed values, so time complexity is O(n²) and auxiliary space is O(1).4(a). Consider the following code segment: ``java int a = 5; int b = 2; System.out.println(a++ + ++b * a); `` Determine the value printed by the program and show the evaluation sequence according to Java's operator and increment rules.20267m
Module 1: Introduction to Java
View this question on its own page →Consider the following code segment:
int a = 5; int b = 2; System.out.println(a++ + ++b * a);Determine the value printed by the program and show the evaluation sequence according to Java's operator and increment rules.
Worked SolutionEvaluate the expression
int a = 5; int b = 2; System.out.println(a++ + ++b * a);Java evaluates operands left-to-right; multiplication has higher precedence than addition.
a++yields the old value 5, thenabecomes 6.++bincrementsbfrom 2 to 3, and yields 3.- The later
ais now 6, so3 * 6 = 18. - Addition gives
5 + 18 = 23.
Output:
23. Final values area = 6,b = 3.4(b). A student record system stores marks of 50 students in an array. Construct a Java program to calculate the highest, lowest and average marks and analyse the time complexity of the operations.20267m
Module 2: Arrays and Strings
View this question on its own page →A student record system stores marks of 50 students in an array. Construct a Java program to calculate the highest, lowest and average marks and analyse the time complexity of the operations.
Worked SolutionFind highest, lowest and average marks
public class Marks { public static void main(String[] args) { int[] marks = {72, 85, 61, 90, 77}; // example values int max = marks[0], min = marks[0], sum = 0; for (int mark : marks) { if (mark > max) max = mark; if (mark < min) min = mark; sum += mark; } double average = (double) sum / marks.length; System.out.println("Highest = " + max); System.out.println("Lowest = " + min); System.out.println("Average = " + average); } }Replace the example array with the 50 students' marks. Initializing
maxandminfrom the first element avoids assuming marks are non-negative. A single pass calculates all three values: O(n) time and O(1) extra space.5(a). Consider the following code segment: ``java String s1 = "Java"; String s2 = new String("Java"); ` Analyse the results of s1 == s2 and s1.equals(s2)`.20267m
Module 2: Arrays and Strings
View this question on its own page →Consider the following code segment:
String s1 = "Java"; String s2 = new String("Java");Analyse the results of
s1 == s2ands1.equals(s2).Worked Solution==versus.equals()String s1 = "Java"; String s2 = new String("Java");s1 == s2is false because==compares object references, andnew String(...)creates a distinct object.s1.equals(s2)is true becauseString.equals()compares character contents.
For strings, use
.equals()when comparing text.==is appropriate when reference identity is what you intend to test.5(b). Construct overloaded methods for calculating the area of a circle, rectangle and triangle. Analyse how Java selects the appropriate method based on the parameter list.20267m
Module 3: Methods of Java
View this question on its own page →Construct overloaded methods for calculating the area of a circle, rectangle and triangle. Analyse how Java selects the appropriate method based on the parameter list.
Worked SolutionMethod overloading for areas
Overloading means methods share a name but have different parameter lists. Java resolves the call at compile time using argument count and types.
class Area { static double area(double r) { return Math.PI * r * r; } static double area(double length, double width) { return length * width; } static double area(double base, double height, boolean triangle) { return 0.5 * base * height; } public static void main(String[] args) { System.out.println(area(2.0)); System.out.println(area(4.0, 3.0)); System.out.println(area(4.0, 5.0, true)); } }Return type alone cannot distinguish overloads. The extra boolean is used here to give the triangle method a distinct signature; a named method such as
triangleAreawould be clearer in production code.6(a). In Java, a subclass needs to invoke a constructor and method of its superclass. Construct a suitable program using super and analyse the order in which superclass and subclass constructors execute.20267m
Module 3: Methods of Java
View this question on its own page →In Java, a subclass needs to invoke a constructor and method of its superclass. Construct a suitable program using
superand analyse the order in which superclass and subclass constructors execute.Worked SolutionUsing
superand constructor ordersuper(...)invokes a superclass constructor and must be the first statement in a constructor.super.method()calls an accessible superclass method implementation.class Person { Person(String name) { System.out.println("Person: " + name); } void info() { System.out.println("Person info"); } } class Student extends Person { Student(String name) { super(name); System.out.println("Student created"); } @Override void info() { super.info(); System.out.println("Student info"); } } class Demo { public static void main(String[] args) { Student s = new Student("Asha"); s.info(); } }Output order:
Person: Asha,Student created, thenPerson info,Student info. The superclass constructor runs before the subclass constructor body.6(b). Compare checked and unchecked exceptions using suitable examples. Analyse how the compiler treats each category and discuss appropriate handling strategies.20267m
Module 4: Exception Handling
View this question on its own page →Compare checked and unchecked exceptions using suitable examples. Analyse how the compiler treats each category and discuss appropriate handling strategies.
Worked SolutionChecked vs unchecked exceptions
Checked Unchecked Compiler requires catching or declaring them No compile-time catch/declare requirement Subclasses of ExceptionexcludingRuntimeExceptionRuntimeExceptionand its subclassesExample: IOException,SQLExceptionExample: NullPointerException,ArithmeticExceptionimport java.io.IOException; class Example { static void read() throws IOException { throw new IOException("Read failed"); } public static void main(String[] args) { try { read(); } catch (IOException e) { System.err.println(e.getMessage()); } } }Catch exceptions when recovery is possible, or declare checked exceptions with
throws. Prevent unchecked exceptions through validation and correct program logic; do not catchExceptionindiscriminately.- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
7(a). Construct a thread life-cycle diagram showing the major states through which a Java thread can pass. Analyse transitions caused by start(), scheduling, waiting and termination.20267m
Module 4: Exception Handling
View this question on its own page →Construct a thread life-cycle diagram showing the major states through which a Java thread can pass. Analyse transitions caused by
start(), scheduling, waiting and termination.Worked SolutionJava thread life cycle
A Java thread may be
NEW,RUNNABLE(eligible to run, including running),BLOCKED,WAITING,TIMED_WAITING, orTERMINATED. The scheduler decides when a runnable thread gets CPU time.MermaidDiagramRendering diagram…Calling
start()schedules a new thread; callingrun()directly is an ordinary method call. A terminated thread cannot be restarted.7(b). A Java application creates several threads having different priorities. Analyse how thread priority is assigned and discuss why priority alone should not be treated as a guarantee of execution order.20267m
Module 4: Exception Handling
View this question on its own page →A Java application creates several threads having different priorities. Analyse how thread priority is assigned and discuss why priority alone should not be treated as a guarantee of execution order.
Worked SolutionThread priorities
Java priorities range from
Thread.MIN_PRIORITY(1) toThread.NORM_PRIORITY(5) andThread.MAX_PRIORITY(10). Set one usingthread.setPriority(7)and inspect it withgetPriority().Priorities are hints to the scheduler, not a promise of execution order. Scheduling policies vary by JVM and operating system; threads may run in an order different from their priority. Correctness must rely on synchronization primitives (
synchronized, locks, queues, latches), not priority. Avoid using priority as a substitute for coordination.8(a). Compare the four types of JDBC drivers with respect to architecture, dependence on native libraries, portability and typical use.20267m
Module 6: Introduction to Java Database Connectivity
View this question on its own page →Compare the four types of JDBC drivers with respect to architecture, dependence on native libraries, portability and typical use.
Worked SolutionFour types of JDBC drivers
Type Architecture Native dependency Portability 1: JDBC–ODBC bridge JDBC translated to ODBC ODBC/native layer Low; obsolete/removed from modern JDKs 2: Native API JDBC translated to vendor native API Yes Requires native library per platform 3: Network protocol JDBC sent to middleware, translated to DB protocol Usually no client native library Portable, requires middleware 4: Thin/pure Java JDBC translated directly to database wire protocol No High; needs database-specific driver Type 4 is widely used because it is pure Java and communicates directly with the database server. Choose a driver supported by the target database and deployment environment.
8(b). Construct an AWT application containing a frame, label, text field and button. Develop an event-handling mechanism that displays a message when the button is pressed.20267m
Module 5: Introduction to AWT and Applets
View this question on its own page →Construct an AWT application containing a frame, label, text field and button. Develop an event-handling mechanism that displays a message when the button is pressed.
Worked SolutionAWT event-handling example
import java.awt.*; import java.awt.event.*; public class GreetingApp { public static void main(String[] args) { Frame frame = new Frame("Greeting"); Label label = new Label("Enter your name:"); TextField input = new TextField(18); Button button = new Button("Greet"); Label output = new Label(" "); Panel panel = new Panel(); panel.add(label); panel.add(input); panel.add(button); panel.add(output); button.addActionListener(e -> output.setText("Hello, " + input.getText())); frame.add(panel); frame.setSize(420, 120); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); } }); frame.setVisible(true); } }The button is the event source.
addActionListenerregisters a listener; a click generates anActionEventand invokes the handler. The window listener closes the frame cleanly.9(a). Write a short note on Runtime Polymorphism.20267m
Module 3: Methods of Java
View this question on its own page →Write a short note on Runtime Polymorphism.
Worked SolutionRuntime polymorphism
Runtime polymorphism allows a superclass reference to invoke a subclass's overridden instance method. The method implementation is chosen at runtime using dynamic method dispatch.
class Shape { void draw() { System.out.println("Shape"); } } class Circle extends Shape { @Override void draw() { System.out.println("Circle"); } } Shape s = new Circle(); s.draw(); // CircleBenefits include extensibility, loose coupling and writing code against abstractions. Static, private and final methods are not overridden in the normal runtime-dispatch sense.
9(b). Write a short note on Constructors and Object Creation.20267m
Module 2: Arrays and Strings
View this question on its own page →Write a short note on Constructors and Object Creation.
Worked SolutionConstructors and object creation
A constructor initializes an object's state. It has the same name as its class and no return type. Constructors may be no-argument, parameterized, or overloaded; if no constructor is declared, Java supplies a default no-argument constructor.
class Book { String title; Book(String title) { this.title = title; } } Book b = new Book("Networks");newallocates an object, initializes its fields to default values, and invokes the selected constructor.this(...)calls another constructor in the same class and must be first;super(...)calls a superclass constructor and must also be first.9(c). Write a short note on Method Overriding.20267m
Module 3: Methods of Java
View this question on its own page →Write a short note on Method Overriding.
Worked SolutionMethod overriding
Overriding occurs when a subclass provides a compatible implementation of an inherited instance method. The method signature must match; the return type must be the same or covariant, access cannot be more restrictive, and checked exceptions cannot be broadened beyond the parent's declaration. Use
@Overrideto catch mistakes.class Animal { void speak() { System.out.println("..."); } } class Cat extends Animal { @Override void speak() { System.out.println("Meow"); } }Overriding supports runtime polymorphism. It differs from overloading, where methods share a name but have different parameter lists.
9(d). Write a short note on Applets and Applet Parameters.20267m
Module 5: Introduction to AWT and Applets
View this question on its own page →Write a short note on Applets and Applet Parameters.
Worked SolutionApplets and applet parameters
A Java applet was a small Java program designed to run inside an applet viewer or browser plugin. Applets historically used lifecycle methods such as
init(),start(),stop()anddestroy(). Modern browsers no longer support Java applets, so they are a legacy topic rather than a current deployment choice.Parameters could be passed in HTML using
<param name="color" value="blue">and read withgetParameter("color").public void init() { String color = getParameter("color"); if (color == null) color = "blue"; // use the parameter in applet initialization }MermaidDiagramRendering diagram…For modern applications, use standard desktop, web or mobile technologies instead.
Coursify — Personal AI Course Generator
Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.