XCODX |

Java Online Compiler & Interpreter

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  Welcome to XCODX Online Compiler

  Quick Start:
  Ctrl+Enter  Run code
  Ctrl+S      Save / Download
  Ctrl+L      Clear output

  Select a language and start coding.
Success
Operation completed

About Java

Java is a general-purpose, class-based, statically typed language that compiles to bytecode and runs on the Java Virtual Machine, giving it the "write once, run anywhere" portability it was designed around. James Gosling and his team at Sun Microsystems released it publicly in 1995; Oracle has stewarded it since acquiring Sun in 2010. Its combination of strong backward compatibility, mature tooling, and an enormous library ecosystem has kept it near the top of enterprise adoption for three decades. Today it runs most large-scale backends (usually through Spring Boot), Android's original toolchain, big-data engines like Hadoop and Spark, and the core systems at banks, insurers, and governments. Releases now follow a six-month cadence, and long-term-support versions such as Java 21 and Java 25 are the lines most teams standardize on.

Hello World in Java

import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> languages = Arrays.asList(
            "Java", "Kotlin", "Scala", "Clojure", "Groovy");

        System.out.println("JVM languages sorted by name length:");
        languages.stream()
                 .sorted((a, b) -> Integer.compare(a.length(), b.length()))
                 .forEach(name -> System.out.println("  " + name.length() + "  " + name));

        double avgLen = languages.stream()
                                 .mapToInt(String::length)
                                 .average()
                                 .orElse(0);
        System.out.printf("Average name length: %.1f%n", avgLen);
    }
}

When to use Java

Java is a strong default for long-lived server-side systems where stability, backward compatibility, and a deep hiring pool matter more than terse syntax, such as transaction processing, enterprise APIs, and data pipelines expected to run for years. Its mature JIT compiler and choice of garbage collectors make it competitive for high-throughput services, and the Spring and Jakarta ecosystems cover nearly every integration you might need. It is also the substrate for the wider JVM world, so learning it carries over to Kotlin, Scala, and Clojure. It is a poorer fit for small scripts or quick automation, where its ceremony (a class, a main method, explicit types, and a compile step) is heavier than a scripting language like Python.

Common questions

Can I use Maven, Gradle, or add libraries like Spring, Guava, or Jackson here?

No. This sandbox runs only the JDK standard library, with no Maven, Gradle, or dependency resolution and no external jars on the classpath. Imports such as org.springframework.*, com.google.common.*, or org.junit.* fail at compile time with a "package does not exist" error. Stick to the built-in packages (java.util, java.io, java.time, java.util.stream, and so on), which cover most language-learning and algorithm work.

How do I read input from the user in Java on this compiler?

Create a Scanner over System.in with Scanner sc = new Scanner(System.in); then call sc.nextInt(), sc.nextLine(), sc.nextDouble(), and so on. You can either type into the live terminal (a print prompt pauses and waits for you) or paste everything up front into the Stdin Box before running, and press Ctrl+D to signal end of input. A BufferedReader wrapping new InputStreamReader(System.in) also works and is noticeably faster for reading large amounts of input.

Why does my Java code need a class named Main, and what causes "class X is public, should be declared in a file named X.java"?

Java requires the file name to match any public class it contains, and this sandbox compiles and launches the class named Main, so your entry point should be public class Main { public static void main(String[] args) { ... } }. If you rename the public class without renaming its file, the compiler rejects it with that exact error. You can add more classes in extra files via the + tab, but every public class must live in a file whose name matches it exactly, and Java is case-sensitive.

Which Java version does this online compiler run?

The exact runtime appears in the version badge above the editor, so check there rather than guessing. It is a standard OpenJDK build, which means var (10+), text blocks (15+), and records (16+) work on recent releases, while newer additions such as sealed classes (17+) and pattern matching for switch (21+) depend on the version shown. Preview features that require the --enable-preview flag are not available, since you cannot pass compiler flags here.

Can my Java program open files, connect to a database, or make HTTP requests?

No. The program runs in an isolated sandbox with no outbound network, so HttpClient calls, JDBC connections, and sockets to external hosts fail or time out. The filesystem is temporary and reset on every run, so anything written with Files or FileWriter disappears afterward and cannot be used to persist state. Reading and writing scratch files during a single execution is fine, but nothing survives between runs.

Is Java compiled or interpreted, and how does that affect running it here?

Both, in stages: javac compiles your source to platform-independent bytecode, and the JVM then executes that bytecode, JIT-compiling hot paths to native code as it runs. In this sandbox both steps happen automatically when you press Run, so a compile error stops the program before any output while a runtime exception prints a stack trace. Because there is a short execution timeout, very long loops or heavy computation may be cut off, though the limit is relaxed while your program waits for stdin.

How Java runs on XCODX

Sandbox filename
Main.java
Entry point
Main class entrypoint
Editor grammar
text/x-java
Reading stdin
new Scanner(System.in)
Input delivery
live WebSocket stream
Prompt flushing
flush manually before reading input
Compile limit
10 s
Run limit
3 s batch · up to 3 min live
Memory
256 MB per stage
Max source
50,000 characters

Default program on this page

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello from Java!");
        System.out.println("Welcome to XCODX Online Compiler!");
    }
}

JVM notices such as "Picked up JAVA_TOOL_OPTIONS" and unchecked-operation notes are filtered from the output pane.