94

I know a cool shortcut for System.out.println(): sysout Ctrl + Space.

Is there something similar for public static void main(String args[])?

8 Answers 8

230

This is just main and Ctrl-Space.

0
50

In Eclipse, select preferences.

In preferences, look for Java/Editor/Templates.

Here you will see a list of all of them. And you can even add your own.

0
19

Just type ma and press Ctrl + Space, you will get an option for it.

3
  • 6
    Just type m and press Ctrl + Space, you will get an option for it. :D Commented Oct 29, 2013 at 2:01
  • 7
    Just press Ctrl + Space and you will get a list that you later can choose it from.
    – Sander
    Commented Nov 13, 2013 at 10:24
  • I am using mac, so Ctrl+Space is only brings up the spotlight, instead of auto complete.
    – C. Zeng
    Commented May 3, 2015 at 17:18
5

As bmargulies mentioned:

Preferences>Java>Editor>Templates>New...

enter image description here

enter image description here

Now, type psvm then Ctrl + Space on Mac or Windows.

2
  • 1
    Above steps are useful but 'main' is already available in the template. enter main and then ctrl + space.
    – Kishore
    Commented Jul 13, 2018 at 17:52
  • Why adding a new template when main is already present?
    – Izerlotti
    Commented Aug 23, 2023 at 15:03
1

Type main and press and hold Ctrl and next press Space Space (double space) and select, it or pressenter to focus on main option.

This is fastest way.

4
  • The shortcut is wrong, it is correctly stated in the accepted answer.
    – tmbo
    Commented Apr 15, 2017 at 15:57
  • are you sure that you are in Eclipse...it is a general trick ctrl +double space is always served for Eclipse ... you can try ..however this is correct in my Eclipse Commented Apr 15, 2017 at 17:08
  • my answer is general and can use in Eclipse jee version but accepted answer not enough for eclipse jee also my answer is for all versions of eclipse Commented Apr 15, 2017 at 17:27
  • in general case ctrl + space + space is to show all shortcuts that eclipse is made but ctrl+space is contained Classes and shortcuts..by double space way we can seperate these from Classes Commented Apr 15, 2017 at 17:31
1

To get public static void main(String[] args) line in eclipse without typing the whole line type "main" and press Ctrl + space then, you will get the option for the main method select it.

enter image description here

0

Alternately, you can start a program containing the line with one click.

Just select the method stub for it when creating the new Java class, where the code says,

Which method stubs would you like to create?

[check-box] public static void main(String[]args) <---- Select this one.

[check-box] Constructors from superclass

[check-box] Inherited abstract methods

-1

Just type main and press Ctrl + Space, and you will get an option for it.

2
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 9, 2022 at 3:17
  • This has already been stated in the accepted answer.
    – Attila T
    Commented Nov 11, 2022 at 16:37