CBSE Class 12 · IT 802 · Unit 3 Java · 2026-27

Class 12 IT 802 Java notes with 20 programs and output.

These Class 12 IT 802 Java notes take Unit 3 in the order CBSE prints it, from language elements to strings. Each topic gets a short explanation, then programs that show it working, with the output of a real run and the two or three points worth remembering.

Live online · 20 programs run on Java 21 · NetBeans steps · one to one at your hours · first class free

Start here

If you want Java taught, not only explained

The Java course for teens begins with a first program and carries on well past Unit 3. MySQL is the other language of 802, and the Class 11 and 12 course suits a student who studies computer science too.

Ans. The short version

Class 12 IT 802 Java notes cover Unit 3, which carries 20 of the 60 theory marks in 2026-27, plus 10 marks for a Java program in the practical. The unit lists language elements, operators, control flow, arrays, class design, exception handling, assertions, threads, wrapper classes and string manipulation. This page explains each topic and shows it in 20 original programs, every one compiled and run on Java 21. Modern Age Coders teaches the same topics in live one to one classes at your own timing, and you can try a full class through a priority demo first.

Q1. What is in the Java unit?

Java in Class 12 Information Technology 802: topics and programs

Unit 3 is the largest unit of the theory paper: 20 marks, with 30 hours of theory and 50 hours of lab work set aside for it. The syllabus names the topics below and does not divide the 20 marks among them.

Topic in the syllabusIn one linePrograms here
Introduction to Java, language elementsStructure of a program, types, variables, constants1, 2
OperatorsArithmetic, relational, logical, assignment, conditional3
Control flowif, switch, for, while, do-while, break, continue4 to 8
ArrayMany values of one type under one name9 to 11
Class design, object oriented programmingClasses, objects, constructors, inheritance12 to 14
Exception handlingDealing with errors while the program runs15, 16
AssertionsTesting that your own logic holds17
ThreadsTwo tasks in progress at once18
Wrapper classesObjects that hold primitive values19
String manipulationMethods of the String class20

Running these programs in NetBeans

Create a Java Application project, then add one Java class per program and give it the name that follows public class. NetBeans puts a package line at the top; leave it there. Press Shift and F6 to run the open file rather than the whole project. Two abbreviations save typing: psvm then Tab writes the main method, and sout then Tab writes a println.

How Java runs: the compiler javac turns .java source into .class bytecode, and the Java Virtual Machine executes the bytecode. The JRE is the JVM with its libraries; the JDK adds the compiler and other tools. Because only the JVM is written for each operating system, the same bytecode runs on all of them.

Q2. What are the basics?

Java notes for IT 802: language elements and operators

A variable is a named place in memory with a fixed type. Java has eight primitive types, and everything else, including String and arrays, is a reference type.

TypeSizeHolds
byte8 bits-128 to 127
short16 bits-32768 to 32767
int32 bitsup to 2147483647
long64 bitsbigger whole numbers, written 5L
float32 bitsdecimals, written 2.5f
double64 bitsdecimals, the usual choice
char16 bitsone Unicode character
booleannot fixedtrue or false
Operators, highest firstKind
++ -- !unary
* / %arithmetic
+ -arithmetic, joining text
< <= > >=relational
== !=equality
&&logical and
||logical or
?:conditional
= += -= *= /=assignment

An identifier may use letters, digits, the underscore and the dollar sign, may not begin with a digit and may not be a keyword. Class names begin with a capital and variable names with a small letter by convention.

Program 1: print, escape characters and joining

Show the difference between print and println, and between joining and adding.

FirstLook.java
public class FirstLook {
    /* Everything inside main runs
       from top to bottom. */
    public static void main(String[] args) {
        System.out.print("Unit");
        System.out.print(" 3: ");
        System.out.println("Java");
        System.out.println("He said \"compile first\".");
        System.out.println("Sum: " + 4 + 5);
        System.out.println("Sum: " + (4 + 5));
        System.out.println("Roll\tName\n7\tAfreen");
    }
}
Outputone run
Unit 3: Java
He said "compile first".
Sum: 45
Sum: 9
Roll	Name
7	Afreen
  • "Sum: " + 4 + 5 joins from left to right, so it prints 45. Brackets force the addition first.
  • \t is a tab, \n a new line, \" a quotation mark inside text.

