Tuesday, July 27, 2010

Using the Tasks view effectively in Eclipse

There are times while coding when I know I have to do something, but it will take some time, so I decide to leave it for later. To remember the tasks I left, I'm using Eclipse Tasks, by writing a comment in the source, starting with "TODO". Before committing anything to a source repository, I always check that I don't have any unfinished tasks.

The Tasks view can be displayed via Window->Show View->Tasks. It shows a list of tasks. The default settings shows various type of tasks, including those with the word "TODO" or "FIXME" in it. In our project, there are a lot of unwanted TODOs left in the source. They all show up in the Tasks view.

Using a TODO is inconvenient, because I can't easily tell which are mine. The solution is to use a filter. Instead of writing a comment with "TODO ...", I use a comment with "TODO CHRIS...". By setting a filter in the Tasks view, I can show only tasks containing "TODO CHRIS".

In Eclipse Helios Tasks view, click the View Menu (the icon shaped as an arrow pointing downwards). Select Configure Contents. Then press New... to make a new configuration. I set the scope to "On any element". I leave all the Completed, Priority and Types check boxes selected. Set the description to "contains" and "TODO CHRIS". This will include my comments. Finally, I check my configuration, set the "show results matching" to "Any enabled filter" and press OK. Voila ! All unwanted default tasks disappear, and only my own tasks are shown.

By the way, default Task Tags in Java comments can be configured in the Preferences, in Java->Compiler->Task Tags. Default tags include "FIXME", "TODO" and "XXX".

Monday, July 26, 2010

My top 10 Eclipse keyboard shortcuts

Keyboard shortcuts are time-savers. Surprisingly, not many people around me use them. Programming is much more fun when you can control most of the action via the keyboard. I introduce some of the shortcuts I use the most in Eclipse. I don't bother mentioning some very common ones, like Ctrl+S for saving, or the king of all, Ctrl+Space, for auto-completion. Here is my top 10 Eclipse keyboard shortcuts to beat the uninitiated.

Ctrl+. : Navigate to the next item. When there are errors in the source, this jumps to the next error. The uninitiated uses his mouse and clicks on the little red square, or clicks in the Problem view, or worse, PgUps/PgDowns to the error. Press Ctrl+. while he is still scrolling his way to the error.

Ctrl+1 : Quick Fix. This will bring a list of possible fixes for errors. For example, on a method which does not exist, it will show fixes like "Create method in...", "Rename method to...", etc... The uninitiated hovers over the error to display the quick fix, which is not so bad after all. But the Ctrl+. Ctrl+1 double combo leaves him way behind.

Ctrl+E : Quick Switch Editor. Open the editor drop down list. Very useful when you have many resources open. The uninitiated clicks on a tab. When there are too many tabs, he clicks on the "Show List" icon and looks for his tab in the list, without even typing the name of the tab, because he still has his hands scotched on the mouse.

Ctrl+Shift+G : Search for references in workspace. Use this on variables, methods, classes to quickly find out where they are used. This one always leaves the uninitiated on their butt :)

Ctrl+Shift+R : Open resource. When you get used to a project and want to quickly jump to a resource, like a properties file, this is very useful. The uninitiated browse through the Package Explorer or Navigator view to find it.

Ctrl+Shift+T : Open type. Like the previous shortcut, but for types. I use it a lot.

Alt+Shift+R : Rename and refactor. This allows to not only rename a variable, method, class, etc..., but also to refactor the places which use the entity being renamed. The uninitiated renames it by hand, and goes through all errors to fix it. I'm exaggerating, aren't I ? But, I'm curious to know how many uninitiated go to the Navigator view, right-click on a class, and choose "Rename..." to rename a class ?

Ctrl+O : Quick outline. In a class, this allows to quickly jump to a method. The uninitiated uses the Outline view, or worse, Ctrl+F (ouch). Ctrl+O is a knock out shortcut.

Ctrl+Shift+O : Organize imports. I always leave Eclipse manage imports. Especially for unused imports. Auto-completion also takes care of the imports most of the time. The uninitiated uses his mouse to do the same.

Ctrl+F8 : Select perspective. Press repeatedly to cycle through available perspectives. Again, the uninitiated uses his mouse.

That's it ! I don't think that you have to remember a lot of shortcuts to increase your productivity, but these surely help me increase it. Think about the actions you often do and make your own list !

Friday, July 23, 2010

Removing unwanted kernels in Ubuntu and updating Grub2 configuration

The installation of a new kernel adds two new entries in the Grub menu. I have set the default selected entry to something different from the first item, so each time a new kernel is installed, the default entry points to the wrong menu item. Using update-grub will automatically update all Grub2 configuration files, and that's when the kernels present in the file system are automatically detected (Grub2).

I want to remove the old kernels, which I won't need anymore. There are several ways to do it. I'll show how to do it on the command line. First, let's list the installed kernels

dpkg -l | grep linux-im

