-
-
Notifications
You must be signed in to change notification settings - Fork 123
Java
Evan Shaw edited this page Sep 30, 2025
·
13 revisions
Since Java 25, it's not necessary to wrap main in a class, so shortest boilerplate is:
void main(String[]a){}
// If the hole doesn't have arguments:
void main(){}Defining a type with var is often shorter. Note that multiple assignment is not possible with this method.
String s="foo";
// vs
var s="foo";This can save 1 to 2 characters on char scoring. If you need a large integer constant between 1000 and 65535 (inclusive), it may help to use a char literal instead of a number:
var n=30000;
// vs
var n='田';This can save a few chars when using large numbers that end in zeros
var n=30000;
// vs
var n=3e4;If you need a single integer initialized to 0, using a field saves 1 byte:
void main(){for(int i=0;i<10;)IO.println(i++);}
// vs
int i;void main(){for(;i<10;)IO.println(i++);}Java doesn't allow declaring multiple fields like this at once without explicit initializers.