Categories
Uncategorized

5 Ways to Boost Your Efficiency with Eclipse

Shortcuts

Learn to use the shortcuts. Seriously!

Did you know that if you need to scroll suddenly while typing, you don’t need to reach out for your mouse? Just use the Ctrl or the Ctrl key combinations to scroll up or down.

To learn more about Eclipse shortcuts, head over to TechNonStop’s tutorial on Eclipse Shortcuts.

Templates

Templates are a must-learn – there are so many out there.

For example, sysout, syserr, and systrace.

Look up Window->Preferences->Java->Editor->Templates for all the pre-defined templates available, and don’t forget to add your own!

Often, those working on a single project would like to share templates they create so that the whole team enjoys the shortcuts.

Eclipse Preferences - Java templates

Tweaks to eclipse.ini

I’ve had a noticeable improvement in startup time and overall response times on my Eclipse installation by adding the following to eclipse.ini, at the bottom:

-Xincgc 
-XX:-DontCompileHugeMethods 
-XX:MaxInlineSize=1024  
-XX:FreqInlineSize=1024 

Source: Nerds-Central: Tuning The JVM For Unusual Uses – Have Some Tricks Under Your Hat

Also, tweak the Xms (initial heap size) and Xmx (maximum heap size) to higher values, depending on your RAM and the number of other running applications, or in the event that Eclipse gives you nasty “OutOfMemory” errors. 384m and 1024m respectively for Xms and Xmx work well on my 4 GB machine.

Note: The above optimizations are for Sun’s Java 7. If you use another JDK version, look up this StackOverflow.com thread for optimizations that have worked for others.

Useful Plugins

Mylyn is an excellent plugin to keep track of your TODOs. The Java EE version of Eclipse has this plugin installed, as well as others that are quite useful. Examples are the Web Page Editor for HTML editing, and the XML editor for XML editing.

Use your version control system’s plugin for Eclipse, so that code check-ins can be done from within.

The JDEclipse Decompiler plugin is useful for class decompilation.

Google’s CodePro Analytics is great to analyze and improve the quality of your code.

Eclipse color themes has a cool plugin for changing color themes.

There’s also this cool JSON Editor Eclipse Plugin.

Whatever plugins you use, ensure that you turn them off on startup. Go to General->Startup and Shutdown, and uncheck ALL plugins listed. Also, disable or uninstall the ones you don’t need.

Improve General Eclipse Knowledge

Did you know that you can use the Navigator View (rather than the Package explorer) to see all the files present, including .project files and the bin directory?

Did you know you could just paste exception stack traces into the Java Stack Trace console, and lines numbers turn into hyperlinks?

Use the documentation to keep improving your general knowledge on Eclipse, and for more tips and tricks!

Add shortcuts to related external tools

Yes, I did say 5, but here’s a bonus!

Using the External Tools Configuration window (accessible from the External Tools icon in the toolbar), add shortcuts to scripts that automate commonly run tasks.

For example, I have a script that does the following: syncs down latest code, builds it and runs the test cases after deploying the newly generated artifacts to a locally running server. Adding a shortcut to this within Eclipse has greatly eased the way I run the script and refresh my workspace after it completes.

Categories
Uncategorized

Five Reasons to Adopt Linux, Today!

The popular open source news site LXer recently published a detailed article on the advantages of Linux, with the aim of dispelling unfair cynicism.

Whether you are a home user or a business owner, Linux is a great choice for an operating system. I entered the Linux world pretty recently, after spending a long time with various Microsoft Windows versions. Now, there’s no looking back!

I’ve identified the top 5 reasons to consider turning to Linux:

1) Cost of operating your computer.

Microsoft Windows offers various paid license plans to run your computer, or install copies on several machines in a network. When you turn to Linux, software that runs your computers is completely free!

This is a great advantage for both home users and businesses who are seeking to cut costs.

2) The spirit of sharing.

Linux is based on sharing and caring. Linux is often the force behind social initiatives that bring computing power to less privileged children and people in war ravaged areas.

When you adopt Linux, you are automatically enrolled into community service – pure material aims take a backseat.

3) Vibrant support communities.

There are extremely active support communities that help users of various distros troubleshoot their problems. The AskUbuntu forums which I’ve used for my Ubuntu system is just one of countless examples. Experienced users will patiently help you run your computer flawlessly, without asking even a cent for it.

If you’re new to Linux, you surely won’t feel lost.

Paid support is also available from companies specializing in it, especially at the enterprise level.

4) Security.

Linux provides the harshest environment for viruses to live. Open source software is collaboratively scrutinized by developers from around the world, which means that viruses will be busted well before they make it to your computers.

You do need anti-viruses on a Linux box, at times. These are chiefly meant for scanning Windows drives, or viruses that execute themselves with Wine!

5) Linux encourages you to be tech savvy.

