How long is the shortest possible Java program?



Occasionally I may include affiliate links, which means I may get a commision if you purchase something via that link. Check out my privacy policy for more info.

This is my answer to this question on Quora.

You can even do a little shorter than Garry Taylor’s solution, by giving main’s argument a shorter name:

public class A{public static void main(String[] a){}}

The class doesn’t even need to be public, it can be default as well:

class A{public static void main(String[] a){}}

You can verify that it works by running this slightly longer Java program:

class A{public static void main(String[] a){System.out.println("hi");}}