Important
In Java, all executable code must be inside a class.
HelloWord.java
;{ }// one line/* multi-lines */package com.example.utils;int |
Integer |
|
|---|---|---|
| Nature | Primitive | Object (Wrapper) |
| Nullable | ❌ No | ✅ Yes |
| Performance | ⭐ Very fast | Slightly slower |
| Memory usage | Low | Higher (object overhead) |
| Typical uses | Calculations, loops | Collections, APIs |
String s = "Java";
String fullName = "Alain" + " " + "Philippe"; // concat
s.length();
s.charAt(0); // Get character at index 0
s.contains("va");
s.toLowerCase(); // also toUpperCase
s.endsWith("Java"); // also startsWith
s.equals("Java"); // Use equals to compare, not ==
String textBlock = """
First line
Second line
""";Others: replace(), split()
toString() for Object types
System.out.print("Hello");System.out.println("Hello");
i = 0i < 5i++Methods and Attributes Accessiblility
| Modifier | Same Class | Same Package | Subclasses | Everywhere |
|---|---|---|---|---|
| public | ✅ | ✅ | ✅ | ✅ |
| protected | ✅ | ✅ | ✅ | ❌ |
| default (no modifier) | ✅ | ✅ | ❌ | ❌ |
| private | ✅ | ❌ | ❌ | ❌ |