Java Compiler Guide

Our compiler expects a complete Java program with a public class Main entry point. If your code doesn't follow this structure, compilation will fail.

Why does this matter?

When you create a new room, the editor is pre-loaded with a Java template. However, during a collaborative session, the code may be edited or replaced entirely. If the public class Main wrapper is removed, the compiler won't know where to start and will throw an error.

Required template

Your code must be wrapped in a public class Main with a public static void main(String[] args) method. Here is the minimum structure:

public class Main {

public static void main ( String[] args )

{
// your code here
}
}

Common mistakes

  • Missing public class Main — Writing a standalone function like void solve() without wrapping it in the Main class will cause a compilation error.
  • Wrong class name — Using public class Solution or public class HelloWorld instead of public class Main will fail. The class name must be Main.
  • Missing main method — The class must contain public static void main(String[] args) as the entry point.

Example: adding a helper method

If you need helper methods, define them inside the Main class:

public class Main {

static int add ( int a, int b )

{

return a + b;

}

public static void main ( String[] args )

{

System. out. println ( add ( 2, 3 ) );

}
}