What is more gratifying than knowing the what, where, when, how and why of the software that powers your computer?

If you’re an Apple user, you’ll typically head straight to the nearest Mac genius for help in times of distress. As a Windows user, you’ll probably hesitate to venture beyond the basic troubleshooting methods.

Linux users set a very different example. They try to get to the bottom of every problem themselves (if they ever come), get help from worldwide networks of users if they’re stuck, and ensure that they’ve straightened out issues with their operating systems.

Linux has retained the way the classical Unix operating system works. Most servers today run Unix-like operating systems – if you’re technically inclined and get accustomed to using Linux, you’re getting to know how operating systems worked in their original design.

Sounds cool?

Choose from an array of distros, and get ready to go the Linux way!

What has been the most compelling reason for you to adopt Linux and stay with it? Are you skeptical about using Linux? Use the comment form below and speak your mind!

Categories
Uncategorized

Setting up the DB2 database on Ubuntu and testing JDBC connectivity

I got my DB2 database installation running on a Ubuntu 11.10 machine recently, and have documented the steps I carried out below.

Downloading DB2

The express edition is free, and can be downloaded from Download DB2 Express-C. You’ll need to register for an IBM id if you don’t already have one.

Download DB2 Express C Using HTTP

Extracting and installing

Use the command tar -zvxf db2exc_975_LNX_x86.tar.gz to extract the gzipped file. Run the installer using sudo ./db2setup, and choose “Install a Product” on the left menu. The installation process is quite straightforward after this point.

DB2 Setup Launchpad - Install a Product as root

Troubleshooting libaio.so.1 ‘not found’ when running db2setup

I faced the following problem when I ran the setup script:


$ sudo ./db2setup
ERROR: 
   The required library file libaio.so.1 is not found on the system. 
   Check the following web site for the up-to-date system requirements
   of IBM DB2 9.7
   http://www.ibm.com/software/data/db2/udb/sysreqs.html
   http://www.software.ibm.com/data/db2/linux/validate  
  Aborting the current installation ...
  Run installation with the option "-f sysreq" parameter to force the installation.

To fix it, I had to run sudo apt-get install libaio-dev to install the missing package.

Verifying the Installation

The following command verifies the db installation and configured instances:

sudo /opt/ibm/db2/V9.7/bin/db2val -a

Creating a database

Switch to the user account that is the owner of the instance (db2inst1 is the default).

$ su db2inst1

Switch to the bash shell if necessary:

$ bash

Under this user account, you can run DB2 commands as illustrated below. Note that the create database command takes time – it took several minutes on my machine.


$ db2 create database test
DB20000I  The CREATE DATABASE command completed successfully.
$ db2 connect to test

   Database Connection Information

 Database server        = DB2/LINUX 9.7.5
 SQL authorization ID   = DB2INST1
 Local database alias   = TEST

$ db2 "create table test.technonstop(id int, username varchar(200))"
DB20000I  The SQL command completed successfully.
$ db2 "INSERT INTO test.technonstop VALUES(1, 'abdullah')"
DB20000I  The SQL command completed successfully.

Troubleshooting

If you’re unable to run any db2 command, the db2 environment variables may not have been sourced. To do it, run the following command at the terminal, replacing db2inst1 with the instance owner.

. /home/db2inst1/sqllib/db2profile

Java Program to Test JDBC Connectivity

I use the following Java program to test to see if JDBC connectivity works from a Java program, after assigning appropriate values to the constants at the beginning:


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;


public class PrintSQLTable {

	final static String dbdriver = "com.ibm.db2.jcc.DB2Driver";
	final static String dburl = "jdbc:db2://localhost:50000/test";
	final static String dbuser = "db2inst1";
	final static String dbpassword = "myPassword";
	final static String dbtable = "test.technonstop";
	
	public static void main(String[] args) throws ClassNotFoundException,
			SQLException {
		Class.forName(dbdriver);
		Connection connection = DriverManager.getConnection(dburl, dbuser,
				dbpassword);
		Statement statement = connection.createStatement();
		ResultSet resultSet = statement
				.executeQuery("SELECT * FROM " + dbtable);

		StringBuilder tableContents = new StringBuilder("");
		ResultSetMetaData metaData = resultSet.getMetaData();
		int noOfColumns = metaData.getColumnCount();

		for (int i = 1; i <= noOfColumns; i++) {
			tableContents.append(metaData.getColumnName(i) + " \t ");
		}

		tableContents.append("\n");
		int sbLength = tableContents.length();
		for (int i = 0; i < sbLength; i++)
			tableContents.append("-");
		tableContents.append("\n");

		while (resultSet.next()) {
			for (int i = 1; i <= noOfColumns; i++) {
				tableContents.append(resultSet.getString(i) + " \t ");
			}
			tableContents.append("\n");
		}

		if (tableContents.length() == 0)
			tableContents.append("No data found");

		System.out.println(tableContents);
	}


}

