■ Java Week 1 Notes (Day 1–2 + Strings Deep Dive)
■ Day 1 — Java Basics & Setup
1■■ What is Java? - Java is a programming language that runs on the JVM (Java Virtual Machine).
2■■ Tools You Need - JDK (Java Development Kit) and IDE (IntelliJ, Eclipse, VS Code).
3■■ First Program:
public class Hello { public static void main(String[] args) {
System.out.println("Hello World!"); } }
■ Day 2 — Variables & Data Types
Variables are boxes that store values.
int age = 21; double height = 5.6; char grade = 'A'; boolean student = true;
Type Example Meaning
int 25 Whole numbers
double 3.14 Decimal numbers
char 'A' Single character
boolean true/false Logical values
long 1000000000L Very big integers
float 3.14f Decimal (smaller than double)
■ Type Casting
Widening (automatic, safe): int → double
int a = 5; double b = a; // 5.0
Narrowing (manual, data loss): double → int
double d = 9.7; int x = (int) d; // 9
■ Flashcards Recap
- System.out.print → no new line.
- System.out.println → prints + new line.
- Java is case-sensitive.
- Variable names follow camelCase.
- Reserved words (keywords) cannot be variable names.
■ Strings Deep Dive
Creating Strings:
String s1 = "Hello"; String s2 = new String("Hello");
Strings are Immutable:
String s = "Hi"; s.concat(" Swati"); System.out.println(s); // Hi s = s.concat("
Swati"); System.out.println(s); // Hi Swati
Method Meaning Example Output
length() Count characters "Swati".length() 5
charAt(i) Character at index "Swati".charAt(0) 'S'
toUpperCase() Uppercase "Swati".toUpperCase() SWATI
toLowerCase() Lowercase "Swati".toLowerCase() swati
equals(str) Exact match "Swati".equals("swati") false
equalsIgnoreCase(str) Match ignoring case "Swati".equalsIgnoreCase("swati") true
contains(str) Substring check "Hello Swati".contains("Swati") true
substring(start,end) Slice string "Swati".substring(0,3) Swa
replace() Replace text "Swati".replace("ti","ty") Swaty
trim() Remove spaces " Swati ".trim() Swati
split(" ") Split words "I love Java".split(" ") ["I","love","Java"]
indexOf() First occurrence "Swati".indexOf("a") 2
lastIndexOf() Last occurrence "Swati".lastIndexOf("a") 3