Java
v15.0.2
Java
v15.0.2
Java is a statically typed, class-based, object-oriented language created by James Gosling at Sun Microsystems and released in 1995. Designed around the principle of write once, run anywhere, Java source is compiled to bytecode that runs on the Java Virtual Machine, providing portability across platforms. It features automatic memory management, strong typing, and a vast standard library.
Today Java powers a huge share of enterprise backends, Android applications, big-data systems, and financial platforms. Its mature ecosystem includes frameworks like Spring and build tools like Maven and Gradle. This compiler runs Java 15.0.2, so you can use features such as the var keyword, switch expressions, and text blocks. The JVM's stability and performance keep Java central to large, long-lived codebases.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
System.out.println("Hello, " + name + "!");
}
}public class Main {
public static void main(String[] args) {
String[] fruits = {"apple", "banana", "cherry"};
for (int i = 0; i < fruits.length; i++) {
System.out.println((i + 1) + " " + fruits[i]);
}
}
}public class Main {
static long factorial(int n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}
public static void main(String[] args) {
System.out.println(factorial(5));
}
}public class Main {
public static void main(String[] args) {
try {
int x = Integer.parseInt("abc");
System.out.println(x);
} catch (NumberFormatException e) {
System.out.println("Invalid number: " + e.getMessage());
} finally {
System.out.println("Done");
}
}
}import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Map<Character, Integer> counts = new HashMap<>();
for (char c : "banana".toCharArray()) {
counts.merge(c, 1, Integer::sum);
}
System.out.println(counts);
}
}import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>(List.of(3, 1, 2));
Collections.sort(nums);
System.out.println(nums);
}
}public class Main {
static class Person {
String name;
int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
String describe() {
return name + " (" + age + ")";
}
}
public static void main(String[] args) {
Person p = new Person("Ada", 36);
System.out.println(p.describe());
}
}import java.util.List;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
List<Integer> nums = List.of(1, 2, 3, 4, 5);
List<Integer> evens = nums.stream()
.filter(n -> n % 2 == 0)
.map(n -> n * n)
.collect(Collectors.toList());
System.out.println(evens);
}
}public class Main {
static String day(int n) {
return switch (n) {
case 1, 7 -> "weekend";
default -> "weekday";
};
}
public static void main(String[] args) {
System.out.println(day(1));
System.out.println(day(3));
}
}Yes. CompileBytes compiles and runs Java in your browser, so you do not need to install a JDK locally.
It runs Java 15.0.2, which supports features like the var keyword, switch expressions, and text blocks.
Use a Scanner on System.in (or BufferedReader) in your code and type the input into the stdin box before running.
Yes, compiling and running Java on CompileBytes is free and requires no account.
Your public class containing main should be named Main here, since the runner compiles and executes a single source file.