BCAMCABSc ITB.Tech CSE

Java — syllabus, exam questions and lab programs

Your scheme may call it Programming in Java / Object Oriented Programming using Java.

Java arrives after C, and the shift it asks for is not syntax — it is the idea that a program is a set of objects sending each other messages rather than a list of instructions. Students who make that shift find the rest of the degree easier, because inheritance and interfaces turn up again in software engineering, in web technologies and in whatever framework they meet later. Students who treat Java as C with extra brackets struggle from the inheritance unit onwards.

The paper is generous. Four principles — encapsulation, inheritance, polymorphism, abstraction — carry a large share of the marks and each of them is a short definition plus a five-line program. Exception handling, multithreading and collections are similarly compact. There is very little to memorise and a lot to demonstrate.

Java is also the language most in-bulk recruiters in this region still name in a job description, so unlike some papers this one is worth learning beyond the exam. The gap is that a syllabus stops at core Java, and a job starts at Spring Boot and a database. That gap is worth closing in your own time.

We teach this

Java is one of the papers we teach at WebPrims

This is not only a page about Java. It is a subject we teach in a classroom on Majitha Road, and a good share of every batch is college students taking it alongside their own semester. Bring your scheme and we cover what is on it.

What that means in practice: the whole syllabus gets covered rather than the parts that make a good demo, you write code on a machine instead of copying it into a file, and the lab work gets done here rather than the night before submission.

What we will not say is that this guarantees you marks or a job. We do not run placements and we do not promise results. Come and sit in a class, decide for yourself.

₹4,500 / month— one rate, any subjectMon–Sat, batches at 11, 1, 3 and 5Majitha Road, Amritsar

The syllabus, unit by unit

What each unit actually contains, and whether it is there because it matters or because it is on the paper. Unit order and numbering vary between GNDU, PTU and your batch’s scheme — check your own before you plan a revision week.

1

Introduction and the Java environment

Features of Java, the JVM, JRE and JDK and how they differ, bytecode and platform independence, compiling with javac and running with java, data types, variables, operators, control structures and arrays.

'Explain JDK, JRE and JVM' is asked in nearly every paper and in nearly every interview. Two marks for ninety seconds of revision.

2

Classes, objects and methods

Defining a class, objects and references, constructors including overloading, the this keyword, static variables and methods, access modifiers, garbage collection and the finalize method.

Constructor overloading and static versus instance are the two things asked here. Both are short programs.

3

Inheritance and polymorphism

extends, single and multilevel and hierarchical inheritance, why Java has no multiple inheritance of classes, method overriding, super, the final keyword, abstract classes and methods, and dynamic method dispatch.

The heart of the paper. Overloading versus overriding is asked every single year — know both definitions and have a program for each.

4

Interfaces and packages

Declaring and implementing interfaces, multiple inheritance through interfaces, extending interfaces, creating and importing packages, and the access rules across packages.

The answer to 'how does Java achieve multiple inheritance' lives here, and that question follows the no-multiple-inheritance one almost automatically.

5

Exception handling

try, catch, finally, throw and throws, checked and unchecked exceptions, the exception hierarchy, nested try blocks and writing your own exception class.

Compact and reliably examined. The difference between throw and throws is a one-line answer worth remembering exactly.

6

Multithreading

The thread life cycle, creating threads by extending Thread and by implementing Runnable, thread priorities, synchronisation, and inter-thread communication with wait, notify and notifyAll.

Draw the life cycle diagram — new, runnable, running, blocked, terminated. It is asked as often as the definitions are.

7

Collections, strings and I/O

String, StringBuffer and StringBuilder, the wrapper classes, ArrayList, LinkedList, HashMap, HashSet, the Iterator, and byte and character streams for file input and output.

String versus StringBuffer versus StringBuilder is a stock question. ArrayList and HashMap are what you will actually use afterwards.

8

Applets, AWT, Swing and JDBC

The applet life cycle, AWT and Swing components, event handling with listeners, layout managers, and connecting to a database with JDBC.

Applets are dead technology and still in most schemes — learn the life cycle for the exam and forget it afterwards. JDBC is the part that is genuinely useful.

What is worth keeping after the exam

Revise all of it — the marks are the marks. But it is worth knowing which half of this paper you will still be using in two years, and which half exists because it is on the paper.

Stays with you

  • +Object-oriented thinking, which every language you touch from here on assumes
  • +Interfaces and abstraction, which is what every framework is built out of
  • +Exception handling, and the habit of deciding what should happen when something fails
  • +Collections — ArrayList and HashMap are in almost every program you will write
  • +JDBC, because talking to a database is most of what backend work is

For the exam, and then gone

  • −Applets and their life cycle — browsers removed the plugin years ago
  • −AWT, superseded by Swing and then by JavaFX, and by nothing in most real work
  • −finalize(), deprecated and unused
  • −Writing GUI layout managers by hand for a mark

Questions that come up year after year

Not a guess paper, and not a promise about what will be set. These are the questions this subject keeps asking because they are the ones that test whether you understood it.

  1. 01Difference between JDK, JRE and JVM
  2. 02Explain method overloading and method overriding with programs
  3. 03Why does Java not support multiple inheritance? How is it achieved?
  4. 04Explain the thread life cycle with a diagram
  5. 05Difference between String, StringBuffer and StringBuilder
  6. 06Write a program demonstrating exception handling with try, catch and finally
  7. 07Explain abstract class versus interface
  8. 08Write a program to connect to a database using JDBC

What students get wrong

From teaching this paper, not from a list somewhere. Each of these costs marks every year.

Wrong — Saying overloading and overriding are 'both about having two methods'.

