Search WebSpherePower's 6,962 WebSphere, Java, and Eclipse article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
THIS WEEK'S POWERTIP
Commenting Java code the WebSphere way
By Dan Velasco

One of the first things a developer learns about Java is how to do comments. In Java, there are three basic types of comments: single line comments, multi-line comments and Javadoc comments. Learning the basic format of commenting is simple, so simple in fact you might forget that an IDE like WebSphere Studio can make it even easier. Well, WebSphere Studio can make commenting your code ever so much easier for you, and making it a little easier can go a long way toward improving your productivity and the readability of your code.

The basic way to do a single line comment in Java is to use two forward slashes, i.e. "//";. It doesn't seem too hard to type just two characters, but when you have to do it many times a day or for multiple lines it can quickly add up to a pain in the patootie. The easier way to comment code using WebSphere Studio is to first select the code you want to comment (either a single line or multiple lines) and right-click and choose Comment from the menu. If you're commenting just a single line, you can click anywhere on the line to be commented and then right-click and select Source --> Comment. You can see how this is done in Figure A. If you're a keyboard king or queen, you can also comment code by pressing CTRL + / (forward slash).

FIGURE A


You can comment a single line. Roll over picture for a larger image.

OK, so you saved a few keystrokes and kept carpal tunnel at bay for a few more minutes of your life. The really nice part of using the WebSphere Studio commenting feature is that you can also uncomment your code as easily as you commented it. Simply click on the line to be uncommented or select a block of code and right-click and select Source --> Uncomment. Or, the keyboard way is to press CTRL + \ (backslash). This will restore your code to the exact same state it was before you commented it. You can see this in Figure B.

FIGURE B


Sometimes, you just need to take back your comments. Roll over picture for a larger image.

The subtle but important difference between commenting code out manually as opposed to using WebSphere Studio to do it is that WebSphere Studio both puts the commenting characters ("//";) at the far left of the screen where they are easier to see and it also does not insert any extra spaces in a line. As you can see in the manual comment in Figure B above, there is a space between the "//"; and the comment that makes it look odd when I uncomment the line using WebSphere Studio. If I had commented it with WebSphere in the first place it would be aligned with the other code when I uncommented it.


1  ·  2  ·  Next »
Other articles you might like
Home > Java (6 articles)
   Locate your JDBC DataSource in WebSphere Application Server using JNDI
   Use WebSphere to develop Java applications for Palm handhelds
   A simple introduction to J2EE
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent WebSpherePower Articles
A perfect 10: celebrating 10 years online
You can help bring security and safety back to White House email
Introducing the WebSpherePower RSS feeds
From New Jersey to Palm Bay, Florida
A WebSphere pot o' gold
How Elvis entered the building and CES went out the window
WebSphere Application Server 6: what's it all mean?
WebSpherePower News
Excitement brewing for JavaOne 2010, with or without Google
Large companies ignore data centre advice
Onapsis to Release ERP Vulnerability Testing Suite
Botnet Takedown May Yield Valuable Data
VMware app dev platform gazes beyond SpringSource Java
IBM Claims World's Fastest Chip
'Free Java': InfoWorld's guide to the protest goodies
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Smartphone smarts for a mobile world
David Gewirtz Online: CNN commentary and analysis
DominoPower: It's time for Lotus to double-down on Linux and open source
OutlookPower: The strange case of Outlook losing notes and requiring passwords
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login