How long is the shortest possible Java program?



This site utilizes Google Analytics, Google AdSense, as well as participates in affiliate partnerships with various companies including Amazon. Please view the privacy policy for more details.

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

Leave a Reply

Note that comments won't appear until approved.