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 with that.  Even programmers with 3 to 4 years of experience sometimes don't know this useful Eclipse shortcut to generate System.out.println messages.  This Eclipse tip 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 times 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 require setups like configuring Log4J or java.util.Logger .

Though I recommend using logging for better information display in production code, nobody can undermine the importance of System.out.println statement in Java. On the quest of learning Eclipse shortcuts, some of them which I have discussed in my list of Top 30 Eclipse shortcuts 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.

Btw, if you are a beginner, I suggest you to first go through a beginner course like Eclipse Tutorials for Beginners to understand the core concepts of Eclipse IDE and get yourself familiar with UI and essential features. Learning plugins will be a lot easier after that.

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

6 comments :

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...

Main(Ctrl+space)

Post a Comment