ii linux-image-2.6.32-23-generic 2.6.32-23.37 Linux kernel image for version 2.6.32 on x86
ii linux-image-2.6.32-24-generic 2.6.32-24.38 Linux kernel image for version 2.6.32 on x86
ii linux-image-generic Generic Linux kernel image

Here, we see package names and package version numbers. The syntax to completely remove packages is "apt-get purge packagename". Let's remove the unwanted kernel image, which is 2.6.32-23.37. The string used after "purge" is a regular expression. I don't bother to escape it.

sudo apt-get purge .*.2.6.32-23

All packages matching this regular expression will be completely removed. This operation must be done with caution. Fortunatly, before packages are removed, a confirmation will be displayed (in Japanese in my local environment):

linux-headers-2.6.32-23* linux-headers-2.6.32-23-generic*
アップグレード: 0 個、新規インストール: 0 個、削除: 3 個、保留: 0 個。
この操作後に 184MB のディスク容量が解放されます。
続行しますか [Y/n]? Y

This shows that three packages will be removed. That's what I was expecting. After accepting the changes, the Grub configuration will be automatically updated ! No need to update it yourself.

Running postrm hook script /usr/sbin/update-grub.
Generating grub.cfg ...
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-24-generic
Found initrd image: /boot/initrd.img-2.6.32-24-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Microsoft Windows XP Home Edition on /dev/sda1
Found Windows NT/2000/XP on /dev/sda3

Voila ! The unwanted kernels should be gone from the file system and from the Grub menu.

Thursday, July 22, 2010

Griffon 0.9 released

Griffon 0.9 is out, with a bunch of bug fixes and new features. Once thing which caught my eyes was Spock. It's not a name easy to miss ! But it's the first time I hear about it. Yet another framework on my todo list.

Sadly, I've stopped studying Griffon recently. My lack of Groovy/Grails knowledge is wasting all the fun. I've decided to study Groovy and Grails first, as Griffon is not only based on Groovy, but it also gets a lot of its inspiration from Grails. I bought Grails In Action and started studying it. There's a whole chapter on Groovy basics. Developping Grails application helps to get used to it. I must say that this is a very cool framework ! Once I'm finished with it, I plan to go back to Griffon, and restart reading Griffon In Action's MEAP book.

I'm late to dive into the Groovy world. There's so much I have to do to get back on tracks. But the efforts are well worth it. Groovy is fun. Grails is fun. But I'm yet to know just how fun it can be.

Friday, July 9, 2010

Preventing services to startup at boot time in Ubuntu

After installing Tomcat6 via the Synaptic package manager, Tomcat is automatically started at boottime. This was fine, until I started playing with Grails. Without changing any configuration settings, Grails will start its own web server instance at the default http port, 8080, the same as Tomcat's default. This results in an error when trying to start a Grails application :

grails run-app

Server failed to start: java.net.BindException: Address already in use

There are different ways to avoid this error. Make Grails use Tomcat's instance, change either Grails or Tomcat's default http port, or don't start Tomcat at boot time. I decided to remove Tomcat's automatic startup. How do we do that in Ubuntu ?

Init scripts are in /etc/init.d, and symbolic links to these scripts are separated in runlevels, each residing in /etc/rcX.d/, where X is the runlevel. We could remove them by hand, but this can be done easily with one single command : update-rc.d

sudo update-rc.d tomcat6 disable

update-rc.d: warning: tomcat6 start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: tomcat6 stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)
Disabling system startup links for /etc/init.d/tomcat6 ...
Removing any system startup links for /etc/init.d/tomcat6 ...
Adding system startup for /etc/init.d/tomcat6 ...
/etc/rc0.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc1.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc6.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc2.d/K80tomcat6 -> ../init.d/tomcat6
/etc/rc3.d/K80tomcat6 -> ../init.d/tomcat6
/etc/rc4.d/K80tomcat6 -> ../init.d/tomcat6
/etc/rc5.d/K80tomcat6 -> ../init.d/tomcat6

There are a couple of warning because I used the disable command without any parameters. These can be ignored. As the man page says : "If no start runlevel is specified after the disable or enable keywords, the script will attempt to modify links in all start run‐levels.". Enabling back the service at bootime is as simple (same warnings):

sudo update-rc.d tomcat6 enable

update-rc.d: warning: tomcat6 start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: tomcat6 stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)
Enabling system startup links for /etc/init.d/tomcat6 ...
Removing any system startup links for /etc/init.d/tomcat6 ...
Adding system startup for /etc/init.d/tomcat6 ...
/etc/rc0.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc1.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc6.d/K20tomcat6 -> ../init.d/tomcat6
/etc/rc2.d/S20tomcat6 -> ../init.d/tomcat6
/etc/rc3.d/S20tomcat6 -> ../init.d/tomcat6
/etc/rc4.d/S20tomcat6 -> ../init.d/tomcat6
/etc/rc5.d/S20tomcat6 -> ../init.d/tomcat6

To disable the running service without having to reboot:

sudo /etc/init.d/tomcat6 stop