Right — Overloading is compile time, same class, same name, different parameter list, return type irrelevant. Overriding is run time, subclass, identical signature, and the access modifier cannot be narrower. Write both programs, three lines each — the examiner wants to see the difference, not hear it.

Wrong — Comparing two strings with ==.

Right — == compares references. Two separately created Strings with the same text are not the same object, so == is false while .equals() is true. The string pool makes literals behave differently, which is exactly why this question is asked.

Wrong — Writing catch (Exception e) as the first catch block.

Right — Catch the specific exceptions first and the general one last, otherwise the compiler rejects the code as unreachable. This is a favourite trick in 'find the error in this program' questions.

Wrong — Learning core Java for the exam and stopping there because the syllabus stops there.

Right — Every Java job description in this region asks for Spring Boot and SQL. The syllabus ends where employability begins, and closing that gap is a few months of your own work — or a course built around exactly that.

Lab file programs

These compile and run as written — type them in, break them, and fix them. Copying a program into a file you never ran is how a practical viva goes badly.

Method overloading and overriding in one file

The two together, so the difference is visible rather than described. The standard practical answer.

java
class Shape {
    void area() {
        System.out.println("Area of a shape is not defined");
    }
}

class Rectangle extends Shape {
    // OVERRIDING: same signature as the parent, decided at run time
    @Override
    void area() {
        System.out.println("Rectangle area = length x breadth");
    }

    // OVERLOADING: same name, different parameters, decided at compile time
    void area(int length, int breadth) {
        System.out.println("Rectangle area = " + (length * breadth));
    }

    void area(double side) {
        System.out.println("Square area = " + (side * side));
    }
}

public class OverloadOverride {
    public static void main(String[] args) {
        Shape s = new Rectangle();   // reference of parent, object of child
        s.area();                    // calls the child version: dynamic dispatch

        Rectangle r = new Rectangle();
        r.area(10, 5);
        r.area(4.0);
    }
}

Exception handling with a custom exception

Covers try, catch, finally, throw, throws and a user-defined exception in one program.

java
class MarksOutOfRangeException extends Exception {
    MarksOutOfRangeException(String message) {
        super(message);
    }
}

public class ExceptionDemo {

    static void checkMarks(int marks) throws MarksOutOfRangeException {
        if (marks < 0 || marks > 100) {
            throw new MarksOutOfRangeException("Marks must be between 0 and 100, got " + marks);
        }
        System.out.println("Marks accepted: " + marks);
    }

    public static void main(String[] args) {
        int[] values = {85, 120};

        for (int m : values) {
            try {
                checkMarks(m);
            } catch (MarksOutOfRangeException e) {
                System.out.println("Rejected: " + e.getMessage());
            } finally {
                System.out.println("Checked " + m + "\n");
            }
        }

        try {
            int[] a = new int[3];
            a[5] = 1;                       // unchecked, at run time
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Array error: " + e.getMessage());
        }
    }
}

Multithreading with Runnable and synchronisation

Shows why synchronized exists — run it with the keyword removed and the total comes out wrong.

java
class Counter {
    private int count = 0;

    // Remove 'synchronized' and the final total will be less than 20000
    synchronized void increment() {
        count++;
    }

    int get() {
        return count;
    }
}

public class ThreadDemo implements Runnable {
    private final Counter counter;

    ThreadDemo(Counter counter) {
        this.counter = counter;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            counter.increment();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Counter c = new Counter();

        Thread t1 = new Thread(new ThreadDemo(c), "Thread-1");
        Thread t2 = new Thread(new ThreadDemo(c), "Thread-2");

        t1.start();
        t2.start();

        t1.join();      // wait for both to finish before reading the value
        t2.join();

        System.out.println("Expected 20000, got " + c.get());
    }
}

Long questions, answered the way they are marked

Not model answers to reproduce. What the examiner is checking for, and where the marks actually sit in each one.

Differentiate between JDK, JRE and JVM.

The JVM is the abstract machine that executes bytecode; it is what makes Java platform independent, because the bytecode is the same everywhere and the JVM differs per platform. The JRE is the JVM plus the standard class libraries — enough to run a Java program but not to compile one. The JDK is the JRE plus the development tools, javac and the debugger among them. Draw them as three nested boxes, JVM innermost; the nesting diagram is what the examiner is checking for.

Why does Java not support multiple inheritance of classes? How is it achieved?

Because of the diamond problem: if class D extends both B and C, and both inherit the same method from A, the compiler cannot decide which version D gets. Java removes the ambiguity by allowing only one superclass. The same effect is achieved with interfaces — a class may implement any number of them — because an interface historically carried no implementation, so there was nothing to be ambiguous about. Add that Java 8 introduced default methods and requires the implementing class to resolve a clash explicitly; that sentence marks out an answer that understands the reasoning rather than the rule.

Explain the difference between an abstract class and an interface.

An abstract class can hold both abstract and concrete methods, instance variables and constructors, and a class may extend only one. An interface holds method signatures — with default and static methods since Java 8 — has only public static final fields, no constructor, and a class may implement many. Use the judgement to close: an abstract class expresses 'is a kind of' with shared code; an interface expresses 'is capable of'. That last line is what turns a listed comparison into a full-marks answer.

Explain the thread life cycle with a diagram.

New when the Thread object is created; Runnable after start() is called, meaning ready and waiting for the scheduler; Running when the scheduler picks it; Blocked or Waiting on sleep(), wait(), join() or a lock it cannot get; Terminated when run() completes. Draw it as five boxes with labelled arrows and write the method that causes each transition on the arrow itself. The transitions carry the marks — a diagram with unlabelled arrows scores about half.

Past the syllabus

Your paper stops somewhere, and a job interview does not. If you want the version of this subject that goes further than the scheme asks for, there is a full course for it.