简体   繁体   中英

In eclipse can we generate main method for a java class from the source

When we create a new class file in eclipse the steps we follow is

  1. we name the class file
  2. if we want a main class we click on the checkbox

    public static void main(String[] args)

But suppose we don't click the checkbox and create a .java file, is there a way to generate public static void main(String[] args) from the source, just like the way we generate getter/setter from source in eclipse.

PS: I know we can write public static void main(String[] args) manually, but I just want to know if eclipse has any feature to do that.

You can write "main" and hit Ctrl + Space to generate the main method. In IDEA IntelliJ the alias is "psvm".

Eclipse does nothing you can't do your self just try it. Create a new class call it what ever you want then create public static method called main which has a return type of void and excepts String array and you are done here is an example

public class IWantCacke {

public static void main (String ...sdadasda){
    System.out.println("Welcome to my main");
}

}

What youn need to understand that methods with the signature public static void main (String ...someArgName) are special methods that tell your program where to start you can create this method in any class it is static because it is born before any other object in your program

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM