Thursday, May 31, 2007

[Humor] Copy n Paste

A well known motivational speaker gathering the entire crowd's attention, said "The best years of my life were spent in the arms of a woman who wasn't my wife"
The crowd was shocked...
He followed up by saying, "That woman was my mother"
The crowd burst into laughter and he gave his speech, which was well received.
About a week later, one of the top managers of an organization who had attended the speech decided to use that joke at his house. He tried to rehearse the joke in his head. It was a bit foggy to him.
He said loudly, "The greatest years of my life were spent in the arms of a woman who was not my wife"
Naturally, his wife was shell shocked, murmuring.
After standing there for almost 10 seconds trying to recall the second half of the joke, the manager finally blurted out "... and I can't remember who she was"
As expected, he got the thrashing of his life time...

Moral of the story:
Don't copy if you can't paste J J J

[Received in an email]

Sunday, May 20, 2007

Show'em Who's Boss

Received this seriously funny pic in an email forward :)





How true it is!

Monday, May 14, 2007

If you just focus on fixing someone...

Rajesh Setty of Life Beyond Code has this inspiring entry about 'fixing' people.

Your spouse wants to fix you.

You want to fix your spouse.

Your parents want to fix you.

You want to fix your children.

Your teachers want to fix you.

You want to fix your teachers.

Your boss wants to fix you.

You want to fix your boss.

Your colleagues want to fix you.

You want to.. well you get the point.

Wanting to fix someone whether right or not has one problem. In your quest to fix that someone, you forget to leverage the strengths of the that person for the benefit of both.

Next time, before you attempt to "fix" someone, why not focus on what that person brings to the table and see how best both of you can benefit from it?


http://blog.lifebeyondcode.com/blog/_archives/2007/5/10/2941581.html

Sunday, May 6, 2007

Java 6 Feature : Working with Derby Database

The Java 5 and Java 6 releases have introduced some significant changes. While Java 5 introduces new features (e.g. Generics, Variable arguments, Enhanced for loop, Boxing/unboxing, Type-safe enumerations, Static import, Metadata), Java 6 installation includes a lightweight database known as Derby.
Derby is actually an Apache Database project. Derby is a transactional, relational database and provides a small footprint on disk. When you install Java 6, core libraries, example programs, and a sample database gets automatically installed.
Derby has a command-line tool called ij. This tool provides a way to connect to and manipulate Derby databases.

To connect to Derby is quite easy. You need to have following jar files in the classpath to enable you to access Derby:
D:\tools\jdk1.6.0_01\db\lib\derby.jar
D:\tools\jdk1.6.0_01\db\lib\derbytools.jar

The derby.jar has JDBC drivers, while derbytools.jar contains the ij tool.

Once you have configured the classpath for Derby, open the command prompt, and start ij tool:
C:\Documents and Settings\Administrator>java org.apache.derby.tools.ij
ij version 10.2
ij>

You are now connected to Derby db.
Connect to the supplied example database (toursdb):
ij> connect 'jdbc:derby:Absolute_Path_to_the_connecting_database';
ij>

You can create a new database from the ij tool.
connect 'jdbc:derby:DB4MyApplication;create=true';

A semicolon (;) at the end of each command is also required.
You can get a list of Derby commands by issuing help command.
ij> help;

Supported commands include:

PROTOCOL 'JDBC protocol' [ AS ident ];
-- sets a default or named protocol
DRIVER 'class for driver'; -- loads the named class
CONNECT 'url for database' [ PROTOCOL namedProtocol ] [ AS connectionName ];
-- connects to database URL
-- and may assign identifier
SET CONNECTION connectionName; -- switches to the specified connection
SHOW CONNECTIONS; -- lists all connections
AUTOCOMMIT [ ON OFF ]; -- sets autocommit mode for the connection
DISCONNECT [ CURRENT connectionName ALL ];
-- drop current, named, or all connections;
-- the default is CURRENT

SHOW SCHEMAS; -- lists all schemas in the current database
SHOW [ TABLES VIEWS PROCEDURES SYNONYMS ] { IN schema };
-- lists tables, views, procedures or synonyms
SHOW INDEXES { IN schema FROM table };
-- lists indexes in a schema, or for a table
DESCRIBE name; -- lists columns in the named table

COMMIT; -- commits the current transaction
ROLLBACK; -- rolls back the current transaction

PREPARE name AS 'SQL-J text'; -- prepares the SQL-J text
EXECUTE { name 'SQL-J text' } [ USING { name 'SQL-J text' } ] ;
-- executes the statement with parameter
-- values from the USING result set row
REMOVE name; -- removes the named previously prepared statement

RUN 'filename'; -- run commands from the named file

ELAPSEDTIME [ ON OFF ]; -- sets elapsed time mode for ij
MAXIMUMDISPLAYWIDTH integerValue;
-- sets the maximum display width for
-- each column to integerValue

ASYNC name 'SQL-J text'; -- run the command in another thread
WAIT FOR name; -- wait for result of ASYNC'd command

GET [SCROLL INSENSITIVE] CURSOR name AS 'SQL-J query';
-- gets a cursor (JDBC result set) on the query
-- SCROLL cursors are only available
-- in JDBC 2.0 and higher.
-- (Cursor scroll type is ignored in JDBC 1.X.)
NEXT name; -- gets the next row from the named cursor
FIRST name; -- gets the first row from the named scroll cursor
LAST name; -- gets the last row from the named scroll cursor
PREVIOUS name; -- gets the previous row from the named scroll cursor
ABSOLUTE integer name; -- positions the named scroll cursor at the absolute row number
-- (A negative number denotes position from the last row.)
RELATIVE integer name; -- positions the named scroll cursor relative to the current row
-- (integer is number of rows)
AFTER LAST name; -- positions the named scroll cursor after the last row
BEFORE FIRST name; -- positions the named scroll cursor before the first row
GETCURRENTROWNUMBER name; -- returns the row number for the current position of the named scroll cursor
-- (0 is returned when the cursor is not positioned on a row.)
CLOSE name; -- closes the named cursor
LOCALIZEDDISPLAY [ ON OFF ];
-- controls locale sensitive data representation

EXIT; -- exits ij
HELP; -- shows this message

Any unrecognized commands are treated as potential SQL-J commands and executed directly.

So, now you have a lightweight DB installed alongwith the JDK. You can use this database for Proof-of-Concepts (POC), sample applications, demos among other things. To connect to Derby from Java, use the supplied driver
org.apache.derby.jdbc.EmbeddedDriver
. Connect to DB as shown earlier.

Saturday, May 5, 2007

Developing a Spring Framework MVC application step-by-step

Recently, I started reading on Spring. I was looking for an example application code, and then, I came across this article on springframework.org. The article is quite old (first written in July 2003, and then revised in April 2005), but quite relavent to topic. This is a hand-holding type of tutorial and develops an application from scratch, covering various Spring components, and even talks to HSqlDB, with JUnit test cases. Ant is used for deployment. It takes not more than 2-3 hours to develop the complete application.

Application is covered in 4 steps:
  • Basic Application and Environment Setup
  • Developing and Configuring the Application
  • Adding Unit Tests and a Form to the Application
  • Implementing Database Persistence

The tutorial assumes a Tomcat installation, but then u can develop it for any servlet engine or application server (e.g. i did it for JBoss).

it is a good exercise if u r new to Spring, or want to have a first hand look at Spring.

http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html

Tuesday, May 1, 2007

Java 5 Feature: Static Imports

Static imports are another convenience feature added to version 1.5 that extends the way imports work in Java. For example, consider the code fragment shown below that calls the static ceil() method on the java.lang.Math class


// x is a number of type double such as 98.765
double y = Math.ceil(x);


With static imports in 1.5, you can ask the Java compiler to import only a class's static portions, as shown, for example, in the rewritten code fragment below:


// Import declaration at the top of the class along with the other imports
import static java.lang.Math.ceil;

// And then somewhere in the code...

// x is a number of type double such as 5.345
double y = ceil(x);

In the above fragment, I used the new static import feature to import the static method ceil() from the Math class. Now when I call the method, I don't have to qualify it with Math. If I wanted to use multiple static methods from the Math class, I could import them individually or all at once as shown below:

// Import all static methods from Math
import static java.lang.Math.*;


This also applies to any constants declared within Math, such as E and PI. With the above declaration, I can use these constants as if they were declared locally within my class (or superclass).

Use it when you require frequent access to static members from one or two classes. If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from. Importing all of the static members from a class can be particularly harmful to readability; if you need only one or two members, import them individually. Used appropriately, static import can make your program more readable, by removing the boilerplate of repetition of class names.

Total Pageviews

Diving into the Controversial World of IPL with Lalit Modi

Lalit Modi, the mastermind behind the Indian Premier League (IPL), recently had a candid interview with Raj Shamani. The interview delved d...