hat is Java?
Java is an object-oriented programming language developed by Sun Microsystems. It is
platform-independent — meaning programs run on any computer that has the Java Virtual
Machine (JVM).
🔹 Features of Java
Simple and secure
Object-oriented
Platform-independent
Robust and portable
🔹 Basic Structure of a Java Program
class Hello {
public static void main(String args[]) {
[Link]("Hello, World!");
}
}
🔹 Key Points
class – defines a class
main() – entry point of the program
[Link]() – displays output
✨ Tip: Always match file name and class name!
⚙️Document 2: Variables, Data Types, and Operators
🔹 Variables
A variable is a name that stores data in memory.
Syntax:
int age = 16;
🔹 Data Types
Type Example Description
int 5 Integer
double 5.7 Decimal number
char 'A' Single character
boolean true True or False
String "Blu Ble" Sequence of characters
🔹 Operators
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Assignment: =, +=, -=
✨ Tip: Always use correct data type to avoid errors!
🔄 Document 3: Conditional Statements and Loops
🔹 If-Else Example
if (marks >= 35)
[Link]("Pass");
else
[Link]("Fail");
🔹 Nested If
if (marks >= 90)
grade = "A+";
else if (marks >= 75)
grade = "A";
else
grade = "B";
🔹 Loops
For Loop:
for (int i = 1; i <= 10; i++)
[Link](i);
While Loop:
while (n <= 5) {
[Link](n);
n++;
}
Do-While Loop: Executes at least once.
🧮 Document 4: Functions and Arrays
🔹 Functions (Methods)
Used to break code into small parts.
Example:
int add(int a, int b) {
return a + b;
}
Call:
[Link](add(5, 10));
🔹 Types of Functions
With return value
Without return value
With arguments
Without arguments
🔹 Arrays
Used to store multiple values of the same type.
Example:
int marks[] = {45, 67, 89, 92};
Access: marks[0] = 45
Looping through array:
for (int i = 0; i < [Link]; i++)
[Link](marks[i]);
📊 Document 5: String Functions & Practical Programs
🔹 Common String Functions
Function Description Example
length() returns length [Link]()
toUpperCase() converts to uppercase [Link]()
toLowerCase() converts to lowercase [Link]()
charAt(i) returns character at position [Link](2)
equals(str) checks equality [Link]("Hello")
substring(a,b) part of string [Link](2,5)
🔹 Sample Programs
1. Check Palindrome
String s = "LEVEL";
String rev = "";
for (int i = [Link]()-1; i >= 0; i--)
rev += [Link](i);
if ([Link](rev))
[Link]("Palindrome");
else
[Link]("Not Palindrome");
2. Find Largest of Three Numbers
int a = 10, b = 25, c = 15;
int largest = (a > b && a > c) ? a : (b > c ? b : c);
[Link]("Largest: " + largest);
3. Sum of Digits
int n = 1234, sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
[Link]("Sum = " + sum);
✨ Final Tips
Always write comments in code (// comment here)
Indent properly
Practice short programs daily
Revise syntax before practical exam