0% found this document useful (0 votes)
12 views1 page

Java Lessons 1 To 3

programming

Uploaded by

mchenm.08
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)
12 views1 page

Java Lessons 1 To 3

programming

Uploaded by

mchenm.08
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/ 1

Java Programming - Lesson 1: Getting Started ■ What You Learned: - What is Java and how it

works (compiled language, cross-platform) - How to set up and run Java (Programiz compiler or VS
Code setup) - Writing your first Hello World program Code Sample: public class HelloWorld { public
static void main(String[] args) { System.out.println("Hello, Java!"); } } ■ Variables and Data Types: -
int, double, String, boolean - How to store and display data Code Sample: String name = "Che"; int
age = 20; double height = 5.4; boolean lovesJava = true; ■ Input with Scanner: - Used to get user
input - Syntax: Scanner input = new Scanner(System.in); Code Sample: Scanner input = new
Scanner(System.in); System.out.print("Enter your name: "); String name = input.nextLine();

Java Programming - Lesson 2: Operators & Type Casting ■ Operators in Java: - Arithmetic: +,
-, *, /, % - Comparison: ==, !=, >, <, >=, <= ■ Type Casting: - Automatic (widening): int → double -
Manual (narrowing): double → int Example: double price = 99.99; int approx = (int) price; ■ Input
Practice with Math: Code Sample: Scanner input = new Scanner(System.in);
System.out.print("Enter num1: "); int a = input.nextInt(); System.out.print("Enter num2: "); int b =
input.nextInt(); System.out.println("Sum: " + (a + b));

Java Programming - Lesson 3: Conditionals (if, else, switch) ■ Decision Making: - Use if-else
to check conditions - Use switch for multiple known options Code Sample: int grade = 85; if (grade
>= 75) { System.out.println("You passed!"); } else { System.out.println("You failed."); } ■ switch
Example: String letter = "A"; switch(letter) { case "A": System.out.println("Excellent!"); break; case
"F": System.out.println("Failed"); break; default: System.out.println("Invalid grade"); }

You might also like