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

Ch 5-Fundamentals of Java

School Revise · Class 11 Information Technology · Chapter 5

Fundamentals of Java

Code 802, Class 11. Java is a popular programming language. Here we write our first Java programs, use variables, and make decisions and loops.

class

holds the code

main

where it starts

What this chapter is about

A Java program lives inside a class and starts running at the main method. System.out.println prints output.

1. A first Java program

Every Java program has a class and a main method. System.out.println(“…”) prints a line.

public class Main { public static void main(String[] args) { System.out.println(“Hello, School Revise”); } }

2. Variables and operators

Java has data types: int (whole numbers), double (decimals), String (text) and boolean (true or false). Operators include + – * / % and comparisons.

3. Decisions and loops

if and else make decisions, and for and while loops repeat work, much like other languages but with braces and semicolons.

Practise with the interactive

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

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. Print a message.

SOLUTION

public class Main { public static void main(String[] args) { System.out.println(“Hello, School Revise”); } }

OUTPUT

Hello, School Revise
Problem 2. Add two numbers.

SOLUTION

int a = 5, b = 3; System.out.println(a + b);

OUTPUT

8
Problem 3. Declare different data types.

SOLUTION

int age = 15; double pi = 3.14; String name = “Java”; System.out.println(age + ” ” + pi + ” ” + name);

OUTPUT

15 3.14 Java
Problem 4. Check even or odd.

SOLUTION

int n = 8; if (n % 2 == 0) System.out.println(“even”); else System.out.println(“odd”);

OUTPUT

even
Problem 5. Print numbers 1 to 5.

SOLUTION

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

OUTPUT

1 2 3 4 5
Problem 6. Count down from 5 with while.

SOLUTION

int n = 5; while (n > 0) { System.out.println(n); n–; }

OUTPUT

5 4 3 2 1
Problem 7. Find the sum of 1 to 10.

SOLUTION

int s = 0; for (int i = 1; i <= 10; i++) s = s + i; System.out.println(s);

OUTPUT

55
Problem 8. Print the 3 times table.

SOLUTION

for (int i = 1; i <= 3; i++) System.out.println(“3 x ” + i + ” = ” + (3 * i));

OUTPUT

3 x 1 = 3 3 x 2 = 6 3 x 3 = 9
Problem 9. Write a method that adds two numbers.

SOLUTION

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

OUTPUT

8
Problem 10. Find the length of a string.

SOLUTION

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

OUTPUT

4

Practice set A, multiple choice

1. Where does a Java program start running?

At the main method.

2. Which statement prints a line?

System.out.println().

3. The data type for whole numbers is …

int.

4. Which keyword makes a decision?

if.

Quick summary

A Java program lives inside a class and starts at the main method; System.out.println prints output. Data types include int, double, String and boolean, with operators + – * / % and comparisons. if and else make decisions, and for and while loops repeat work, using braces and semicolons.

Open the Virtual Lab

These free Class 11 Information Technology (Code 802) notes explain the fundamentals of Java, class and main method, System.out.println, variables and data types, and decisions and loops 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 11 Information Technology syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories