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 do 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 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.
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 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 the 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.
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.
As I have always said learn new Linux commands 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 the development time of new projects. I'll keep sharing useful Eclipse shortcuts as and when I will find them. Let me know if you come across any interesting Eclipse shortcut like this.
Other useful Eclipse tips and tricks from Javarevisited Blog
11 comments :
You dont need to type whole "sysout"..
just type "syso" then CTRL+Space ,
it will replace with System.out.println("");
Sysout is just an example ,we can create our own templstes in Eclipse under this navigation path :
Window -> Preferences ->Java->Editor->Templates
what is the shortCUt for public static void main() ???????
public static void main()
short cut for main(). ctrl+space
No need to type main(). Just type m then ctrl+space....:P
Main(Ctrl+space)
syso(ctrl+space) for System.out.println("");
That's a nice shortcut but isn't its sout?
psvm + Tab = public static void main(String[] args)
sout + Tab = System.out.println("")
serr + Tab = System.err.println("")
for + Tab = for (int i = 0; i < 10; i++)
do + Tab = do {} while (true);
Is there anything else I should do in addition to press ctrl+space to get the shortcut launched ? I tryed and it did not worked for me, not sure if I should do any special config at eclipse or install any plugin to get the shortcuts enabled or there is something I am missing.
Actually you should remember the shortcut to launch them. The whole purpose of shortcut is that they are easy to remember, for example, I often use Ctrl + T to find a class and Ctrl + R to find any resource like File be it Java, JSON or XML in Eclipse
Post a Comment