Program 2: data types, constants and type casting

Print the limits of some types and convert between types.

TypeTour.java
public class TypeTour {
    public static void main(String[] args) {
        System.out.println("byte  " + Byte.MIN_VALUE
                + " to " + Byte.MAX_VALUE);
        System.out.println("short " + Short.MIN_VALUE
                + " to " + Short.MAX_VALUE);
        System.out.println("int   max " + Integer.MAX_VALUE);

        final int OVERS = 20;          // a constant
        long balls = OVERS * 6;        // int to long, automatic
        int whole = (int) 8.97;        // double to int, cast
        byte small = (byte) 130;       // does not fit
        char next = (char) ('P' + 1);

        System.out.println("balls " + balls);
        System.out.println("whole " + whole);
        System.out.println("small " + small);
        System.out.println("next  " + next);
        System.out.println("'P' as int " + (int) 'P');
    }
}
Outputone run
byte  -128 to 127
short -32768 to 32767
int   max 2147483647
balls 120
whole 8
small -126
next  Q
'P' as int 80
  • A wider type accepts a narrower one without a cast. The other way round needs a cast and may lose data.
  • (byte) 130 wraps round to -126, because a byte stops at 127.
  • final makes a constant: assigning to it again is a compile error.

Program 3: operators

Predict each line before you read the output.

OperatorTour.java
public class OperatorTour {
    public static void main(String[] args) {
        int a = 9, b = 4;
        System.out.println(a / b + " " + a % b + " "
                + (double) a / b);
        System.out.println(-a % b);

        int c = a++;                   // use, then add
        int d = ++b;                   // add, then use
        System.out.println(a + " " + b + " " + c + " " + d);

        a += 2.9;                      // cast hidden inside
        System.out.println(a);

        int zero = 0;
        boolean safe = zero != 0 && 10 / zero > 1;
        System.out.println(safe);

        String size = a > 10 ? "big" : "small";
        System.out.println(size);
        System.out.println(6 + 3 * 2 - 8 / 4);
    }
}
Outputone run
2 1 2.25
-1
10 5 9 5
12
false
big
10
  • The remainder takes the sign of the left number, so -9 % 4 is -1.
  • && stops at the first false, so the division by zero never happens.
  • a += 2.9 hides a cast: 10 + 2.9 becomes 12.

Q3. How do I control and repeat?

Control flow and array programs in Java for Class 12 IT 802

Selection statements choose, loops repeat, and an array gives a loop something to walk through. A for loop fits a known count, while fits an unknown one, and do-while fits a body that must run once before the test.

Program 4: if, else if and logical operators

Classify a triangle from three sides.

TriangleType.java
import java.util.Scanner;

public class TriangleType {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Three sides: ");
        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();

        if (p + q <= r || q + r <= p || p + r <= q) {
            System.out.println("Not a triangle");
        } else if (p == q && q == r) {
            System.out.println("Equilateral");
        } else if (p == q || q == r || p == r) {
            System.out.println("Isosceles");
        } else {
            System.out.println("Scalene");
        }
    }
}
Outputtwo runs
Three sides: 7 7 10
Isosceles

Three sides: 3 4 9
Not a triangle
  • The impossible case is tested first; after it, every later branch can trust the data.
  • Order matters: an equilateral triangle would also pass the isosceles test.

Program 5: switch with grouped cases

Print the number of days in a month of an ordinary year.

MonthDays.java
import java.util.Scanner;

public class MonthDays {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Month (1-12): ");
        int month = sc.nextInt();
        int days;

        switch (month) {
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                days = 28;             // 29 in a leap year
                break;
            default:
                days = 31;
        }
        if (month < 1 || month > 12) {
            System.out.println("Invalid month");
        } else {
            System.out.println(days + " days");
        }
    }
}
Outputtwo runs
Month (1-12): 9
30 days

Month (1-12): 13
Invalid month
  • Cases without break fall through on purpose, so 4, 6, 9 and 11 share one line.
  • default also catches 13, which is why the range is tested before printing.

Program 6: nested for loops

Print a triangle of multiples.

TimesTriangle.java
public class TimesTriangle {
    public static void main(String[] args) {
        int rows = 5;
        for (int r = 1; r <= rows; r++) {
            for (int c = 1; c <= r; c++) {
                System.out.print(r * c + " ");
            }
            System.out.println();
        }
    }
}
Outputone run
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 
  • The inner loop runs r times, so 1 + 2 + 3 + 4 + 5 = 15 numbers are printed.
  • print stays on the line; the empty println ends the row.

Program 7: while loop

Find the HCF of two numbers by repeated remainders.

CommonDivisor.java
public class CommonDivisor {
    public static void main(String[] args) {
        int big = 1071, small = 462;

        while (small != 0) {
            int left = big % small;
            System.out.println(big + " % " + small
                    + " = " + left);
            big = small;
            small = left;
        }
        System.out.println("HCF is " + big);
    }
}
Outputone run
1071 % 462 = 147
462 % 147 = 21
147 % 21 = 0
HCF is 21
  • The divisor becomes the next dividend. When the remainder is 0, the last divisor is the HCF.
  • Three remainders are enough for 1071 and 462; trying every number would need hundreds of steps.

Program 8: do-while, break and continue

Accept a limit of at least 2 and list the primes up to it.

PrimeList.java
import java.util.Scanner;

public class PrimeList {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int limit;
        do {
            System.out.print("Limit (2 or more): ");
            limit = sc.nextInt();
        } while (limit < 2);

        int found = 0;
        for (int n = 2; n <= limit; n++) {
            boolean prime = true;
            for (int d = 2; d * d <= n; d++) {
                if (n % d == 0) {
                    prime = false;
                    break;             // leaves the inner loop
                }
            }
            if (!prime) {
                continue;              // next n
            }
            System.out.print(n + " ");
            found++;
        }
        System.out.println("\n" + found + " primes");
    }
}
Outputone run
Limit (2 or more): 1
Limit (2 or more): 30
2 3 5 7 11 13 17 19 23 29 
10 primes
  • do-while suits checking input: ask first, test afterwards.
  • d * d <= n is enough, since a factor above the square root has a partner below it.
  • break ends the inner loop; continue moves on to the next n.

Arrays in four sentences

An array is created with new int[5] or with a list in braces, and its size cannot change afterwards. Indexes run from 0 to length - 1; anything else throws ArrayIndexOutOfBoundsException. New elements start as 0, 0.0, false or null according to type. length has no brackets for an array but is a method, length(), for a String.

Program 9: one-dimensional array

Find the two largest different values without sorting.

SecondLargest.java
public class SecondLargest {
    public static void main(String[] args) {
        int[] runs = {38, 71, 12, 71, 64, 5};
        int first = Integer.MIN_VALUE;
        int second = Integer.MIN_VALUE;

        for (int r : runs) {
            if (r > first) {
                second = first;
                first = r;
            } else if (r > second && r != first) {
                second = r;
            }
        }
        System.out.println("Largest " + first);
        System.out.println("Second  " + second);
    }
}
Outputone run
Largest 71
Second  64
  • The old largest becomes second before it is replaced.
  • r != first keeps the repeated 71 out of second place.

Program 10: bubble sort with a method

Sort an array in ascending order and show every pass.

SortLevels.java
public class SortLevels {
    static void show(int[] data) {
        for (int value : data) {
            System.out.print(value + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] level = {44, 18, 30, 9, 25};
        for (int pass = 1; pass < level.length; pass++) {
            for (int i = 0; i < level.length - pass; i++) {
                if (level[i] > level[i + 1]) {
                    int temp = level[i];
                    level[i] = level[i + 1];
                    level[i + 1] = temp;
                }
            }
            System.out.print("Pass " + pass + ": ");
            show(level);
        }
    }
}
Outputone run
Pass 1: 18 30 9 25 44 
Pass 2: 18 9 25 30 44 
Pass 3: 9 18 25 30 44 
Pass 4: 9 18 25 30 44 
  • Each pass moves the largest remaining value to the end.
  • Pass 4 changes nothing here, yet the loop does not know that.
  • show() receives a reference to the same array, not a copy of it.

Program 11: two-dimensional array

Turn rows into columns.

Transpose.java
public class Transpose {
    public static void main(String[] args) {
        int[][] seats = {{11, 12, 13, 14}, {21, 22, 23, 24}};
        int rows = seats.length;
        int cols = seats[0].length;
        int[][] turned = new int[cols][rows];

        for (int r = 0; r < rows; r++) {
            for (int c = 0; c < cols; c++) {
                turned[c][r] = seats[r][c];
            }
        }
        for (int[] row : turned) {
            for (int value : row) {
                System.out.print(value + " ");
            }
            System.out.println();
        }
    }
}
Outputone run
11 21 
12 22 
13 23 
14 24 
  • 2 rows and 4 columns become 4 rows and 2 columns.
  • seats.length counts rows; seats[0].length counts columns.

If tracing loops is the slow part, the Class 10 board has good short exercises on the same Java: try our Java output questions.

Q4. What is class design?

Object oriented programming notes: classes, constructors, inheritance

A class describes what an object knows and can do; an object is one such thing in memory. Designing a class means choosing its data, its constructors, its methods and how much of it others may touch.

Encapsulation

Data and the methods that use it are kept together, with the data private. Outsiders call a method, and the method can refuse.

Inheritance

A child class extends a parent and starts with its members. Java allows one parent class, and super reaches it.

Polymorphism

One name, several forms: overloading is settled while compiling, overriding while the program runs.

AccessSame classSame packageChild in another packageAnywhere
privateyesnonono
(none written)yesyesnono
protectedyesyesyesno
publicyesyesyesyes

Program 12: constructors and method overloading

Create objects in three ways and call an overloaded method.

BookDemo.java
class Book {
    String title;
    int copies;

    Book() {
        this("Untitled", 0);           // calls the other one
    }

    Book(String title) {
        this(title, 1);
    }

    Book(String title, int copies) {
        this.title = title;
        this.copies = copies;
    }

    void issue() {
        copies--;
    }

    void issue(int n) {                // overloaded method
        copies -= n;
    }
}

public class BookDemo {
    public static void main(String[] args) {
        Book x = new Book();
        Book y = new Book("Monsoon Maths");
        Book z = new Book("River Atlas", 12);
        y.issue();
        z.issue(5);
        System.out.println(x.title + " " + x.copies);
        System.out.println(y.title + " " + y.copies);
        System.out.println(z.title + " " + z.copies);
    }
}
Outputone run
Untitled 0
Monsoon Maths 0
River Atlas 7
  • A constructor has the class name and no return type, not even void.
  • this(...) calls another constructor and must be the first statement.
  • The compiler picks issue() or issue(int) from the arguments.

Program 13: encapsulation

Keep the balance private and allow changes only through methods.

MetroCardDemo.java
class MetroCard {
    private double balance;

    public double getBalance() {
        return balance;
    }

    public void recharge(double amount) {
        if (amount >= 100) {
            balance += amount;
        } else {
            System.out.println("Minimum recharge is 100");
        }
    }

    public boolean travel(double fare) {
        if (fare > balance) {
            return false;
        }
        balance -= fare;
        return true;
    }
}

public class MetroCardDemo {
    public static void main(String[] args) {
        MetroCard card = new MetroCard();
        card.recharge(60);
        card.recharge(150);
        System.out.println("Trip 1: " + card.travel(42.5));
        System.out.println("Trip 2: " + card.travel(120));
        System.out.println("Left: " + card.getBalance());
    }
}
Outputone run
Minimum recharge is 100
Trip 1: true
Trip 2: false
Left: 107.5
  • No code outside the class can write card.balance = 9000: the compiler reports private access.
  • A field with no starting value is 0.0. A local variable gets no such default.

Program 14: abstract class and polymorphism

Call the same method on objects of two child classes.

StaffDemo.java
abstract class Staff {
    protected String name;

    Staff(String name) {
        this.name = name;
    }

    abstract double pay();

