Jul 5, 2024
Create
button to start a new Java Repl
project. Name it descriptively, like HelloWorld
.side-by-side
or stacked
).Run
button to compile and execute Java code..java
and compiled files end with .class
.public static void main(String[] args)
.System.out.println("Hello, World!");
.int age = 27;
int sum = 10 + 5; // 15
for(initialization; condition; update)
for(int i = 0; i < 10; i++) { System.out.println(i); }
while(condition)
int i = 0; while(i < 10) { System.out.println(i); i++; }
do { // code } while(condition);
int i = 0; do { System.out.println(i); i++; } while(i < 10);
if (condition) { // code } else { // code }
int score = 85;
if (score >= 90) {
System.out.println("A grade");
} else if (score >= 80) {
System.out.println("B grade");
} else {
System.out.println("C grade");
}
switch (variable) { case x: // code; break; ... default: // code }
int day = 2;
switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
// other cases
default:
System.out.println("Other day");
}
dataType[] arrayName = new dataType[size];
arrayName[index] = value;
int[] numbers = new int[5];
numbers[0] = 10;
for(dataType item : arrayName) { // code }
public class User {
public String name;
public LocalDate birthdate;
public User(String name, String birthdate) {
this.name = name;
this.birthdate = LocalDate.parse(birthdate);
}
public int getAge() {
return Period.between(this.birthdate, LocalDate.now()).getYears();
}
}
class SuperClass { ... }
class SubClass extends SuperClass { ... }
public class AudioBook extends Book {
private int runTime;
public AudioBook(String title, String author, int runTime) {
super(title, author);
this.runTime = runTime;
}
}