NAME: Malek Moustafa
ID: 231099
Java Programming Lab Summary
________________________
1. Class & Main Method
Every Java program starts with a class
and main() method.
java
public class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello,
world!");
}
}
2. Variables & Data Types
int age = 20; (whole numbers)
double pi = 3.14; (decimals)
String name = "Saif"; (text)
boolean isOn = true; (true/false)
3. Condi onal Statements (if-else)
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
__________________________________________________
______________________________________________
4. Loops (for, while)
For Loop:
for (int i = 1; i <= 5; i++) {
System.out.println(i);
}
While Loop:
int i = 1;
while (i <= 5) {
System.out.println(i);
i++;
}
5. Strings
String name = "maalleejffds";
System.out.println(name.toUpperCase()); //
"SAIF"
System.out.println(name.length()); 4
_____________________________________
6. Methods
public static void sayHello() {
System.out.println("Hello!");
}
public static void main(String[] args) {
sayHello();
}
7. Arrays
String[] fruits = {"Apple", "Banana"};
System.out.println(fruits[0]); // "Apple"
8. Comments
// Single-line
/* Multi-line */
Conclusion
Learned Java basics: classes, variables, conditions, loops,
strings, methods, arrays, and comments. Ready for advanced
topics like OOP.