Curriculum
Course: Grade XII IT (802)
Login
Text lesson

Ch-3 Java Programming

School Revise · Class 12 Information Technology · Chapter 3

Java Programming

Code 802, Class 12. Java builds real programs with methods, arrays and classes. Here we go further with functions, arrays and objects.

method

reusable code

class

builds objects

What this chapter is about

We build on Java basics with methods that we call, arrays that hold many values, and simple classes and objects.

1. Methods

A method is a named block of code. It can take values (parameters) and return a result, so we can reuse it.

static int add(int a, int b) { return a + b; } // call: add(5, 3) gives 8

2. Arrays

An array holds many values of the same type, read by index. int[] marks = {80, 90, 70}; and marks[0] is the first value.

3. Classes and objects

A class is a blueprint with data and methods. An object is made from a class with new, and we call its methods with a dot.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

[sr_g12_it802 id=”g12-it802-ch3″]

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Write a method that adds two numbers.

SOLUTION

static int add(int a, int b) { return a + b; } // System.out.println(add(5, 3));

OUTPUT

8
Problem 2. Declare and print an array.

SOLUTION

int[] marks = {80, 90, 70}; System.out.println(marks[1]);

OUTPUT

90
Problem 3. Loop through an array.

SOLUTION

int[] a = {1, 2, 3}; for (int i = 0; i < a.length; i++) System.out.println(a[i]);

OUTPUT

1 2 3
Problem 4. Find the sum of an array.

SOLUTION

int[] a = {10, 20, 30}; int s = 0; for (int x : a) s = s + x; System.out.println(s);

OUTPUT

60
Problem 5. Find the largest in an array.

SOLUTION

int[] a = {3, 9, 5}; int big = a[0]; for (int x : a) if (x > big) big = x; System.out.println(big);

OUTPUT

9
Problem 6. Write a method that checks even.

SOLUTION

static boolean isEven(int n) { return n % 2 == 0; } // isEven(8)

OUTPUT

true
Problem 7. Use a String method.

SOLUTION

String s = “School”; System.out.println(s.length());

OUTPUT

6
Problem 8. Convert to uppercase.

SOLUTION

String s = “java”; System.out.println(s.toUpperCase());

OUTPUT

JAVA
Problem 9. Print the factorial of 5.

SOLUTION

int f = 1; for (int i = 1; i <= 5; i++) f = f * i; System.out.println(f);

OUTPUT

120
Problem 10. A simple class with a method.

SOLUTION

class Student { void hello() { System.out.println(“Hi”); } } // Student s = new Student(); s.hello();

OUTPUT

Hi

Practice set A, multiple choice

1. A named block of reusable code is a …

method.

2. Which holds many values of the same type?

An array.

3. Which keyword makes an object?

new.

4. array.length gives the …

number of elements.

Quick summary

Java builds real programs with methods, arrays and classes. A method is reusable code that can take parameters and return a result. An array holds many values of one type, read by index (a[0] is first, a.length is the count). A class is a blueprint; an object is made with new, and its methods are called with a dot.

Open the Virtual Lab

These free Class 12 Information Technology (Code 802) notes explain Java programming, methods, arrays, and classes and objects, with worked programs with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Information Technology syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories