0% found this document useful (0 votes)
3 views9 pages

ICSE Class 8 Java Programme For Beginers

Uploaded by

madhubelakoba
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

ICSE Class 8 Java Programme For Beginers

Uploaded by

madhubelakoba
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ICSE Class 8 – Java Programming

Notes and Practice Problems

Unit 1: Introduction to Java


Notes
Java is a high-level, object-oriented programming language developed by Sun
Microsystems (now owned by Oracle).
Java programs are usually written and run using BlueJ, a simple IDE (Integrated
Development Environment) designed for teaching.
Every Java program is organized inside a class.
Basic structure of a Java program:

java

class Sample
{
public static void main(String args[])
{
[Link]("Hello, World!");
}
}

Key parts explained:


class Sample — defines a class named Sample

public static void main(String args[]) — the main method; execution starts
here
[Link]() — prints output and moves to a new line
[Link]() — prints output but does NOT move to a new line
Every statement in Java ends with a semicolon (;)
Curly braces { } mark the beginning and end of a block of code

Quick Check Questions


1. What is the extension of a Java source file?
2. What is the difference between print() and println() ?
3. Why does every Java program need a main method?
Unit 2: Java Fundamentals – Data Types, Variables, Operators
Notes
Identifiers – Names given to variables, methods, classes. Rules:
Must begin with a letter, _ or $

Cannot use Java keywords (like class , int , if )


Case-sensitive ( Sum and sum are different)

Data Types in Java

Type Keyword Size Example

Integer int 4 bytes int age = 13;

Long integer long 8 bytes long pop = 1000000L;

Decimal double 8 bytes double pi = 3.14;

Character char 2 bytes char grade = 'A';

Boolean boolean 1 bit boolean isPass = true;

Byte byte 1 byte byte b = 10;

Short short 2 bytes short s = 200;

Float float 4 bytes float f = 5.6f;

Variable Declaration

java

int marks = 95;


double price = 45.5;
char initial = 'S';
boolean flag = true;

Operators
Type Operators Example

Arithmetic + - * / % a + b , a % b (remainder)

Relational > < >= <= == != a > b

Logical && || ! a>5 && b<10

Assignment = += -= *= /= a += 5; (means a = a+5)

Increment/Decrement ++ -- a++; --b;

Type Casting
Widening (implicit): smaller type → larger type automatically. int → long → float →
double
Narrowing (explicit): larger type → smaller type, needs manual casting.

java

double d = 9.7;
int x = (int) d; // x becomes 9 (decimal part truncated)

Quick Check Questions


1. Name two invalid identifiers and explain why: 2sum , int , total-marks
2. Evaluate: 17 % 4 and 17 / 4
3. What will (int) 7.9 output?

Practice Programs
1. Write a program to declare two integers, and print their sum, difference, product,
quotient, and remainder.
2. Write a program to swap the values of two variables using a third variable.
3. Write a program to accept the radius of a circle (use a fixed value) and calculate its
area and circumference. (Area = πr², Circumference = 2πr)
4. Write a program to convert temperature from Celsius to Fahrenheit. (F = (C × 9/5) +
32)
5. Write a program to calculate simple interest given principal, rate, and time. (SI =
(P×R×T)/100)
Unit 3: Taking Input in Java (Using Scanner Class)
Notes
To take input from the user, Java provides the Scanner class from [Link] package.

java

import [Link];

class InputDemo
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
[Link]("Enter your age:");
int age = [Link]();
[Link]("Your age is: " + age);
}
}

Common Scanner methods:

Method Used for

nextInt() reading an integer

nextDouble() reading a decimal number

nextLine() reading a full line of text (String)

next() reading a single word

nextBoolean() reading true/false

Practice Programs
6. Write a program to accept a student's name and marks in 3 subjects, then display the
total and percentage.
7. Write a program to accept the length and breadth of a rectangle from the user and find
its area and perimeter.
8. Write a program to accept two numbers from the user and display the larger of the
two.
9. Write a program to accept the price of an item and calculate the final price after
applying 18% GST.
Unit 4: Conditional Statements
Notes
if statement

java

if (marks >= 40)


{
[Link]("Pass");
}

if-else statement

java

if (marks >= 40)


{
[Link]("Pass");
}
else
{
[Link]("Fail");
}

if-else-if ladder

java

if (marks >= 90)


[Link]("Grade A");
else if (marks >= 75)
[Link]("Grade B");
else if (marks >= 40)
[Link]("Grade C");
else
[Link]("Fail");

switch statement – used when checking one variable against many fixed values

java
switch (day)
{
case 1: [Link]("Monday");
break;
case 2: [Link]("Tuesday");
break;
default: [Link]("Invalid day");
}

break is important — it stops execution from falling into the next case.

Quick Check Questions


1. What happens if you forget to write break in a switch case?
2. Convert this if-else ladder into a switch statement (where suitable).

Practice Programs
10. Write a program to check whether a number entered by the user is even or odd.
11. Write a program to check whether a given year is a leap year or not.
12. Write a program to accept three numbers and find the greatest among them.
13. Write a program to accept marks and print the grade using an if-else-if ladder:
90 and above: A
75–89: B
40–74: C
Below 40: Fail
14. Write a menu-driven program using switch that:
Accepts a choice (1 to 4)
1: Add two numbers, 2: Subtract, 3: Multiply, 4: Divide
15. Write a program to accept a character and check whether it is a vowel or a consonant
using switch .

Unit 5: Iterative Statements (Loops)


Notes
for loop – used when the number of repetitions is known

java
for (int i = 1; i <= 5; i++)
{
[Link](i);
}

while loop – used when repetition depends on a condition, checked before each iteration

java

int i = 1;
while (i <= 5)
{
[Link](i);
i++;
}

do-while loop – executes the body at least once, condition checked after

java

int i = 1;
do
{
[Link](i);
i++;
} while (i <= 5);

Nested loops – a loop inside another loop, commonly used for patterns.

Quick Check Questions


1. What is the key difference between while and do-while loops?
2. How many times will this loop run? for(int i=10; i>0; i--)

Practice Programs
16. Write a program to print the first 10 natural numbers using a for loop.
17. Write a program to print the multiplication table of a number entered by the user.
18. Write a program to find the sum of the first N natural numbers (N entered by the
user).
19. Write a program to find the factorial of a number.
20. Write a program to check whether a number is a prime number.
21. Write a program to print the Fibonacci series up to N terms.
22. Write a program to check whether a number is a palindrome (e.g., 121, 1331).
23. Write a program to reverse the digits of a number entered by the user.
24. Write a program to find the sum of digits of a number.
25. Write a program using nested loops to print the following pattern:

*
* *
* * *
* * * *
* * * * *

26. Write a program using nested loops to print the following pattern:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

27. Write a program to display all Armstrong numbers between 1 and 500. (An Armstrong
number equals the sum of the cubes of its digits, e.g., 153 = 1³+5³+3³)

Mixed Practice Set (Challenge Problems)


28. Write a program to accept 5 numbers from the user and find their average.
29. Write a program to accept a number and check whether it is positive, negative, or zero.
30. Write a program to display the multiplication tables of numbers from 2 to 5 using
nested loops.
31. Write a program to accept a number and print whether it is divisible by both 3 and 5.
32. Write a program to accept marks of 5 subjects and display: total, percentage, and grade
(using if-else-if).
33. Write a program to find the greatest common divisor (GCD) of two numbers using a
loop.
34. Write a program to print all even numbers between 1 and 50 using a while loop.
35. Write a program to count how many digits are present in a given number.

Tips for Teaching / Exam Preparation


Encourage students to dry run programs on paper before typing them, tracing
variable values step by step.
Emphasize correct use of semicolons, curly braces, and indentation — common
sources of syntax errors.
Remind students that Java is case-sensitive.
Practice converting between if-else-if ladders and switch statements, since ICSE
exams often test both.
For loop-based problems, have students first identify: (a) the starting value, (b) the
ending condition, (c) how the variable changes each iteration.
Pattern printing problems are a favorite in ICSE exams — practice several nested loop
variations.

You might also like