Spiritual java is an attempt to let me express my thoughts, my ideas, my views and my feelings about two topics which are very close to my heart. Vippasana and Java!!! I have been practicing Vipassana for more than 8 years now and in all these years the way this teqnuqie helped me in overcoming many ups and downs in my life is quite remarkable. Java on the other hand is my source of my materialistic existence. So I'll be sharing my views on J2EE technology and its relevance in web.

Monday 28 December 2009

Important tips for IT contracting

Anyone who is planning to do IT contracting should do a little bit of research. This site gives some basic tips and tricks about IT contracting in UK
http://www.bytestart.co.uk/content/contractors/index.shtml


Information about IT Contract Rates can be found from these resources:
ITJobswatch:This is a handy site which provides high level data for key roles (such as Analysts, Developers) as well as specific skill sets (e.g. Oracle, UNIX, Java, .NET)
Jobstats: Jobstats has provided data extracted from the major job search engines for many years now. This site paints a general picture of the state of the IT Contracting market - including average market rates.

In addition, the following sites also provide data on pay rates in the IT arena:
E-Skills - Skills site, also provides training and salary information.
Contract Eye - This one is a dedicated IT Contractor site, with a dedicated channel on IT contractor rates


Next task is to write a good and to the point CV. This one explains it best http://www.bytestart.co.uk/content/contractors/contractor-guides/it-contractors-cv.shtml
            

Wednesday 23 December 2009

Saturday 19 December 2009

Java concepts


This post contains the compilation of some of the most popular java design questions that every java developer should be aware of.

  • ThreadLocal explained in Detail.
This is a very well written article that explains the use of ThreadLocal with example

  • Why multiple inheritance is not for java?
This question come to any developer's mind who has worked in C++. This is a very nice article that explains exactly this.

http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html


  • Diamond shape problem solved.
How multiple inheritance is achieved in java with the help of interfaces.



  • What is the difference b/w weak and soft references?


  • Static Factory pattern example: class instance which is created at the time of Static member initialization. This Factory always returns this instance.
http://alexmcferron.com/staticFactory.html

  • Static method Pattern example: This pattern is just a style of decoupling object initialization from the client code. It always returns a new class instance.


Monday 5 October 2009

An inspirational interview from Hrithik Roshan

This is another deviation from my normal posts. I just saw a talk show on youtube and thought it is worth keeping this in my compilation of posts. So here it is... A little preface, we all know Kritik Roshan. A Bollywood superstar who has delivered hits like Koi Mil gaya, Kaho na pyar hai, Dhoom 2 and Lakshya to name a few. From the energetic performance and the kind of dance that he do, a few people would know at one time he had twisted spine problem and stammering problem.
Kritik Roshan is one of the few Bollywood superstars who made his life's adversity as an opportunity. From birth he was born with bundles of problems; stammering problem, spinal problem; born with double thumb and all the emotional and social pressure that these problems brings with them. From the state of such an adversity to the current state of being a Bollywood star is some journey in itself.

This interview in itself captures the essence that if you wish something in life and you are determined to do it, then nothing is impossible. An old saying is true..."Nothing is impossible, even impossible say I'm possible"
Just to keep in mind that this interview is majority in Hindi language. What I really liked in this interview compared to others is that its not treated as just another celebrity talk show. It would be worth watching the last part of the video in which a physically challenged  girl plays a very good music composition.

Part 1. In this Kritik talks about his stammering problem and how he showed determination to overcome that weakness...




Part 2. Continues further with the introduction of another Bollywood celebrity Kangana Ranaught...




Part 3. Kritik and Kangana plays some fun games...




Part 4. In this part the physically challenged girl plays the musical composition...

Saturday 3 October 2009

"Letters from Mara..."

Few days back Vikas Ji shared an inspirational Article(sent to him from Prof Dhar) with Delhi Vipassana group meditators.
Got some time today and read it. Found it very interesting and engaging.
The article "Letters from Mara" has got 10 letters in it. The article is taken by Buddha's one of the Sutta's.
Each of the letters is written by Mara to its squadrons namely desires, craving, lust, boredom,...(the impurities in the mind).
Thought of something to be shared. http://bit.ly/1AkHrR

Thursday 1 October 2009

Deploying Simple Hellworld lift webapp on Google App Engine




In the previous post we deployed the sample HelloWorld lift app on tomcat. In this post we will take one step further and go ahead with our lift helloworld webapp and deploy it on Google App engine.
From whatever I have read on different blogs, lift framework 1.0 support seems unavailable on GAE. But in milestone 1.1 there seems to be a limited support for it. With the future release lift may become fully compatible with GAE.
So for this example we will deviate from our 1.0 version to 1.1-M4 version.


Steps to do the initial maven setup remain same as with the previous post.
 
Ok, lets get started; first go to your workspace and type in the following maven command

mvn archetype:generate -U \-DarchetypeGroupId=net.liftweb \-DarchetypeArtifactId=lift-archetype-blank \-DarchetypeVersion=1.1-M4 \-DremoteRepositories=http://scala-tools.org/repo-releases \-DgroupId=demo.helloworld \-DartifactId=helloworld \-Dversion=1.0-SNAPSHOT



Once executed it will dispaly a list of outputs in verbose mode. At one or two places you may be prompted, just press enter.


Go to the project directory.
suresh-sharmas-macbook-pro:Projects sureshsharma$ cd helloworld
suresh-sharmas-macbook-pro:helloworld sureshsharma$ ls
pom.xml src
suresh-sharmas-macbook-pro:helloworld sureshsharma$


Packaging of the scr code to the war file can be done with maven's package command. Staying at /Projects/helloworld/ folder give the following command
suresh-sharmas-macbook-pro:helloworld sureshsharma$mvn package


This will create a war file in /Projects/helloworld/target/helloworld-1.0-SNAPSHOT.war


To deploy the war locally, go to the helloworld project directory. Maven comes in with inbuilt jetty and tomcat plugin so give the following command for tomcat deploy the app using tomcat plugin for maven.


suresh-sharmas-macbook-pro:helloworld sureshsharma$ mvn tomcat:run


Ok now coming back to GAE deployment, the first step for Deployment of war file to GAE is to install the google app engine SDK for java. You can download it from here.
Unzip the files in a folder say /usr/local/appengine-java-sdk-1.2.5/


Now for preparing the war file to be deployed in GAE, first go to /Projects/helloworld/src/main/webapp/WEB-INF folder. Their you will see web.xml file. For GAE deployment we need to create another appengine-web.xml file and add the following entries in it.

<?xml version="1.0" encoding="utf-8"?>
 <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
 <application>surylifting</application>
 <version>3</version>
 <system-properties>
   <property name="in.gae.j" value="true" />
 </system-properties>
 <sessions-enabled>true</sessions-enabled>
 <static-files>
   <exclude path="/**" />
 </static-files>
</appengine-web-app>



Change application name with the name of your registered application id in GAE, in my case it is surylifting.
Now first we will deploy GAE locally and then if everything goes fine we will deploy it to GAE.
Staying at /Projects/helloworld/ give the following command 


suresh-sharmas-macbook-pro:helloworld sureshsharma$/usr/local/appengine-java-sdk-1.2.5/bin/dev_appserver.sh /Projects/helloworld/target/helloworld-1.0-SNAPSHOT

Note that .war extension is not present above for helloworld-1.0-SNAPSHOT

And here u go u will be able to see it running at http://localhost:8080/


Now finally to deploy this app on GAE give the following command


suresh-sharmas-macbook-pro:helloworld sureshsharma$/usr/local/appengine-java-sdk-1.2.5/bin/appcfg.sh update /Projects/helloworld/target/helloworld-1.0-SNAPSHOT


again note that helloworld-1.0-SNAPSHOT is without .war extension


Once the deployment starts  you will be prompted for email id and password with which you registered on app engine. Once deployment is done you are ready to see you helloworld app on GAE.


Click on the http://surylifting.appspot.com and you will see my application deployed there. Simple :-)


Tuesday 29 September 2009

Installing tomcat in Mac OSX leopard

Found an interesting link for installing Tomcat on Mac OSx. Hope you will find it useful. This post gives details instructions to install the tomcat. Have a look at it.
http://www.malisphoto.com/tips/tomcatonosx.html

Saturday 26 September 2009

Creating HelloWorld webapp in Lift and Deploying it on Tomcat 6.x

In this post I'm going to create a very simple webapp on lift and then deploy it on tomcat 6. As usual, I'm going to use mac OsX but it should not be too different on any other environment. The most funny part is that we don't have to write a single line of code to make our Helloworld app! A sample HelloWorld app for lift framework already comes in as Maven build.


So lets get started, first u need to have the following:
  • jdk 1.5 or above installed on ur system. You can download it from here.
  • Latest Maven  installation. You can download it from here.
  • Scala Plugin for eclipse. See how to install it from here.
Once everything is installed go to the command prompt and check mvn version.


suresh-sharmas-macbook-pro:~ sureshsharma$ mvn -version


Maven version: 2.0.9
Java version: 1.5.0_19
OS name: "mac os x" version: "10.5.8" arch: "i386" Family: "unix"
suresh-sharmas-macbook-pro:~ sureshsharma$


