0% found this document useful (0 votes)
2 views

Basics of Java Programming

The document provides an overview of Java programming for Grade 9 ICSE students, covering topics such as the basics of Java, program structure, data types, variables, operators, input/output, control statements, and functions. It includes example code snippets and practice programs to enhance understanding. The material is intended for educational purposes and is in the public domain for free use.

Uploaded by

contactkeenan72
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)
2 views

Basics of Java Programming

The document provides an overview of Java programming for Grade 9 ICSE students, covering topics such as the basics of Java, program structure, data types, variables, operators, input/output, control statements, and functions. It includes example code snippets and practice programs to enhance understanding. The material is intended for educational purposes and is in the public domain for free use.

Uploaded by

contactkeenan72
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
You are on page 1/ 7

Basics of Java Programming – Grade 9 ICSE Notes

1. Introduction to Java
• Java is a high-level, object-oriented programming
language.
• It was developed by James Gosling at Sun Microsystems.
• Java is platform-independent (Write Once, Run
Anywhere - WORA).
• Java programs are written in .java files and compiled into
bytecode (.class files).

2. Structure of a Java Program


java
CopyEdit
class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Key parts:
• class Hello → Class declaration
• main method → Entry point of a Java program
• System.out.println → Used to display output
3. Java Tokens
Java tokens are the smallest elements of a program:
1. Keywords: Reserved words (e.g., int, class, if, else, while)
2. Identifiers: Names of variables, classes, methods
3. Literals: Constants like numbers (10, 3.14), characters
('A'), strings ("Java")
4. Operators: Symbols for operations (+, -, *, /, %)
5. Separators: e.g., ;, (), {}, []
6. Comments:
o Single line: // comment
o Multi-line: /* comment */

4. Data Types in Java


Java is statically typed. You must declare variables with a
type.
Primitive data types:
Type Size Example
int 4 bytes int a = 5;
float 4 bytes float x = 3.14f;
double 8 bytes double y = 9.81;
char 2 bytes char ch = 'A';
Type Size Example
boolean 1 bit boolean b = true;

5. Variables and Constants


• Variable: Storage location with a name.
java
CopyEdit
int marks = 90;
• Constant: Value that doesn't change, declared with final.
java
CopyEdit
final int MAX = 100;

6. Operators
• Arithmetic: +, -, *, /, %
• Relational: ==, !=, <, >, <=, >=
• Logical: &&, ||, !
• Assignment: =, +=, -=, *=, /=
• Unary: ++, --

7. Input and Output


Output:
java
CopyEdit
System.out.println("Hello");
System.out.print("World"); // no newline
Input (using Scanner):
java
CopyEdit
import java.util.Scanner;

Scanner sc = new Scanner(System.in);


int a = sc.nextInt();
String name = sc.nextLine();

8. Control Statements
a. Conditional (if, else)
java
CopyEdit
if (a > b) {
System.out.println("A is greater");
} else {
System.out.println("B is greater");
}
b. Switch
java
CopyEdit
switch (choice) {
case 1: System.out.println("One"); break;
case 2: System.out.println("Two"); break;
default: System.out.println("Invalid");
}
c. Loops
• for loop
java
CopyEdit
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}
• while loop
java
CopyEdit
int i = 1;
while (i <= 5) {
System.out.println(i);
i++;
}
• do-while loop
java
CopyEdit
int i = 1;
do {
System.out.println(i);
i++;
} while (i <= 5);

9. Functions (Methods)
java
CopyEdit
public static int add(int a, int b) {
return a + b;
}
• Calling: int sum = add(5, 3);

10. Basic Programs to Practice


• Print numbers from 1 to 100
• Find if a number is even or odd
• Calculate area of a circle
• Print multiplication table of a number
• Check whether a number is prime

No Copyright Claimed
This material has been created for educational purposes and
is intended for free public use.
The content in this document is released into the public
domain by the author and contributors.
You are free to copy, share, modify, distribute, or use this
material in any form, with or without attribution.
This resource was created with the support of AI tools and
compiled by Annexa Academics for the benefit of students
and educators.
**************************************************

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy