Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Evan Shaw edited this page Sep 30, 2025 · 13 revisions

Boilerplate

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(){}

The var data type

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";

Unicode constants

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='田';

Scientific Notation

This can save a few chars when using large numbers that end in zeros

var n=30000;
// vs
var n=3e4;

Use Fields to Initialize to Zero

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.

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.