This should tell u the maven version installed. Now go to ur workspace directory, in my case it is /Projects


At the command prompt give the following command; I'll explain the
meaning of it a little later.


Suppose I want to create a project called helloworld and want to be
packaged under com.elslon.lancet.rad, then first I'll go to my
workspace /Projects


suresh-sharmas-macbook-pro:~ sureshsharma$ mvn archetype:generate -U \-DarchetypeGroupId=net.liftweb \-DarchetypeArtifactId=lift-archetype-blank \-DarchetypeVersion=1.0 \-DgroupId=com.elslon.lancet.rad \-DartifactId=helloworld \-Dversion=1.0-SNAPSHOT


Once executed it will dispaly a list of outputs in verbose mode. At one or two places you may be prompted, just press enter.


Once it is done and u get back to the command prompt u are ready to  launch your first app. Go to the project directory.


suresh-sharmas-macbook-pro:Projects sureshsharma$ cd helloworld


suresh-sharmas-macbook-pro:helloworld sureshsharma$ ls
pom.xml src
suresh-sharmas-macbook-pro:helloworld sureshsharma$


Maven. Comes in with inbuilt jetty and tomcat plugin so give the following command for tomcat deploy the app using tomcat plugin for maven.


suresh-sharmas-macbook-pro:helloworld sureshsharma$ mvn tomcat:run


And here u go it will start tomcat plugin and u will be able to see it running at http://localhost:8080/


The next step is to create a war file to be deployed on tomcat, go to  helloworld directory, you should see that pom.xml and target directory present there. Give the following command mvn package. This is maven's task that builds and creates the war file and place it in target directory. In our case the war file will be created in /Projects/helloworld/target/helloworld-1.0-SNAPSHOT.war.


Now take the war file and deploy it on tomcat. Start the tomcat and here you go! You have deployed your helloworld lift webapp on tomcat.


Sunday 13 September 2009

Creating Simple Hello World webapp in JRuby on Rails

In this post I'm going to create a simple Hello World webapp on JRuby on rails right from the scratch.

I'm using Mac OSX version 10.5 for development  but I assume it would not be very different on other OS like Windows.
I like to do all the installation in directory /usr/local.  You can go to this directory from the terminal or from finder. Just keep in mind that this location is not visible from the finder window as the folder /usr is hidden by default. Click here to see how to open this window in finder.

First we need to install the latest version of JRuby. The zip file can be downloaded from here.
Once downloaded extract and move the jRuby folder to /usr/local

>mv /Users/sureshsharma/Downloads/jruby-1.3.1 /usr/local/jrub

After that go to the ~/.profile file and update the path for the installation
export PATH=/usr/local/jruby/bin:/usr/local/bin:/usr/sbin:$PATH

Now install rails, mongrel and jdbc adapter.If you are using sqlite3 instead of mysql then you must install the jdbc-sqlite3 adapter.
>sudo /usr/local/jruby/bin/gem install rails mongrel activerecord-jdbcsqlite3-adapter rspec rack rake jruby-openssl activesupport
At this point you have the following things installed.
  • JRuby
  • Rails framework
  • mongrel server
  • jdbc sqlite3 adapter
Now we are ready to go and create our hello world app. 
Create a workspace directory to create the jruby project. In my case it is /Projects. 
Once inside give the following command 
/Projects>jruby -S rails helloWorldPrj
This command will create a project helloWorldPrj inside /Projects folder. 
Ok now lets create a controller.
/Projects/helloWorldPrj>jruby -S script/generate controller home

The above command will create the following for you:

  • A controller called HomeController in /helloWorldPrj/app/controllers/home_controller.rb
  • A view Helper called HomeHelper in /helloWorldPrj/app/helpers/home_helper.rb
  • a view folder in /helloWorldPrj/app/views/home
Now open your favorite editor to proceed. In my case I'm using Rad-Rails editor plugin for Eclipse. Go to the install and update new softwares option and give the following url http://update.aptana.com/install/rails/
Make sure you install only the RadRails editor infrastructure and nothing more than that. We will add on the stuff as and when we need it.
Once it is installed change to RadRails perspective and in the Ruby explorer 
right click->new Project->Rails Project
Yes, you need to create new Rails Project even though we are going to use our existing helloWorldPrj project.
In the New project window uncheck both the following two options
  • Generate Rails Application skeleton
  • Automatically start server after project is created
Type in the name helloWorldPrj in the project name and press ok. This will automatically import the existing project that we created from the terminal into the Ruby explorer.
Open /helloWorldPrj/app/controllers/home_controller.rb file and create an action called view

class HomeController < ApplicationController
  def view
   @model = "Hello world!!!"
  end
end

Next go inside the /helloWorldPrj/app/views/home folder and create a view.html.erb file. This will be our view template.
Inside the body tag give the following 



<body>This is my first  application!!!
body>

Now the next most important thing; because we are using sqlite3, go to /helloWorldPrj/config/database.yml and change the development,test and production adapters to jdbcsqlite3 
/helloWorldPrj/config/database.yml file should look like this
# SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: jdbcsqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: jdbcsqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000
production:
  adapter: jdbcsqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000
We are done now!!! Go inside the titi project and start the server
/Projects/helloWorldPrj>jruby -S script/server
Now go the browser and check this out at  http://0.0.0.0:3000/
You should see something like this

Now check out your hello world page at http://0.0.0.0:3000/home/view
Congratulations!!! You have just created your first Hello world jruby web application :-)

How to find hidden folders in finder on Mac OS X

Go to the finder and on the menu bar select Go->Go to Folder (or use shortcut key cmd+shift+G) 
After that a window will open as shown below. Type in any path you want to go; say for instance you want to go to hidden folder /usr/local, just type in that. It will open the folder in finder.

How to take screen snapshot in Mac OS X

Taking screen snapshot in Mac OS X is very simple. If you want to capture the snapshot of the entire screen just press cmd+shift+3 and you will hear a camera click sound!!! Go to the desktop and you will see by default an image called picture-1 is created there. Thats all :-)

If you want to take the snapshot of only a selected area of the window then press cmd+shift+4 and this time you will see that your mouse pointer has become an area selection pointer. Select the area of the window you want to take the snapshot and release the mouse pointer, again you will hear a camera click sound !!!. Go to the desktop and find your image there. Dead simple on Mac... making simple things simpler... thats Mac for you :-)

Thursday 10 September 2009

Unique way to tackle ATM Thefts

I'm deviating from my normal post and want to share an information about an interesting mail that i received recently. Not too sure whether it is correct or not as I never dared to try it and hope nobody need to try it either!!!
Say for instance you are in an ATM and you see a man just behind you and that he is too close to you for your comfort.

You look back and he stares at you, reaches his pocket and takes out a gun, soon his accomplice follows

Now what do you do? Do you fight back or try to run? or try to raise an alarm?....
The answer is no.... don't do that... read the following excepts from mail carefully!!!

"... WHEN A THIEF FORCES YOU TO TAKE MONEY FROM THE ATM, DO NOT ARGUE OR RESIST,
YOU MIGHT NOT KNOW WHAT HE OR SHE MIGHT DO TO YOU.   WHAT YOU SHOULD DO IS TO

PUNCH YOUR PIN IN THE REVERSE, I...E IF YOUR PIN IS 1254, YOU PUNCH 4521.  


THE MOMENT YOU PUNCH IN THE REVERSE, THE MONEY WILL COME OUT BUT WILL BE

STUCK INTO THE MACHINE HALF WAY OUT AND IT WILL ALERT THE POLICE WITHOUT THE NOTICE OF THE THIEF.
EVERY ATM HAS IT; IT IS SPECIALLY MADE TO SIGNIFY DANGER AND HELP. NOT
EVERYONE IS AWARE OF THIS.
..."


Please share this post with your friends, relatives and colleagues of yours.

Saturday 5 September 2009

A quick intro to Mercurial Revision control system

This post is for all the developers who are using revision control systems like CVS to use Mercurial. This post just contains a few brief descriptions and urls from where more information can be found about using the mercurial

Ok so lets get started.

Few FAQ which will make you familiar with the terminologies used in mercurial.


What is tortoiseHg?
This is a windows version of Mercurial. It is like tortoise for CVS.
Ok fine, but then what is Mercurial?
It is a revision control system just like CVS
And what is Hg?
Its the chemistry name of Mercurial :-)

Something to know for developers who are on Mac 
What is Ticke(TCL)?
Tools command language is a scripting command language like ruby
What is macport(s)?
Macport is a command line package distribution tool just like ruby gem for Mac.
From where can I install mercurial on my machine?
For windows: download the latest version from http://bitbucket.org/tortoisehg/stable/wiki/Home

For Mac OS-X: Install it from http://mercurial.berkwood.com/
Ok, how can i get started with mercurial once i have installed it?
Installing mercurial is just like creating any new directory in your machine which contains all the version control information.
To create a hg repository
hg init myproject

This will create a new repository call myproject
Go inside this and copy any file you want to provide versioning with.
To add the file to the repository
hg add
This will add the copied file to the repository
To check the status of the added file
hg status
To commit changes
hg commit -m 'initial commit'

Detailed instructions can be found at the link below