⚡FREE AI Live Master Session: Teach AI to See! Build Your Own AI Image Classifier

    Register for Free →
    HomeClass 12 IT (802)Unit 3: Java Programming
    CBSE Class 12 IT (802) • Unit 320 Marks Theory + 10 Marks Practical80 Instructional Hours (30T + 50P)

    Unit 3: Fundamentals of Java ProgrammingOOP Class Design, NetBeans, JDBC & Exception Handling

    Exhaustive, board-aligned notes based on Pages 81–143 of the CBSE Class XII Student Handbook. Master Java bytecode & JVM architecture, NetBeans IDE project creation, control flow statements, 1D arrays, OOP class construction, access modifiers, Scanner & String libraries, JDBC MySQL connectivity, multithreading, and solved programming lab exercises.

    Quick Revision Box • High-Yield Board Summary
    Bytecode & JVM (WORA)Java compiler compiles code into intermediate Bytecode (.class files), which any OS running a Java Virtual Machine (JVM) translates into native machine code.
    OOP Pillars in JavaEncapsulation: Private data members + Public getters/setters. Inheritance: extends keyword. Polymorphism: Overloading & overriding. Constructors: Same name as class, no return type.
    JDBC MySQL Pipeline1) DriverManager.getConnection(), 2) conn.createStatement(), 3) stmt.executeQuery(), 4) ResultSet.next(), wrapped in try-catch (SQLException).
    Section 3.1 - 3.3

    Java Architecture, Primitive Types & NetBeans Project Setup

    In Java, all executable code is contained inside classes. The main method (public static void main(String[] args)) is the mandatory entry point for every standalone application.

    8 Java Primitive Data Types (Table 1, Page 93)

    Data TypeKind of ValueMemory SizeExample Value
    byteInteger8-bit100
    shortInteger16-bit5000
    intInteger32-bit56789
    longInteger64-bit9876543210L
    floatFloating Point32-bit3.14f
    doubleFloating Point64-bit346.75
    charCharacter (Unicode)16-bit'M'
    booleanLogical Truth1-bittrue / false
    Section 3.4

    Control Flow: Selection Structures & Loops

    Selection: if-else & switch

    if-else evaluates boolean conditions. switch matches an expression against constant case values using break to terminate fall-through.

    switch (today) {

      case 1: day = "Monday"; break;

      case 5: day = "Friday"; break;

      default: day = "Incorrect Day!"; break;

    }

    Comparison: while vs do-while (Table 6, Page 104)
    while LOOPdo-while LOOP
    Entry-controlled loop (tests condition prior to body)Exit-controlled loop (tests condition after body)
    Runs 0 or more times (may never execute body)Always runs once or more (at least once)
    No semicolon after while conditionRequires semicolon after while (cond);
    Section 3.7 & 3.8

    Object-Oriented Programming (OOP) & Class Design (The Book Class)

    A Class is a template/blueprint representing a real-world entity with state (attributes) and behavior (methods). An Object is a concrete instance instantiated using new.

    // Complete Book.java Class with Encapsulation & Constructors (Pages 115-119)

    package javaprograms;


    public class Book {

      // Private data members (Encapsulation)

      private String title;

      private String author;

      private String publisher;

      private String genre;

      private double price;


      // Parameterized Constructor

      public Book(String t, String a, String pub, String g, double p) {

        title = t; author = a; publisher = pub; genre = g; price = p;

      }


      // Controlled Getter & Setter methods

      public double getPrice() { return price; }

      public void setPrice(double newprice) {

        if (newprice < 100) {

          System.out.println("Price cannot be set lower than 100!");

        } else {

          price = newprice;

        }

      }


      public void display() {

        System.out.println("Title: " + title + " | Author: " + author + " | Price: " + price);

      }

    }

    Section 3.11

    Java Database Connectivity (JDBC) with MySQL Server

    JDBC (Java Database Connectivity) allows Java applications to execute SQL queries on relational databases. In NetBeans, configure the MySQL connection under the Services tab and add mysql-connector-java-bin.jar to the project libraries.

    // MySQLDemo.java - Complete JDBC Query Pipeline (Page 136)

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.Statement;

    import java.sql.ResultSet;

    import java.sql.SQLException;


    public class MySQLDemo {

      public static void main(String[] args) {

        String dbURL = "jdbc:mysql://localhost:3306/bookstore";

        String username = "root";

        String password = "password";


        try {

          // 1. Establish connection

          Connection dbCon = DriverManager.getConnection(dbURL, username, password);

          // 2. Create Statement

          Statement stmt = dbCon.createStatement();

          // 3. Execute query

          String query = "SELECT * FROM book";

          ResultSet rs = stmt.executeQuery(query);


          // 4. Iterate over rows

          while (rs.next()) {

            for (int i = 1; i <= 5; i++) {

              System.out.print(rs.getString(i) + " | ");

            }

            System.out.println();

          }

          dbCon.close();

        } catch (SQLException ex) {

          System.out.println("Database Error: " + ex.getMessage());

        }

      }

    }

    Section 3.12

    Advanced Java: Assertions, Threads & Wrapper Classes

    1. Assertions (-ea)

    States conditions that must be true during execution. Used for debugging. Throws AssertionError if false. Enabled via -ea VM flag.

    assert age >= 18 : "Age not Valid";
    2. Multithreading

    Executes tasks concurrently. Created either by extending Thread or by implementing Runnable and overriding run(). Started using t.start().

    3. Wrapper Classes

    Wraps primitives into objects (Integer, Double, Boolean). Supports parsing: Integer.parseInt("345") and toString().

    Board Exam Practice • 10 Questions

    Official Unit 3 Practice Questions

    Q1. Why are compiled Java programs platform independent?

    Q2. What is the memory size and storage capability of the 'int' primitive data type in Java?

    Q3. What is the fundamental difference in execution count between a 'while' loop and a 'do-while' loop?

    Q4. What exception is thrown at runtime if a program attempts to access an array of size 5 at index 5?

    Q5. Which of the following is true regarding a Constructor method in Java?

    Q6. Which access modifier must be applied to class data members to enforce encapsulation and hide internal data from outside modification?

    Q7. Before executing Arrays.binarySearch() to search for an element, what prerequisite condition must be met?

    Q8. Which method of the DriverManager class is invoked to establish a connection to a MySQL database in JDBC?

    Q9. What command-line VM flag must be passed to the Java runtime to enable assertions at execution time?

    Q10. What are the two official ways to create a multi-threaded program in Java?

    Frequently Asked Questions

    Unit 3 Java Programming FAQs (AEO & Board Focus)

    Score 100/100 in Class 12 Java & Practical Lab

    TeacherColab provides 1-on-1 personalized tutoring for Java OOP NetBeans projects, JDBC database connectivity, and board viva voce prep.