    void slip() {
        System.out.println(name + ": " + pay());
    }
}

class Librarian extends Staff {
    Librarian(String name) {
        super(name);
    }

    double pay() {
        return 31000;
    }
}

class Coach extends Staff {
    private int sessions;

    Coach(String name, int sessions) {
        super(name);
        this.sessions = sessions;
    }

    double pay() {
        return sessions * 850.0;
    }
}

public class StaffDemo {
    public static void main(String[] args) {
        Staff[] team = {new Librarian("Zoya"),
            new Coach("Arnav", 24)};
        for (Staff member : team) {
            member.slip();
        }
    }
}
Outputone run
Zoya: 31000.0
Arnav: 20400.0
  • Staff cannot be instantiated; it only promises that each child has pay().
  • protected lets child classes use name.
  • The loop does not ask which kind of object it has. Java calls the right pay().

Constructors deserve a second reading, since default, parameterised and copy constructors are easy to mix up: see Java constructors explained.

Q5. How are errors and threads handled?

Exception handling, assertions and threads in Java: notes and programs

An exception is an object Java creates when something goes wrong at run time. Put the risky line in try, the remedy in catch, and work that must always happen in finally.

ExceptionA line that causes it
ArithmeticException10 / 0 with integers
ArrayIndexOutOfBoundsExceptionindex 5 in an array of 5
StringIndexOutOfBoundsException"abc".charAt(5)
NumberFormatExceptionInteger.parseInt("ab")
NullPointerExceptiona method called on a variable that is null
ClassCastExceptioncasting a String object to Integer

All six are unchecked: the compiler does not force you to catch them. Checked exceptions, such as InterruptedException from sleep(), must be caught or declared. An error that stops compilation is not an exception at all.

Program 15: several catch blocks and finally

Handle a missing index, text that is not a number, and zero.

ReadMarks.java
public class ReadMarks {
    static void read(String[] data, int index) {
        try {
            int value = Integer.parseInt(data[index]);
            System.out.println("Share: " + 100 / value);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("No entry at " + index);
        } catch (NumberFormatException e) {
            System.out.println("Not a number: " + data[index]);
        } catch (ArithmeticException e) {
            System.out.println("Zero is not allowed");
        } finally {
            System.out.println("-- checked " + index);
        }
    }

    public static void main(String[] args) {
        String[] data = {"8", "ab", "0"};
        for (int i = 0; i <= 3; i++) {
            read(data, i);
        }
    }
}
Outputone run
Share: 12
-- checked 0
Not a number: ab
-- checked 1
Zero is not allowed
-- checked 2
No entry at 3
-- checked 3
  • Four calls, four endings, and finally runs each time.
  • 100 / 8 is 12 because both are integers.

Program 16: throw and throws

Raise an exception for a rule of your own.

RideCheck.java
public class RideCheck {
    static int ticket(int heightCm) throws Exception {
        if (heightCm < 120) {
            throw new Exception("Too short by "
                    + (120 - heightCm) + " cm");
        }
        return heightCm >= 150 ? 80 : 50;
    }

    public static void main(String[] args) {
        int[] queue = {155, 112, 131};
        for (int h : queue) {
            try {
                System.out.println(h + " cm pays " + ticket(h));
            } catch (Exception e) {
                System.out.println(h + " cm: " + e.getMessage());
            }
        }
    }
}
Outputone run
155 cm pays 80
112 cm: Too short by 8 cm
131 cm pays 50
  • throw raises one exception; throws in the heading warns the caller.
  • Exception is checked, so Java insists that the call is inside try or declared.

Program 17: assertions

Test a fact that must be true, first with assertions off and then on.

SplitCheck.java
public class SplitCheck {
    public static void main(String[] args) {
        int sweets = 50, children = 8;
        int each = sweets / children;
        int left = sweets - each * children;
        assert left >= 0 && left < children : "left is " + left;
        System.out.println(each + " each, " + left + " left");

        left = left + children;        // wrong on purpose
        assert left < children : "left is " + left;
        System.out.println("Never checked: " + left);
    }
}
Outputtwo runs
6 each, 2 left
Never checked: 10

6 each, 2 left
Exception in thread "main" java.lang.AssertionError: left is 10
	at SplitCheck.main(SplitCheck.java:10)
  • assert condition : message; does nothing until Java is started with -ea.
  • Use it for your own logic, never for user input, because it can be switched off.

Thread methods to know

start() begins a thread, run() holds its work, sleep(ms) pauses the current thread, join() waits for another to end, and getName() and setPriority() do what they say. There are two ways to make one: extend Thread, or implement Runnable and hand the object to a Thread. The second leaves your class free to extend something else.

Program 18: threads with Runnable

Run two tasks together and wait for both.

TwoClocks.java
class Ticker implements Runnable {
    private int gap;

