1

Given the following class, I am trying to find program's main entry point:

public class Demo {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }

    public static void main(String a, String b){
        // ...
    }

    public void main(int a){
        // ...
    }
}

Any help appreciated, thanks.

Perception
  • 79,279
  • 19
  • 185
  • 195

2 Answers2

6

Find the method named main, which is public, static, returns void, and takes a String array as argument.

The Class.getDeclaredMethod() can be used to do that. And you just need to filter the returned method to only keep it if it's public, static, and returns void. The getModifiers() and getReturnType() methods of the Method class can be used to do that.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Yeah, I saw that later, so I deleted my comment. Though to be fair to the skimmer contingency, you did put all the other metadata about the method to the right of its name in the first line :) – yshavit Nov 24 '12 at 13:42
0

In Java, if you're bundling to a jar, you can define your entry point in the jar's manifest. In Java, the computer determines the "entry point" when you actually execute the program, not when you compile.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331