Java Cheatsheet

☕ Java Basics // Hello World public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } ๐Ÿ’ก Tip: Every Java program starts with a main method inside a class. ๐Ÿ“ฆ Variables & Data Types int age = 25; double price = 99.99; char grade = 'A'; boolean isActive = true; String name = "Maxon"; ๐Ÿ’ก Tip: Use wrapper classes (Integer, Double, etc.) for objects and generics. ๐Ÿ”€ Control Flow int num = 10; // if-else if (num > 5) { System.out.println("Greater than 5"); } else { System.out.println("Less or equal to 5"); } // switch switch (num) { case 5: System.out.println("Five"); break; case 10: System.out.println("Ten"); break; default: System.out.println("Other"); } ๐Ÿ’ก Tip: Use switch for cleaner multi-condition checks. ๐Ÿ” Loops // for loop for (int i = 0; i < 5; i++) { System.out.println(i); } // while loop int j = 0; while (j < 5) { System.out…

Post a Comment