    Ticker(int gap) {
        this.gap = gap;
    }

    public void run() {
        String me = Thread.currentThread().getName();
        for (int i = 1; i <= 3; i++) {
            System.out.println(me + " " + i);
            try {
                Thread.sleep(gap);
            } catch (InterruptedException e) {
                System.out.println(me + " stopped");
            }
        }
    }
}

public class TwoClocks {
    public static void main(String[] args) throws Exception {
        Thread slow = new Thread(new Ticker(900), "slow");
        Thread fast = new Thread(new Ticker(250), "fast");
        System.out.println("Before start: " + slow.getState());
        slow.start();
        Thread.sleep(100);             // let slow print first
        fast.start();
        slow.join();
        fast.join();
        System.out.println("After join: " + slow.getState());
    }
}
Outputone run
Before start: NEW
slow 1
fast 1
fast 2
fast 3
slow 2
slow 3
After join: TERMINATED
  • The task goes in run(); start() creates the thread that executes it.
  • A thread is NEW before start and TERMINATED after it ends.
  • On your computer the middle lines may come in another order.

Q6. Which methods should I know?

Wrapper classes and string manipulation: Class 12 IT 802 notes

Every primitive type has a wrapper class: Byte, Short, Integer, Long, Float, Double, Character and Boolean. A String is an immutable sequence of characters with a long list of methods.

Program 19: wrapper classes

Box, unbox, parse and test characters.

WrapperTour.java
public class WrapperTour {
    public static void main(String[] args) {
        Integer boxed = 45;            // autoboxing
        int plain = boxed + 5;         // unboxing
        System.out.println(plain);

        int seats = Integer.parseInt("120");
        double fare = Double.parseDouble("18.75");
        System.out.println(seats * fare);

        System.out.println(Integer.valueOf(7).equals(7));
        System.out.println(Integer.toBinaryString(26));
        System.out.println(Integer.compare(3, 9));
        System.out.println(boxed.doubleValue());
        System.out.println(Boolean.parseBoolean("TRUE"));

        String code = "Gate 4B";
        int letters = 0, digits = 0;
        for (int i = 0; i < code.length(); i++) {
            char ch = code.charAt(i);
            if (Character.isLetter(ch)) letters++;
            if (Character.isDigit(ch)) digits++;
        }
        System.out.println(letters + " letters, "
                + digits + " digit");
    }
}
Outputone run
50
2250.0
true
11010
-1
45.0
true
5 letters, 1 digit
  • Autoboxing turns an int into an Integer; unboxing turns it back.
  • parseInt gives a primitive, valueOf gives an object.
  • Compare two Integer objects with equals(), not with ==.

String methods, tried on one word

Here s is "Information". Cover the right column and fill it yourself.

CallResult
s.length()11
s.charAt(2)f
s.indexOf('o')3
s.lastIndexOf('o')9
s.substring(5)mation
s.substring(2, 6)form
s.toUpperCase()INFORMATION
s.replace('n', 'N')INformatioN
CallResult
s.equals("information")false
s.equalsIgnoreCase("INFORMATION")true
"cat".compareTo("cow")-14, that is 'a' minus 'o'
s.contains("form")true
s.startsWith("In")true
s.endsWith("on")true
s.concat(" Tech")Information Tech
s.indexOf("zz")-1

Program 20: string manipulation

Shorten a full name to initials and surname.

ShortName.java
import java.util.Scanner;

public class ShortName {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Full name: ");
        String full = sc.nextLine().trim().toLowerCase();

        String[] words = full.split(" +");  // 1 or more spaces
        String result = "";
        for (int i = 0; i < words.length; i++) {
            char first = words[i].charAt(0);
            first = Character.toUpperCase(first);
            if (i < words.length - 1) {
                result = result + first + ". ";
            } else {
                result = result + first
                        + words[i].substring(1);
            }
        }
        System.out.println(result);
        System.out.println(result.length() + " characters");
    }
}
Outputone run
Full name: kamala   devi RATHORE
K. D. Rathore
13 characters
  • Strings do not change: every method returns a new one, so the result has to be stored.
  • split(" +") treats several spaces as one gap.
  • substring(1) is everything after the first character.

Longer practice sets: string handling in Java and string and array programs.

Q7. Why will my program not compile?

Java error messages and what they mean

Read the first message and ignore the rest until it is fixed, because one missing character can produce a page of red. These are the exact messages Java 21 gave for ten deliberate mistakes.

MessageWhat we wroteCure
';' expectedint a=5Add the semicolon
package system does not existsystem.out.printlnCapital S in System
incompatible types: possible lossy conversion from double to intint a=7.5;Use double, or cast
missing return statementreturn only inside an ifReturn on every path
variable t might not have been initializedint t; t++;Give t a starting value
class Wrong is public, should be declared in a file named Wrong.javafile saved as E6.javaMatch class and file name
unreported exception Exception; must be caught or declared to be thrownthrow new Exception("x");try and catch, or throws
cannot assign a value to final variable Afinal int A=2; A=3;Remove final or the second line
Z is abstract; cannot be instantiatednew Z()Create a child class object
b has private access in E10private field used outsideUse a public method

A way to study this page in ten sittings

  1. Sitting 1 to 3: programs 1 to 8

    Type them, then change one line in each and say the new output before running.

  2. Sitting 4 and 5: arrays

    Write programs 9 to 11 again with your own data and no help.

  3. Sitting 6 and 7: classes

    Design a class for something you own, with two constructors and one method that can refuse.

  4. Sitting 8: exceptions and assertions

    Make every exception in the table happen once on purpose.

  5. Sitting 9 and 10: threads, wrappers, strings

    Fill the string table from memory, then write one program of 15 lines under a timer.

When the topics feel steady, put them in the file: the 802 practical file and NetBeans project. Definitions from the other units are in the IT 802 notes, the full marks table in the IT 802 syllabus, and exam practice in the IT 802 sample paper.

One to one, at your own timing

Learn Unit 3 with a teacher watching you code

Reading Java is easier than writing it, and a single class will show the gap. Book a priority demo, a paid full class at a slot of your choice: a written skill report follows, and what you paid is taken off the first month if you join. There is also a free demo class. Lessons after that are private, on days you pick.

Before you enrol · Try a class

Priority demo, at a slot you pick

a full live class of about 45 to 60 minutes

  • Your child predicts the output of three short programs
  • One program from Unit 3 is written from nothing in NetBeans
  • The errors are read aloud and fixed by your child, not by us
  • A report sorts the ten topics into steady, shaky and not begun
Book a priority demo

The classes · Choose your own timing

Personalised one to one

₹4,999

per month, 4 private classes, fully flexible timing

  • Start at the topic where your child gets lost, not at chapter one
  • Each class has written theory answers as well as code
  • Lab programs practised against the clock before the practical
  • Monthly billing, no admission fee, and no lock-in past the month
Ask for a personalised plan

Students who met Java in Class 11 usually need classes and exceptions most. Those new to it begin with program 1 and need longer. Say which you are, and the fee shown above is what one month costs.

Studying outside India?

Java classes for 802 students abroad

A private class needs only an hour that is free at both ends. The table shows the time difference and when students in each place are normally home.

Where you liveTime differenceUsual class window, local timeFormat
India
every Indian city
Indian timeAny time you choosePersonalised 1-on-1
UAE and Oman
Dubai, Abu Dhabi, Sharjah, Muscat
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Saudi Arabia, Qatar, Kuwait, Bahrain
Riyadh, Jeddah, Dammam, Doha, Kuwait City, Manama
2 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Nepal
Kathmandu
15 min ahead of India4:30 PM to 9:00 PMPersonalised 1-on-1
Ethiopia and East Africa
Addis Ababa and East Africa Time
2 h 30 min behind India4:30 PM to 9:00 PMPersonalised 1-on-1
Singapore and Malaysia
Singapore, Kuala Lumpur
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

NetBeans and the JDK are free to install, so a student anywhere can share the same screen as the teacher. If 802 is still a choice for you and not yet a subject, read how CS, IP, AI and IT compare.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 12 series

More IT 802 pages for Class 12

Every page in the CBSE Class 12 Information Technology series, grouped by what you need.

Java questions

Questions on Class 12 IT 802 Java notes and programs

How many marks does Java carry in Class 12 IT 802?

Unit 3, Java, carries 20 of the 60 theory marks in 2026-27. In the practical a Java program carries 10 marks, the practical file of 10 marks must include at least 15 Java programs, and the 5-mark project is an application made in NetBeans. Java is the biggest single part of the subject.

What topics are in the Java unit of IT 802 Class 12?

Fundamentals of Java programming, introduction to Java, object oriented programming, Java language elements, operators, control flow, array, class design, exception handling, assertions, threads, wrapper classes and string manipulation. That is the list in the 2026-27 curriculum, and this page has at least one program for each.

Where can I get Class 12 IT 802 Java notes PDF?

Use Print in your browser on this page and choose Save as PDF. You get the notes, tables and all 20 programs. Better still, type the programs as you read; a page you have typed stays in memory longer than one you have saved.

Which Java programs are asked in the IT 802 practical?

The school and examiner choose, so there is no published list. Since the lab asks for one Java program worth 10 marks, practise a loop program, an array program, a class with a constructor, a program with try and catch, and a string program. Write those five unaided and you have used the main statements of the unit.

Is Java difficult for a student who knows only Python?

The ideas carry over; the writing changes. Java needs a class around everything, a type for each variable, semicolons and braces. Expect a week of compile errors, then it settles. Classes, threads and assertions are usually the new topics.

What is the difference between a constructor and a method in Java?

A constructor has the same name as its class, has no return type and runs once when an object is created with new. A method can have any name, must state a return type or void, and runs whenever it is called. If you write no constructor, Java supplies one without parameters.

What are wrapper classes in Java?

Wrapper classes are classes that hold a primitive value as an object: Integer for int, Double for double, Character for char, and so on for all eight types. They also carry useful methods, such as Integer.parseInt to convert text into a number and Character.isDigit to test a character.

What is an assertion in Java and how do I enable it?

An assertion is a statement that a condition must be true, written with the keyword assert. If it is false, Java throws AssertionError. Assertions are off by default. Start Java with the option -ea, or in NetBeans add -ea under Run in the project properties, in the VM options box.

What is the difference between throw and throws?

throw is used inside a method to raise one exception object at that moment. throws is written in the method heading to declare which exceptions may come out of it, so that the caller handles them. One is an action; the other is a warning.

Is string comparison with == wrong in Java?

For content, yes. The == operator asks whether two variables refer to the same object, and equals() asks whether the characters are the same. Two literals may share one object and make == look correct, which is why the mistake hides until a value comes from the keyboard.

Do I need JavaFX, collections or JDBC for IT 802?

They are not named in the Class 12 unit list for 2026-27. NetBeans forms are needed for the project, and those use Swing controls such as jButton and jTextField, which appear in the Class 11 syllabus. Learn extra topics for interest once Unit 3 is secure.

Can I learn Java for IT 802 online, one to one?

Yes. Our classes are live and private, on the days and at the hour you choose, and the student writes the code on a shared screen. Try a priority demo or the free demo class before deciding. Billing is monthly and you may stop at any month end.

Start

Write one Java program with us

Choose a topic that makes you nervous, whether it is arrays, constructors or threads. In the demo class you write a short program on it, we talk about each error as it appears, and at the end you know how much of Unit 3 is ready.

For a slot you pick yourself there is the priority demo: a paid full class, a written skill report after it, and the fee adjusted against the first month for those who enrol.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here