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 — tuition for Java, if that is the word you were searching for — 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.

Difference between — the ones that get asked

Every one of these is a five-mark question somewhere on this syllabus, and the marks are rarely in the first line. They are in the consequences underneath it.

Abstract class vs Interface

An abstract class is a partly built thing you extend. An interface is a contract you promise to fulfil. Use an abstract class when subclasses share code; use an interface when unrelated classes share a capability.

 Abstract classInterface
Keywordabstract class, extended with extendsinterface, implemented with implements
Multiple inheritanceA class can extend only one.A class can implement many.
FieldsAny instance variables, any access modifier.Only public static final constants.
ConstructorsYes — called when a subclass is constructed.No.
Method bodiesAbstract and concrete methods both allowed.Abstract by default; default and static methods allowed since Java 8, private methods since Java 9.
Access modifiers on methodsAny.public (or private, for the private helpers added in Java 9).
When to useRelated classes that share state and implementation — Animal and its subclasses.A capability unrelated classes can offer — Comparable, Runnable, Serializable.

Where people lose the marks

Two things date most answers. Since Java 8 an interface can have default and static methods with bodies, so "interfaces cannot have method bodies" is no longer true and examiners know it. And the real distinction is not the feature list — it is "is-a" against "can-do". A Dog is an Animal; a Dog can be Comparable.

Class vs Interface

A class is a blueprint that can be instantiated and holds state. An interface is a list of things a class promises to be able to do, and cannot be instantiated at all.

 ClassInterface
Instantiationnew ClassName() creates an object.Cannot be instantiated directly.
StateInstance variables with real values per object.Constants only.
Inheritanceextends exactly one class.implements any number of interfaces.
Method bodiesAll methods have bodies, unless the class is abstract.Abstract by default; default and static methods may have bodies.
PurposeDescribe what something is and does.Describe what something must be able to do.

Where people lose the marks

Java allows a class to implement many interfaces but extend only one class. That is the language's answer to the diamond problem of multiple inheritance, and saying so is usually worth a mark on its own.

Java vs JavaScript

They are unrelated languages with a shared marketing accident from 1995. The similarity ends at some of the syntax.

 JavaJavaScript
Type systemStatically typed — types are checked before the program runs.Dynamically typed — a variable holds whatever you last put in it.
Runs onThe JVM, after compilation to bytecode.A JavaScript engine — in a browser, or in Node.js on a server.
Compiled or interpretedCompiled to bytecode, then JIT-compiled at runtime.Interpreted, with heavy JIT optimisation.
ConcurrencyReal threads.Single-threaded with an event loop; workers for real parallelism.
Object modelClass-based.Prototype-based, with class syntax added as sugar in ES6.
Typical useBackend services, Android, large enterprise systems.Browsers, backend via Node, mobile via React Native.

Where people lose the marks

The line worth remembering: Java is to JavaScript as car is to carpet. The name was a 1995 marketing decision, nothing more.

print vs println

println moves to a new line after printing. print does not. That is the entire difference.

 print()println()
Cursor after printingStays on the same line.Moves to the start of the next line.
Newline characterNot added.Adds the platform's line separator.
Call with no argumentSystem.out.print() is a compile error.System.out.println() is legal and prints a blank line.
Use whenBuilding one line from several pieces.Finishing a line of output.

Where people lose the marks

Small, but it is a two-mark question in first-semester papers, and it is also the first thing that confuses people when their output all runs together on one line.

Multiple choice, with the reason

Universities set an objective section and campus written rounds are almost nothing else. The answer is marked, and every one of them says why — an answer key you can only memorise is worth nothing in a viva.

  1. 01

    Which of these makes Java platform independent?

    • aThe JDK
    • bBytecode and the JVM
    • cThe garbage collector
    • dThe compiler

    Why — javac produces bytecode, which is the same on every platform, and a platform-specific JVM executes it. The slogan is write once, run anywhere; the mechanism is this pair.

  2. 02

    Method overloading is resolved at:

    • aCompile time
    • bRun time
    • cClass loading time
    • dGarbage collection

    Why — The compiler picks the overload from the argument types it can see, so it is static or compile-time polymorphism. Overriding is the opposite — resolved at run time from the actual object.

  3. 03

    Why does Java not allow a class to extend more than one class?

    • aTo keep the compiler simple
    • bTo avoid the diamond problem of ambiguous inherited members
    • cBecause of the garbage collector
    • dIt does allow it

    Why — If two superclasses supplied the same method, the compiler could not choose. Interfaces give the same reach without the ambiguity, because historically they carried no implementation.

  4. 04

    What does comparing two Strings with == actually compare?

    • aTheir characters
    • bTheir lengths
    • cTheir references
    • dTheir hash codes

    Why — References. Two separately created Strings holding the same text are different objects, so == is false while equals() is true. String literals are pooled, which makes == appear to work and then fail later.

  5. 05

    Which catch block must come last?

    • acatch (ArithmeticException e)
    • bcatch (NullPointerException e)
    • ccatch (Exception e)
    • dThe order does not matter

    Why — The most general goes last. Put catch (Exception e) first and every later block is unreachable, which the compiler rejects outright. This is a standard find-the-error question.

  6. 06

    A class implementing Runnable must provide which method?

    • astart()
    • brun()
    • cexecute()
    • dcall()

    Why — run() holds the work; start() belongs to Thread and is what creates the new thread and then invokes run(). Calling run() directly executes it on the current thread, which is the trap.

  7. 07

    Which is true of an abstract class but not of an interface?

    • aIt can declare abstract methods
    • bIt can have a constructor and instance fields
    • cIt can be implemented by many classes
    • dIt can contain static methods

    Why — Only an abstract class has constructors and ordinary instance state. Both can declare abstract methods, and since Java 8 interfaces can hold default and static methods too — which is why the old answers to this question are now wrong.

  8. 08

    Which collection guarantees no duplicate elements?

    • aArrayList
    • bLinkedList
    • cHashSet
    • dArrayDeque

    Why — A Set stores each element once, using hashCode and equals to decide what counts as the same. That is also why a class used in a HashSet must override both correctly.

Viva questions, and what a good answer sounds like

GNDU’s own scheme says the viva runs one-to-one beside the practical exam, about the code you are writing at that moment. These are the questions that get asked, and what the examiner is listening for in the reply.

“What is the difference between the JDK, the JRE and the JVM?”

The JVM executes bytecode. The JRE is the JVM plus the standard libraries — enough to run a program. The JDK is the JRE plus the tools to compile one. Three nested boxes, JVM innermost.

“You wrote equals(). Did you write hashCode()?”

If not, the object misbehaves in a HashMap or HashSet — two objects that are equal land in different buckets. The contract is that equal objects must return the same hash code, and overriding one without the other breaks it.

“What is the difference between throw and throws?”

throw raises an exception at that point in the code. throws appears in the method signature and declares which checked exceptions the method may let escape to its caller.

“Why is String immutable?”

Safety and the string pool. Because it cannot change, the same literal can be shared, it can be used as a HashMap key without the hash going stale, and it can be passed between threads without a lock.

“Remove synchronized from your counter and tell me what happens.”

The final total comes out lower than expected, because count++ is read, add and write — three steps, and two threads can interleave between them so one update is lost. Being able to say that is the whole point of the practical.

“Where does your program use polymorphism?”

Point at the line where a parent-type reference holds a child object and the child's method runs. That is dynamic method dispatch, and naming it in your own code is worth more than reciting the definition.

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.

CallWhatsAppFree demo