Basics of Java Programming
Basics of Java Programming
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).
6. Operators
• Arithmetic: +, -, *, /, %
• Relational: ==, !=, <, >, <=, >=
• Logical: &&, ||, !
• Assignment: =, +=, -=, *=, /=
• Unary: ++, --
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);
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.
**************************************************