Introductory Java
Introductory Java
What is Java?
• Known for its portability ("Write Once, Run Anywhere"), security, and
performance.
• Compiled and Interpreted (Java code is compiled into bytecode, then executed
by the JVM).
System.out.println("Hello, World!");
}
• public class HelloWorld → Defines a class named HelloWorld.
• public static void main(String[] args) → The main method, the entry point of
Java programs.
• System.out.println("Hello, World!"); → Prints text to the console.
Comments in Java
/*
This is a
multi-line comment
*/
int 25 4 bytes
Operators in Java
+ a+b Addition
- a-b Subtraction
* a*b Multiplication
/ a/b Division
== a == b Equal to
!= a != b Not equal to
Conditional Statements
} else {
}
Loops in Java
For Loop
}
While Loop
int count = 0;
System.out.println(count);
count++;
Functions (Methods)
// Method definition
System.out.println("Hello!");
}
Method with Parameters & Return Value
return a + b;
}
public static void main(String[] args) {
class Car {
void honk() {
System.out.println("Beep! Beep!");
System.out.println(myCar.brand);
myCar.honk();
import java.util.Scanner;
int a = scanner.nextInt();
int b = scanner.nextInt();
scanner.close();