<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CertPal &#187; eclipse</title>
	<atom:link href="http://www.certpal.com/blogs/tag/eclipse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.certpal.com/blogs</link>
	<description>Technology and certifications</description>
	<lastBuildDate>Tue, 24 Aug 2010 17:47:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Eclipse tips and tricks &#8211; Part 3</title>
		<link>http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/</link>
		<comments>http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 16:00:15 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=771</guid>
		<description><![CDATA[The following eclipse tips and tricks can be used to save the time you spend writing code in the IDE. Learn how to customize key bindings ; code suggestions ; workspaces ; revert back to your local history etc. ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F" height="61" width="51" /></a></div><p style="text-align: center;"><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_logo.png"><img class="aligncenter size-full wp-image-775" style="border: 1px solid #cccccc;" title="eclipse_tips_tricks_3_logo" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_logo.png" alt="" width="128" height="128" /></a></p>
<p>Here are a few more tips / tricks with which you can save time when you use the eclipse IDE.</p>
<h2><span style="color: #333399;"><strong>Assign Key bindings:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_2.png"><img class="aligncenter size-full wp-image-781" title="eclipse_tips_tricks_3_2" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_2.png" alt="" width="655" height="411" /></a></p>
<p>Navigate to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; General -&gt; Keys</strong></span></p>
<p>You will find that there are many key bindings that are not assigned to actions that you might do on a daily basis. For example, when I start up on a new project, it is highly likely that I will introduce a lot of Value Objects (or Transfer / Data object, whatever you like to call them). A slick feature is to generate the &#8216;Getters and Setters&#8217; for them using the &#8216;Source -&gt; Generate getter and setter&#8217; command from the Main menu.</p>
<p>You can either do that or you can assign a shortcut key to this action and get it done quickly. I use Alt+Shift+Q, +G (Yeah not the easiest combination. I know <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). To restart eclipse I use Ctrl + F12. You might want to look at other bindings like</p>
<ul>
<li>Generate hashCode</li>
<li> Generate toString()</li>
<li> New package</li>
<li> New class</li>
</ul>
<p>And so on&#8230;</p>
<h2><span style="color: #333399;"><strong>Reduce number of code suggestions:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_1.png"><img class="aligncenter size-full wp-image-778" title="eclipse_tips_tricks_3_1" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_1.png" alt="" width="565" height="263" /></a></p>
<p>The shortcut I use the most in eclipse is perhaps ctrl+space. Code completion is a real time saver. It can however be annoying when you press ctrl+space more than once by mistake. This by default, brings about suggestions for SWT templates among other things. You can turn this off by navigating to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; Java -&gt; Edtior -&gt; Code Assist.</strong></span></p>
<h2><span style="color: #333399;"><strong>Import preferences:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><strong><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_7.png"><img class="aligncenter size-full wp-image-789" title="eclipse_tips_tricks_3_7" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_7.png" alt="" width="465" height="209" /></a><br />
</strong></p>
<p>If you are like me, your hard disk probably has more than 100 eclipse Workspaces. Developers usually customize their workspaces and it can take a while to do this. When you switch to the new workspace, some of the customization is lost because they were workspace specific. You can get them back easily by exporting your preferences in the old workspace and importing them again in the new one. Use the <span style="color: #333399;"><strong>File -&gt; Export / Import</strong></span> option to do this. Preferences like code formatting, code templates, default compiler settings etc will be readily available.</p>
<h2><strong><span style="color: #333399;">Remember more workspaces: (Works on myeclipse)</span></strong></h2>
<h2><strong><span style="color: #333399;"><br />
</span></strong></h2>
<p><strong><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_6.png"><img class="aligncenter size-full wp-image-786" title="eclipse_tips_tricks_3_6" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_6.png" alt="" width="489" height="131" /></a><br />
</strong></p>
<p>Use this technique to allow eclipse to give you more drop down choices when you startup. By default eclipse remembers the last 5 workspaces used. You can increase / decrease this number by navigating to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; General -&gt; Startup and Shutdown -&gt; Workspaces.</strong></span></p>
<h2><span style="color: #333399;"><strong>Associate eclipse with an external browser like firefox :</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p><strong><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_3.png"><img class="aligncenter size-full wp-image-782" title="eclipse_tips_tricks_3_3" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_3.png" alt="" width="697" height="491" /></a><br />
</strong></p>
<p>Eclipse uses the system default browser. In most cases this is IE (gulp). You can change that by defining an external browser by navigating to <span style="color: #333399;"><strong>Window -&gt; Preferences -&gt; General -&gt; Web Browser.</strong></span>. This is great when you combine it with a plugin like Firebug. You get to code and debug HTML / CSS / Javascript all at once.</p>
<h2><span style="color: #333399;"><strong>Work with local history:</strong></span></h2>
<p><span style="color: #333399;"><strong><br />
</strong></span></p>
<p>Screwed up your java file and then saved it ? Yikes. Local history comes to your rescue. Every edit and save that you make in a file is saved as a local history in eclipse. Make use of this to revert changes when necessary.</p>
<p>To use this feature, right click on the file of your choice and click <span style="color: #333399;"><strong>Compare With -&gt; Local hisory. </strong></span>That should open up the entries in the &#8216;History&#8217; view.<br />
<a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_4.png"><img class="aligncenter size-full wp-image-783" title="eclipse_tips_tricks_3_4" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_4.png" alt="" width="355" height="162" /></a></p>
<p>Clicking on any of the history entries will open a diff window telling you the difference between the current entry and the previous edits. Ah ! time is saved.</p>
<p><a href="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_5.png"><img class="aligncenter size-full wp-image-784" title="eclipse_tips_tricks_3_5" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_tips_tricks_3_5.png" alt="" width="747" height="156" /></a></p>
<p>This is a 3 part article. If you would like to browse through the other tips, you can find them here</p>
<p><a href="http://www.certpal.com/blogs/2009/08/eclipse-tips-and-tricks-part-1/" target="_blank">Eclipse tips and tricks</a> &#8211; Part 1</p>
<p><a href="http://www.certpal.com/blogs/2009/09/eclipse-tips-and-tricks-part-2/" target="_blank"> Eclipse tips and tricks </a> &#8211; Part 2</p>
<p><script type="text/javascript">// <![CDATA[
  var dzone_url = 'http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
  var dzone_title = 'Eclipse tips and tricks';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
  var dzone_blurb = 'The following eclipse tips and tricks can be used to save the time you spend writing code in the IDE. Learn how to customize key bindings ; code suggestions ; workspaces ; revert back to your local history etc. ';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
  var dzone_style = '2';
// ]]&gt;</script><br />
<script src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F06%2Feclipse-tips-and-tricks-part-3%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/06/eclipse-tips-and-tricks-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Eclipse and the conflicting shortcut problem</title>
		<link>http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem/</link>
		<comments>http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 06:14:22 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=677</guid>
		<description><![CDATA[Eclipse shortcuts can sometimes conflict with the ones defined by other applications. These series of steps should help you resolve these conflicts]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F" height="61" width="51" /></a></div><p><a href="http://www.certpal.com/blogs/wp-content/uploads/shortcut_failure.png"><img class="alignright size-full wp-image-682" title="shortcut_failure" src="http://www.certpal.com/blogs/wp-content/uploads/shortcut_failure.png" alt="" width="165" height="143" /></a>I moved all development activities to linux recently. Part of the migration process involved getting used to some new apps like <a href="http://kopete.kde.org/" target="_blank">Kopete</a> / Pidgin / KDE Snapshot etc. It was a breeze until I started debugging my code in eclipse.</p>
<p>I frequently use the eclipse keyboard shortcuts to cut down the time I spend coding / debugging. One of my favorite is Ctrl + Shift + i , which will open up the inspection box for a particular variable. This shortcut just did not work. For quite a few days I did not understand why. The other shortcuts like fix imports ( ctrl + shift + o ) seemed to be working fine. That&#8217;s when I stumbled across a <a href="http://docs.kde.org/stable/en/kdenetwork/kopete/configuring.html" target="_blank">kopete shortcut</a>.</p>
<p>The shortcut Ctrl + Shift + i was also used by kopete to read messages. According to the documentation this was a global short cut that was valid in any KDE application. I closed kopete just to confirm that it was contributing to the problem and voila, Ctrl + Shift + i started to work inside eclipse once again. So the next time a shortcut does not work in eclipse you might want to</p>
<ol>
<li>Look at the Wondow -&gt; Preferences -&gt; Keys and ensure that the key is bound.</li>
<li>If it is bound, check other applications and make sure this is not a global shortcut used elsewhere.</li>
<li>If it is a global shortcut, change the key binding in eclipse or the other application.</li>
<li>Relax</li>
</ol>
<p><script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem';</script><br />
<script type="text/javascript">var dzone_title = 'Eclipse and the conflicting shortcut problem';</script><br />
<script type="text/javascript">var dzone_blurb = 'Eclipse shortcuts can sometimes conflict with the ones defined by other applications. These series of steps should help you resolve these conflicts';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2010%2F04%2Feclipse-conflicting-shortcuts-problem%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2010/04/eclipse-conflicting-shortcuts-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse tips and tricks &#8211; Part 2</title>
		<link>http://www.certpal.com/blogs/2009/09/eclipse-tips-and-tricks-part-2/</link>
		<comments>http://www.certpal.com/blogs/2009/09/eclipse-tips-and-tricks-part-2/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 13:34:21 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=197</guid>
		<description><![CDATA[The following eclipse tips and tricks can be used to save the time you spend writing code in the IDE. In this article we look at the debugging tips and tricks that can be used with eclipse. Using these techniques can squash your bugs faster.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Feclipse-tips-and-tricks-part-2%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Feclipse-tips-and-tricks-part-2%2F" height="61" width="51" /></a></div><p>Eclipse can be used to debug your java applications. Here are a few tips that can help you debug better</p>
<h2><span style="color: #0000ff;"><strong>Remote debugging:</strong></span></h2>
<p>The eclipse IDE can remote debug your web application. Imagine being able to debug your development server from your local machine. Eclipse can help you do this. First you need to instruct your application / server to listen on a port for debug messages. That can be done using the -Xdebug flag</p>
<p><strong>java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787,suspend=n</strong></p>
<p>This tells the JVM to listen for specific debug messages on port 8787. In eclipse open <strong>Bug Icon -> Debug configurations</strong> and select &#8220;Remote java application&#8221;. Mention the port and server address and you should now be able to remote debug the application. Make sure that the classes and source sync with each other. On a network where the bandwidth is poor, this technique will not work.</p>
<p><strong>Remote java application:</strong></p>
<p><img class="aligncenter size-full wp-image-198" title="eclipse_debug_remote" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_remote.png" alt="eclipse_debug_remote" width="632" height="263" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Use the display view:</strong></span></h2>
<p>The debug perspective in eclipse can open up a &#8220;<strong>Display</strong>&#8221; view that allows you to dynamically enter some code for execution when you hit a breakpoint. This view is priceless. You can dynamically execute code related to the variables that are in scope. Use the icons available on the top right hand corner of the view to do this.</p>
<p><strong>Display view:</strong><br />
<img class="aligncenter size-full wp-image-201" title="eclipse_debug_display" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_display.png" alt="eclipse_debug_display" width="534" height="434" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Set breakpoints at different levels:</strong></span></h2>
<p>You can set class level, method level or line level breakpoints. Nothing special but once again it can save you time. Just set a breakpoint corresponding to a class declaration a method declaration or a specific line.<br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Set conditional breakpoints:</strong></span></h2>
<p>Breakpoints can be triggered conditionally.  Simple right click on a breakpoint and select &#8216;Breakpoint properties&#8221; There are 3 settings that you can tweak.</p>
<ol>
<li><strong>Hit count</strong> &#8211; Break only when code flow passes over this breakpoint N times.</li>
<li><strong>Condition</strong> &#8211; Break when a specific programmatic condition is reached.</li>
<li><strong>Suspend VM Vs Suspend Thread</strong> &#8211; This is useful when debugging multithreaded application. If you want to suspend only the current thread and not all threads that are running through this code flow, you can use this drop down.</li>
</ol>
<p><strong>Breakpoint properties:</strong></p>
<p><img class="aligncenter size-full wp-image-202" title="eclipse_debug_breakpoint_properties" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_breakpoint_properties.png" alt="eclipse_debug_breakpoint_properties" width="263" height="237" /></p>
<p><strong>Tweak the breakpoint:</strong></p>
<p><img class="aligncenter size-full wp-image-203" title="eclipse_debug_breakpoint_properties_2" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_breakpoint_properties_2.png" alt="eclipse_debug_breakpoint_properties_2" width="616" height="514" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Specify a detail formatter of your own:</strong></span></h2>
<p>Use the Variables view to mention a detailed formatter for an object type. This will display the object in question in a different format when you look it up under Variables or in an inspection window.</p>
<p><strong>Open the detail formatter:</strong></p>
<p><img class="aligncenter size-full wp-image-204" title="eclipse_debug_detail_formatter" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_detail_formatter.png" alt="eclipse_debug_detail_formatter" width="324" height="383" /></p>
<p><strong>Type a detail format:</strong></p>
<p><img class="aligncenter size-full wp-image-205" title="eclipse_debug_detail_formatter_2" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_detail_formatter_2.png" alt="eclipse_debug_detail_formatter_2" width="450" height="380" /></p>
<p><strong>See the results in the variable window (among other places):</strong></p>
<p><img class="aligncenter size-full wp-image-206" title="eclipse_debug_detail_formatter_3" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_detail_formatter_3.png" alt="eclipse_debug_detail_formatter_3" width="637" height="248" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Use inspection windows:</strong></span></h2>
<p>Inspection windows can reveal the detailed object graph of the instance in question. Simply highlight the variable and type the shortcut ctrl+shift+i</p>
<p><strong>Inspect:</strong></p>
<p><img class="aligncenter size-full wp-image-207" title="eclipse_debug_inspection" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_inspection.png" alt="eclipse_debug_inspection" width="482" height="103" /></p>
<p><strong>Traverse the object graph:</strong></p>
<p><img class="aligncenter size-medium wp-image-208" title="eclipse_debug_inspection_2" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_inspection_2-300x153.png" alt="eclipse_debug_inspection_2" width="300" height="153" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Use all instances / references:</strong></span></h2>
<p>Use the all instances / all references option in the Variables view to determine the usage of a particular Object type at runtime. Arguably a profiler might be better suited for this sort of work, but hey, you never know when you might need it.</p>
<p><strong>View all instances of an object type:</strong></p>
<p><img class="aligncenter size-full wp-image-209" title="eclipse_debug_all_instances" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_all_instances.png" alt="eclipse_debug_all_instances" width="315" height="391" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Change variable values dynamically:</strong></span></h2>
<p>You can use the <strong>Variables</strong> view to change the value of a variable dynamically. This helps to determine code flow control if you have conditional statements. You could also do the same using the Display view but the GUI helps.</p>
<p><strong>Change value:</strong></p>
<p><img class="aligncenter size-full wp-image-210" title="eclipse_debug_change_value" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_change_value.png" alt="eclipse_debug_change_value" width="347" height="383" /><br />
<br/><br/></p>
<h2><span style="color: #0000ff;"><strong>Use the drop to frame feature:</strong></span></h2>
<p>The &#8220;drop to frame&#8221; feature allows you to retrace your path after making a minor code change. The code flow goes back to the line of code you have dropped to and executes once again. You could even, say, change a database variable and drop back a few call stacks behind to retrace your steps.</p>
<p><strong>Drop frame:</strong></p>
<p><img class="aligncenter size-medium wp-image-211" title="eclipse_debug_drop_frame" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_debug_drop_frame-300x118.png" alt="eclipse_debug_drop_frame" width="300" height="118" /></p>
<p>Thats about the list of debugging tips I know. Do you have one that could help other developers ? Drop a comment. There is one more article on eclipse productivity coming down the line. Subscribe to the <a href="http://feeds.feedburner.com/Certpal" target="_blank">RSS feed</a> if you would like to keep up to date.<br />
<script type="text/javascript">var dzone_url = 'http://www.certpal.com/blogs/2009/09/better-productivity-with-eclipse-%e2%80%93-part-2/';</script><br />
<script type="text/javascript">var dzone_title = 'Better productivity with eclipse – Part 2';</script><br />
<script type="text/javascript">var dzone_blurb = 'In this article we look at the debugging tips and tricks that can be used with eclipse. Using these techniques can squash your bugs faster.';</script><br />
<script type="text/javascript">var dzone_style = '2';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Feclipse-tips-and-tricks-part-2%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F09%2Feclipse-tips-and-tricks-part-2%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2009/09/eclipse-tips-and-tricks-part-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Eclipse tips and tricks &#8211; Part 1</title>
		<link>http://www.certpal.com/blogs/2009/08/eclipse-tips-and-tricks-part-1/</link>
		<comments>http://www.certpal.com/blogs/2009/08/eclipse-tips-and-tricks-part-1/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 14:09:33 +0000</pubDate>
		<dc:creator>CertPal</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=170</guid>
		<description><![CDATA[The following eclipse tips and tricks can be used to save the time you spend writing code in the IDE. Write code faster by defining your own code templates. This article describes how you can get started doing the same.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Feclipse-tips-and-tricks-part-1%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Feclipse-tips-and-tricks-part-1%2F" height="61" width="51" /></a></div><p>Eclipse is a pretty good IDE to develop java apps on. However there are some features that you might not be using every day that can save you a lot of time.</p>
<p>Writing your own code templates is one of them. To write your own code template do the following</p>
<p>Go to <strong>Window -&gt; Preferences. Select Java -&gt; Editor -&gt; Templates</strong>. You can add your own templates here. Templates are nothing but the code that auto completes when you press ctrl+space. For example type <strong>syso </strong>and <strong>ctrl+space</strong>. This will automatically fill in System.out.println() into the editor.</p>
<p><strong>Eclipse code templates:</strong><br />
<img class="aligncenter size-full wp-image-180" title="eclipse_code_template" src="http://www.certpal.com/blogs/wp-content/uploads/eclipse_code_template.png" alt="eclipse_code_template" width="707" height="550" /><br />
<strong>Code template variables:</strong></p>
<p>Eclipse can automatically fill out dynamic code by sniffing out variables in a template. Here are a few you should make yourself aware of</p>
<p><strong>${cursor} </strong>- Place the cursor here after code completion<br />
<strong>${enclosing_method}</strong> &#8211; Replace this with the method name where the code completion was called.<br />
<strong>${enclosing_method_arguments}</strong> &#8211; Replace this with the enclosing method arguments<br />
<strong>${enclosing_type}</strong> &#8211; The enclosing class name<br />
<strong>${import}</strong> &#8211; Dynamically import some classes<br />
<strong>${importStatic}</strong> &#8211; Same as above but with static imports<br />
<strong>${time}</strong> &#8211; Current time<br />
<strong>${todo} </strong>- The //TODO eclipse task</p>
<p>We can now go ahead and define some useful templates. When you type the name of any of these templates and press <strong>ctrl+space</strong> your custom code will be auto completed. Click on the <strong>New</strong> button to add a template</p>
<p><strong>Name:</strong>call<br />
<strong> Description:</strong>Log once inside a method. When you type call and <strong>ctrl+space</strong> a small snippet is auto completed that will print out to the console the method name that is being called and its arguments.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Called: Class: ${enclosing_type} Method: ${enclosing_method} Args: ${enclosing_method_arguments}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Name:</strong>go<br />
<strong> Description:</strong>Write a program with a main method real quick. Just type go and <strong>ctrl+space</strong> and be on your way to writing a small program.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">new</span> $<span style="color: #009900;">&#123;</span>enclosing_type<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">go</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> go<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#123;</span>cursor<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Name:</strong>log<br />
<strong> Description:</strong>Automatically instantiate a log4j static variable for this class. Also import the necessary classes that we need for log4j. Of course we assume that log4j is in the classpath <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Logger s_logger <span style="color: #339933;">=</span> LogManager
.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#123;</span>enclosing_type<span style="color: #009900;">&#125;</span>.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#123;</span>imp<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">import</span><span style="color: #009900;">&#40;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">log4j</span>.<span style="color: #006633;">LogManager</span>,
org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">log4j</span>.<span style="color: #006633;">Logger</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Name:</strong>deb<br />
<strong> Description:</strong>Log4j debug statement (Do the same for info,warn)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">s_logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;${cursor}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Name:</strong>err<br />
<strong> Description:</strong>Log4j error. Print an error message and print the stack trace on the console.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">s_logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;An error occurred: ${cursor}&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Name:</strong>tryf<br />
<strong> Description: </strong>A variation of the try catch code completion. This one includes finally also</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#123;</span>line_selection<span style="color: #009900;">&#125;</span>$<span style="color: #009900;">&#123;</span>cursor<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#123;</span><span style="color: #003399;">Exception</span><span style="color: #009900;">&#125;</span> $<span style="color: #009900;">&#123;</span>exception_variable_name<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#123;</span>exception_variable_name<span style="color: #009900;">&#125;</span>.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">finally</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ${todo}: Clean up</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>There are many more examples you can think of by yourself. Explore the existing code completions that come with eclipse too. I hope that saves you as much time as it has for me. I will be writing 2 more follow up articles on eclipse. Subscribe to the <a href="http://feeds.feedburner.com/Certpal" target="_blank">RSS feed</a> if you would like to keep up to date.<br />
<script type="text/javascript">// <![CDATA[
var dzone_url = 'http://www.certpal.com/blogs/2009/08/better-productivity-with-eclipse-part-1/';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var dzone_title = 'Better productivity with eclipse - Part 1';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var dzone_blurb = 'Write code faster by defining your own code templates. This article describes how you can get started doing the same.';
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var dzone_style = '2';
// ]]&gt;</script><br />
<script src="http://widgets.dzone.com/links/widgets/zoneit.js"></script></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Feclipse-tips-and-tricks-part-1%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.certpal.com%2Fblogs%2F2009%2F08%2Feclipse-tips-and-tricks-part-1%2F" height="61" width="51" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.certpal.com/blogs/2009/08/eclipse-tips-and-tricks-part-1/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