* Stopping Tomcat servlet engine tomcat6 [ OK ]

After that, Grails applications will be happy to run:

grails run-app

Welcome to Grails 1.1.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/local/lib/grails-1.1.1

Base Directory: /home/kuriqoo/eclipse/workspace/hubbub
Running script /usr/local/lib/grails-1.1.1/scripts/RunApp.groovy
Environment set to development
Running Grails application..
Server running. Browse to http://localhost:8080/hubbub

Tomcat can be manually started using :

sudo /etc/init.d/tomcat6 start

* Starting Tomcat servlet engine tomcat6
Using CATALINA_BASE: /var/lib/tomcat6
Using CATALINA_HOME: /usr/share/tomcat6
Using CATALINA_TMPDIR: /tmp/tomcat6-tmp
Using JRE_HOME: /usr/lib/jvm/java-6-openjdk
Using CLASSPATH: /usr/share/tomcat6/bin/bootstrap.jar [ OK ]

Thursday, July 8, 2010

Oracle updating the Sun Java Certifications

Oracle is starting to change the Sun Certifications. There are already four exams in Beta stage :

* Sun Certified JPA Developer for the Java EE6 Platform
* Sun Certified Developer for the Java Web Services for the Java EE6 Platform
* Sun Certified JSP and Servlet Developer for the Java EE6 Platform
* Sun Certified EJB Developer for the Java EE6 Platform

SCBCD5.0 included JPA1.0 in it. Now JPA has its own exam, so if you want to be a Business Component Developer, you'll have to pay two exams. Beta exams were free in the past. Oracle has decided to get a few bucks out of them. You pay $50 to attend the Sun Certified JSP and Servlet Developer for the Java EE6 Platform beta exam, and spend 3 to 5 hours answering 215 questions ! Good luck. The exam objectives are still very evasive, contrary to the old ones which were very detailed. I mean, in the JPA certification, what is "Optimize database access" and "Use advanced JPA features" supposed to include ? If I decide to upgrade one day, I'll wait for the official one. No beta for me.

JavaRanch and the Big Moose Saloon

JavaRanch and its Big Moose Saloon is a great place to go for anybody interested in Java. If you have a Java problem, go there. If you want to pass a Sun (Oracle) certification like SCJP, SCWCD, SCBCD..., go there. There are also forums for Groovy, Scala, Javascript...

Some of the top reasons why you should be a member :

1. It's a very friendly place. No insults. No "you don't even know that ??" kind of mockery. When you sign there, the first thing you are told is to "Be Nice". It's the number one JavaRanch policy. It's a nice place.
2. The place is kept clean by a bunch of bartenders and sheriffs (ranchy names for moderators), whose first rule is also to "Be Nice". There's no exception to the rule. We are all here to help each other.
3. You'll find people answering your problems relatively quickly. I rarely see questions left unanswered.
4. Answers are usually checked by moderators, leading into constructive arguments or more elaborate answers.
5. You'll find great materials and advices to pass the Sun certifications. Advices given by other members who actually passed the exam.
6. You'll meet book authors, some of them being regual members.
7. One of the original goal of the forum was to help people. So insteading of giving away code snippets for coding problems, we tend to lead people toward the answer, to make them think by themselves. This may take some time, but it's really worth it.
8. The ranch listens to you, and you can help it change. If you have any request concerning the forums, people will listen to you, and debate whether or not your ideas could be applied.
9. You'll have a chance to win free books ! A book promotion is conducted almost every week, where book or software authors spend a week answering members' questions about their product. Don't miss it.

I love being there, helping others solving their problems. I learned a lot thanks to the ranch. Not only about Java, but also about dealing with problems. It's also a great motivation to be there, being surrounded by software experts. It's sometimes challenging to "Be Nice". I think things would easily get out of hands in other forums. But not at JavaRanch. You'll be in good hands.

So, what are you waiting for ? Join this great community.

Sunday, July 4, 2010

Book review : Beginning Oracle Database 11g Administration: From Novice to Professional

I have finished reading the book "Beginning Oracle Database 11g Administration: From Novice to Professional (APress)", by Iggy Fernandez. First of all, I am not a DBA. I'm using Oracle at work, but, most of the time, I'm only using basic SQL. I have nothing to do with database administration, but recently I wanted to know more about Oracle, and this book is just what I needed. The author doesn't go deeply into details, which that is not the purpose of the book. He introduces the most important topics (installation, monitoring, backups, recoveries, tuning...) in a very understandable manner. I don't think that this book will turn anyone into an Oracle Professional, as the title suggests, but it does cover enough material to make you more than a novice. I recommend it highly to anyone who wants to know the basic notions of the Oracle architecture and administration.

I plan to buy "Expert Oracle Database Architecture: Oracle Database Programming 9i, 10g, and 11g Techniques and Solutions" by Thomas Kyte, which is planned to be published this month. For the moment, I'll start reading the Oracle Concepts PDF file, which is available online.