2026 question paper

Introduction To Java Programming Language

28 questions

  1. 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

    Which component makes Java bytecode executable on a particular operating system?

    (i) JVM
    (ii) Javadoc
    (iii) JDK
    (iv) Java compiler

    View this question on its own page →
    Worked Solution

    Answer: (i) JVM

    The Java Virtual Machine (JVM) executes Java bytecode on the host operating system. The compiler converts .java source into platform-independent .class bytecode; a compatible JVM interprets or JIT-compiles it for that platform.

    MermaidDiagram
    Rendering diagram…
  2. 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

    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 inherited

    View this question on its own page →
    Worked Solution

    Answer: (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 constructor
    
  3. 1(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

    Which statement terminates the current iteration of a loop and proceeds with the next iteration?

    (i) break
    (ii) return
    (iii) continue
    (iv) exit

    View this question on its own page →
    Worked Solution

    Answer: (iii) continue

    continue skips the remaining statements in the current loop iteration and moves to the next iteration. break exits the loop; return exits the current method.

    for (int i = 1; i <= 5; i++) {
        if (i == 3) continue;
        System.out.print(i + " "); // 1 2 4 5
    }
    
  4. 1(d). Which keyword refers to the current object? (i) super (ii) current (iii) this (iv) self20262m

    Module 3: Methods of Java

    Which keyword refers to the current object?

    (i) super
    (ii) current
    (iii) this
    (iv) self

    View this question on its own page →
    Worked Solution

    Answer: (iii) this

    this refers to the current object instance. It is often used to distinguish instance fields from parameters or to call another constructor using this(...).

    class Student {
        int id;
        Student(int id) { this.id = id; }
    }
    
  5. 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

    Runtime polymorphism in Java is primarily achieved through:

    (i) Method overriding
    (ii) Constructor overloading
    (iii) Method overloading
    (iv) Static variables

    View this question on its own page →
    Worked Solution

    Answer: (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(); // bark
    
  6. 1(f). Which keyword explicitly generates an exception? (i) throws (ii) exception (iii) throw (iv) catch20262m

    Module 4: Exception Handling

    Which keyword explicitly generates an exception?

    (i) throws
    (ii) exception
    (iii) throw
    (iv) catch

    View this question on its own page →
    Worked Solution

    Answer: (iii) throw

    throw explicitly throws an exception object. throws appears in a method declaration to announce exceptions that may propagate to the caller.

    if (age < 18) throw new IllegalArgumentException("Underage");
    
  7. 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

    Event handling in Java commonly follows the:

    (i) Delegation event model
    (ii) Sequential event model
    (iii) Inheritance event model
    (iv) Compilation event model

    View this question on its own page →
    Worked Solution

    Answer: (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.

    MermaidDiagram
    Rendering diagram…
  8. 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

    JDBC is primarily used for:

    (i) Network routing
    (ii) Thread synchronization
    (iii) Database connectivity
    (iv) Graphics programming

    View this question on its own page →
    Worked Solution

    Answer: (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, and ResultSet.

  9. 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

    AWT stands for:

    (i) Advanced Window Technology
    (ii) Application Window Tool
    (iii) Abstract Window Toolkit
    (iv) Abstract Web Toolkit

    View this question on its own page →
    Worked Solution

    Answer: (iii) Abstract Window Toolkit

    AWT is Java's Abstract Window Toolkit, a GUI library providing components such as Frame, Button, Label, and TextField. Many AWT components use native operating-system peers.

  10. 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

    Which JDBC driver type is commonly called the thin driver?

    (i) Type 1
    (ii) Type 2
    (iii) Type 3
    (iv) Type 4

    View this question on its own page →
    Worked Solution

    Answer: (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.

  11. Budget 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.

    Install Pocketly
  12. 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

    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++.

    View this question on its own page →
    Worked Solution

    Java 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.

    MermaidDiagram
    Rendering diagram…
  13. 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

    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.

    View this question on its own page →
    Worked Solution

    Bytecode, JVM and JDK

    1. Source: The programmer writes .java files.
    2. Compiler: javac (part of the JDK) compiles source into bytecode in .class files.
    3. JVM: A platform-specific JVM loads, verifies and executes bytecode, interpreting it or compiling hot code with a JIT compiler.
    4. 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.
    MermaidDiagram
    Rendering diagram…

    Thus Java source generally need not be recompiled for each OS, provided a compatible JVM and required libraries are available.

  14. 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

    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.

    View this question on its own page →
    Worked Solution

    Primitive types and conversion

    Java has eight primitive types: byte, short, int, long, float, double, char, and boolean. Numeric types differ in range and precision; boolean represents 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 loss
    

    Narrowing 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 byte
    

    A cast permits the conversion; it does not guarantee that the original value is preserved. Use appropriate types and validate ranges.

  15. 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

    Construct a Java program that prints a triangular pattern of numbers and analyse how the for loop controls the number of rows and columns.

    View this question on its own page →
    Worked Solution

    Number triangle using nested for loops

    public 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 5
    

    The outer loop controls rows (i = 1 to rows). The inner loop prints i numbers on row i; 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).

  16. 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

    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.

    View this question on its own page →
    Worked Solution

    Evaluate 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.

    1. a++ yields the old value 5, then a becomes 6.
    2. ++b increments b from 2 to 3, and yields 3.
    3. The later a is now 6, so 3 * 6 = 18.
    4. Addition gives 5 + 18 = 23.

    Output: 23. Final values are a = 6, b = 3.

  17. 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

    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.

    View this question on its own page →
    Worked Solution

    Find 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 max and min from the first element avoids assuming marks are non-negative. A single pass calculates all three values: O(n) time and O(1) extra space.

  18. 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

    Consider the following code segment:

    String s1 = "Java";
    String s2 = new String("Java");
    

    Analyse the results of s1 == s2 and s1.equals(s2).

    View this question on its own page →
    Worked Solution

    == versus .equals()

    String s1 = "Java";
    String s2 = new String("Java");
    
    • s1 == s2 is false because == compares object references, and new String(...) creates a distinct object.
    • s1.equals(s2) is true because String.equals() compares character contents.

    For strings, use .equals() when comparing text. == is appropriate when reference identity is what you intend to test.

  19. 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

    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.

    View this question on its own page →
    Worked Solution

    Method 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 triangleArea would be clearer in production code.

  20. 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

    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.

    View this question on its own page →
    Worked Solution

    Using super and constructor order

    super(...) 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, then Person info, Student info. The superclass constructor runs before the subclass constructor body.

  21. 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

    Compare checked and unchecked exceptions using suitable examples. Analyse how the compiler treats each category and discuss appropriate handling strategies.

    View this question on its own page →
    Worked Solution

    Checked vs unchecked exceptions

    Checked Unchecked
    Compiler requires catching or declaring them No compile-time catch/declare requirement
    Subclasses of Exception excluding RuntimeException RuntimeException and its subclasses
    Example: IOException, SQLException Example: NullPointerException, ArithmeticException
    import 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 catch Exception indiscriminately.

  22. Budget 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.

    Install Pocketly
  23. 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

    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.

    View this question on its own page →
    Worked Solution

    Java thread life cycle

    A Java thread may be NEW, RUNNABLE (eligible to run, including running), BLOCKED, WAITING, TIMED_WAITING, or TERMINATED. The scheduler decides when a runnable thread gets CPU time.

    MermaidDiagram
    Rendering diagram…

    Calling start() schedules a new thread; calling run() directly is an ordinary method call. A terminated thread cannot be restarted.

  24. 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

    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.

    View this question on its own page →
    Worked Solution

    Thread priorities

    Java priorities range from Thread.MIN_PRIORITY (1) to Thread.NORM_PRIORITY (5) and Thread.MAX_PRIORITY (10). Set one using thread.setPriority(7) and inspect it with getPriority().

    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.

  25. 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

    Compare the four types of JDBC drivers with respect to architecture, dependence on native libraries, portability and typical use.

    View this question on its own page →
    Worked Solution

    Four 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.

  26. 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

    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.

    View this question on its own page →
    Worked Solution

    AWT 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. addActionListener registers a listener; a click generates an ActionEvent and invokes the handler. The window listener closes the frame cleanly.

  27. 9(a). Write a short note on Runtime Polymorphism.20267m

    Module 3: Methods of Java

    Write a short note on Runtime Polymorphism.

    View this question on its own page →
    Worked Solution

    Runtime 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(); // Circle
    

    Benefits include extensibility, loose coupling and writing code against abstractions. Static, private and final methods are not overridden in the normal runtime-dispatch sense.

  28. 9(b). Write a short note on Constructors and Object Creation.20267m

    Module 2: Arrays and Strings

    Write a short note on Constructors and Object Creation.

    View this question on its own page →
    Worked Solution

    Constructors 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");
    

    new allocates 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.

  29. 9(c). Write a short note on Method Overriding.20267m

    Module 3: Methods of Java

    Write a short note on Method Overriding.

    View this question on its own page →
    Worked Solution

    Method 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 @Override to 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.

  30. 9(d). Write a short note on Applets and Applet Parameters.20267m

    Module 5: Introduction to AWT and Applets

    Write a short note on Applets and Applet Parameters.

    View this question on its own page →
    Worked Solution

    Applets 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() and destroy(). 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 with getParameter("color").

    public void init() {
        String color = getParameter("color");
        if (color == null) color = "blue";
        // use the parameter in applet initialization
    }
    
    MermaidDiagram
    Rendering diagram…

    For modern applications, use standard desktop, web or mobile technologies instead.

AI LearningWeb Platform

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.