Run the program with the db2jcc.jar file in the classpath, as shown below:


$ java -cp /opt/ibm/db2/V9.7/java/db2jcc.jar:. PrintSQLTable
ID 	 USERNAME 	 
-----------------
1 	 abdullah 	

Categories
Uncategorized

Upgrade from Ubuntu 11.04 to 11.10, and a pleasant user interface greets you. Does the good news end there?

UPDATE (18th Nov, 2011): I carried out a clean installation from a USB drive, and no longer have the purple/blank screen problem while loading the 3.0.0-12-generic kernel. I can conclude that a problematic web upgrade process prevented the newer kernel from loading. Possible fixes are being discussed on various forums, but none of them have worked for me.

I’ve been running Ubuntu 11.04 (Natty Narwhal) for several months and have been satisfied with the experience. In October 2011, the newest stable Ubuntu 11.10 version (Oneiric Ocelot) was announced.

The upgrade to the new distro can be carried out by running the command:

sudo do-release-upgrade

You could also enable automatic updates, like I did, and have Natty Narwhal prompt you to upgrade. Simply go to System -> Administration -> Update Manager, click on the ‘Settings…’ button, and in the ‘Updates’ tab, turn on the checkbox for automatic updates. Also ensure that the release upgrade option is set to “Normal releases”.

To me, it was a surprise that I didn’t have to go to fetch Ubuntu 11.10 or run a command to get it – it came straight to me!

Welcome to Ubuntu 11.10 Oneiric Ocelot

Fast and easy install? Well, the upgrade certainly did not go on unattended and repeatedly questioned me about replacing some old configuration files.

My machine, incidentally, isn’t so dated – it runs an AMD Athlon X2 2.5 GHz processor with 2 GB RAM and an Nvidia GeForce7050PV graphics card.

After a lengthy download of over 850 MB – the size may vary for you, depending on the number of packages needed – and an install process which wasn’t without hiccups, I had to restart, only to find a blank purple screen and no hard disk activity.

Enough to cause my heart to sink.

Doing a hard reboot took me to a menu with a list of options to choose from:

  1. Ubuntu, with Linux 3.0.0-12-generic
  2. Ubuntu, with Linux 3.0.0-12-generic (recovery mode)
  3. Previous Linux versions
  4. Memory test (memtest86+)
  5. Memory test (memtest86+, serial console 115200)

If I’d choose the first option, I’d be back to square one. Choosing the second option would result in a kernel panic.

I went to “Previous Linux versions” and found these options:

  1. Ubuntu, with Linux 2.6.38-8-generic
  2. Ubuntu, with Linux 2.6.38-8-generic (recovery mode)

I chose the first one and was greeted by a glossy LightDM login screen, followed by a beautiful new Ubuntu desktop.

An Exciting New Linux – But not everything’s Smooth Sailing

It turned out that Ubuntu 11.10 was failing to load the new Linux 3.0.0-12-generic kernel. I decided to install the startup manager from the synaptic package manager, and set the default operating system to the older Linux 2.6.38-8-generic to allow my system to function.

Startup Manager

A big thank you to the posters discussing this issue on the thread that helped me!

As for the user interface, much of it is revamped. The action of dragging and docking folders is nicely animated. My Atheros chip based Wi-Fi adapter now connects me to the Internet almost instantly, unlike the case with Natty Narwhal, where I had to wait for several tens of seconds before connectivity would be established. The processes of both starting up and shutting down the computer take only slightly longer.

There’s a prominent launcher that appears when hovering the cursor on the left side of the screen, to help you open your favorite application almost instantly.

Clicking the dash on the top-left corner reveals a translucent box to help navigate to various parts of your machine fairly fast. There’s a Mac OSX-style spotlight for instant searches. However, critics are furious that Ubuntu is trying a lame copy of Mac’s stunning user interface and falling short.

Accessing the most frequently used and other installed applications through the dash was never easier, not least due to the Filters feature that is clearly a leap over the basic offerings of Ubuntu 11.04.

Ubuntu 11.10 Desktop

What worries me is that the dash once became unstable and disappeared.

Switching applications is facilitated by pressing either the Alt+Tab or Alt+Grave buttons and choosing a running program from a frosted-glass box. However, this seems to cause my computer to hang after using it for several seconds, calling for a hard reboot.

I haven’t really tried many of the applications that came pre-bundled with Ubuntu 11.04 or were available for download, since I spend most of my time on the Internet. The few I did try from the math, engineering and graphic designing sections failed to impress me, and I won’t be surprised if Ubuntu 11.10 is not very different on this front.

The Conclusion?

Well, there still seem to be issues that Canonical has to address. Ubuntu 11.10 with its default Unity interface surely has an unprecedented, elegant look and feel. But there’s got to be more than skin-deep beauty – Canonical should definitely have done better testing on the upgrade process and its end result.