Wednesday, October 25, 2017

Eclipse shortcut to System.out.println in Java program - Tips

Eclipse IDE provides quick shortcut keys to print System.out.println statement in Java but unfortunately not every Java programmers are familiar of that.  Even programmers with 3 to 4 year of experience sometimes doesn't know this useful Eclipse shortcut to generate System.out.println messages.  This Eclipse tips is to help those guys. Let me ask you one question, How many times you type System.out.println in your Java program?  I guess multiple time,  while doing programming, debugging and testing small stuff.  System.out.println is the most preferred way to print something on console because it doesn’t required setup like configuring Log4J or java.util.Logger . Though I recommend using logging for better information display in production code, nobody can undermine importance of System.out.println statement in Java. On the quest of learning Eclipse shortcut, some of them which I have discussed in my list of Top 30 Eclipse shortcut for Java programmers,  I found a very useful Eclipse shortcut for generating code for System.out.println statement in Java source file. 

By using this Eclipse shortcut you can create System.out.println() messages in 60% less time,  as you only need to type the message. This Eclipse shortcut will place your cursor right in the place, where it should be i.e. inside System.out.println method.

Eclipse shortcut for System.out.println

In order to generate code for System.out.println statement in your Java file, you can use following Eclipse shortcut keys. Just type "sysout" in your Java editor and press ctrl + space, which triggers code completion. This will expand sysout into System.out.println("") and place your cursor inside println() method argument to enter messages. This is in my knowledge quickest way of writing System.out.println statement in Java code. 

Though you can also use static import feature of Java 5 to import System.out static variable and simply use them as out.println(), which can save you couple of keystrokes but that has its own problem in terms of reduced readability and chance of conflict, In case you happen to have another variable with identifier "out"

This Eclipse shortcut to create System.out.println() statement is best in my opinion. Similar to sysout shortcut, you also have Eclipse shortcut for generating System.err.println() statements. Just type syserr and press ctrl + space, it will generate System.err.println statement and place the cursor in right place to type message.

How to generate system.out.println in Eclipse IDEAs I have always said learn new Linux command to improve productivity in UNIX based systems learn similarly Eclipse shortcuts to work faster in Eclipse and learn Java and open source API to reduce development time of new projects. I'll keep sharing useful Eclipse shortcut as and when I will find them.  Let me know if you come across any interesting Eclipse shortcut like this.

Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 and 2

Other useful Eclipse tips and tricks from Javarevisited Blog


Vizay Soni said...

You dont need to type whole "sysout"..
just type "syso" then CTRL+Space ,
it will replace with System.out.println("");

I @m The W@y I @M said...

Sysout is just an example ,we can create our own templstes in Eclipse under this navigation path :

Window -> Preferences ->Java->Editor->Templates

Unknown said...

what is the shortCUt for public static void main() ???????

Anonymous said...

public static void main()

short cut for main(). ctrl+space

Unknown said...

No need to type main(). Just type m then ctrl+space....:P

Dreamer said...


Post a Comment