Sunday, February 24, 2008

VI Editor Hints - UNIX

Some useful shortcuts ,when using VI editor

Cursor movement

* h - move left
* j - move down
* k - move up
* l - move right
* w - jump by start of words (punctuation considered words)
* W - jump by words (spaces separate words)
* e - jump to end of words (punctuation considered words)
* E - jump to end of words (no punctuation)
* b - jump backward by words (punctuation considered words)
* B - jump backward by words (no punctuation)
* 0 - (zero) start of line
* ^ - first non-blank character of line
* $ - end of line
* G - Go To command (prefix with number - 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For
example, 4j moves down 4 lines.
Insert Mode - Inserting/Appending text

* i - start insert mode at cursor
* I - insert at the beginning of the line
* a - append after the cursor
* A - append at the end of the line
* o - open (append) blank line below current line (no need to press
return)
* O - open blank line above current line
* ea - append at end of word
* Esc - exit insert mode

Editing

* r - replace a single character (does not use insert mode)
* J - join line below to the current one
* cc - change (replace) an entire line
* cw - change (replace) to the end of word
* c$ - change (replace) to the end of line
* s - delete character at cursor and subsitute text
* S - delete line at cursor and substitute text (same as cc)
* xp - transpose two letters (delete and paste, technically)
* u - undo
* . - repeat last command

Marking text (visual mode)

* v - start visual mode, mark lines, then do command (such as y-yank)
* V - start Linewise visual mode
* o - move to other end of marked area
* Ctrl+v - start visual block mode
* O - move to Other corner of block
* aw - mark a word
* ab - a () block (with braces)
* aB - a {} block (with brackets)
* ib - inner () block
* iB - inner {} block
* Esc - exit visual mode

Visual commands

* > - shift right
* < - shift left
* y - yank (copy) marked text
* d - delete marked text
* ~ - switch case

Cut and Paste

* yy - yank (copy) a line
* 2yy - yank 2 lines
* yw - yank word
* y$ - yank to end of line
* p - put (paste) the clipboard after cursor
* P - put (paste) before cursor
* dd - delete (cut) a line
* dw - delete (cut) the current word
* x - delete (cut) current character

Exiting

* :w - write (save) the file, but don't exit
* :wq - write (save) and quit
* :q - quit (fails if anything has changed)
* :q! - quit and throw away changes

Search/Replace

* /pattern - search for pattern
* ?pattern - search backward for pattern
* n - repeat search in same direction
* N - repeat search in opposite direction
* :%s/old/new/g - replace all old with new throughout file
* :%s/old/new/gc - replace all old with new throughout file with
confirmations

Working with multiple files

* :e filename - Edit a file in a new buffer
* :bnext (or :bn) - go to next buffer
* :bprev (of :bp) - go to previous buffer
* :bd - delete a buffer (close a file)
* :sp filename - Open a file in a new buffer and split window
* ctrl+ws - Split windows
* ctrl+ww - switch between windows
* ctrl+wq - Quit a window
* ctrl+wv - Split windows vertically

Thursday, February 21, 2008

CronExpression in Springs

Cron expressions are comprised of 6 required fields and one optional field separated by white space. The fields respectively are described as follows:

Field Name Allowed Values Allowed Special Characters
Seconds 0-59 , - * /
Minutes 0-59 , - * /
Hours 0-23 , - * /
Day-of-month 1-31 , - * ? / L W
Month 1-12 or JAN-DEC , - * /
Day-of-Week 1-7 or SUN-SAT , - * ? / L #
Year (Optional) empty, 1970-2099 , - * /

The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".

The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fileds, but not the other.

The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".

The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".

The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety.

The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.

The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days.

The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month".

The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month.

The legal characters and the names of months and days of the week are not case sensitive.

NOTES:

  • Support for specifying both a day-of-week and a day-of-month value is not complete (you'll need to use the '?' character in on of these fields).

Wednesday, February 20, 2008

Automate your Test With Selenium RC - JAVA

Download Selenium RC :-
http://release.openqa.org/selenium-remote-control/0.9.2/selenium-remote-control-0.9.2-dist.zip

Download JAVA(JRE - version "1.5.0_07" ) :
http://www.java.com/en/download/manual.jsp

STEPS ::::::::

you may need to add JAVA_HOME/bin to your PATH environment variable.

* Windows:
If you're on Windows XP or Windows 2003, you can just use Internet Explorer for this example, or install Mozilla Firefox or Opera. If you're using Windows 2000, you'll need to install reg.exe(http://wiki.openqa.org/display/SRC/Windows+Registry+Support) in order to use Internet Explorer, but Firefox should work regardless. We recommend (but do not require) that you add your browser executable to your PATH environment variable. (If you do not explicitly add your browser's installation directory to the PATH, then you must install your browser in its standard location; Firefox's standard location is "c:\Program Files\Mozilla Firefox\firefox.exe"; Internet Explorer's standard location is "c:\Program Files\Internet Explorer\iexplore.exe".)
* Unix/Linux: For this tutorial, install Firefox and add the Firefox directory to your PATH environment variable. Note that on Unix/Linux we'll be trying to invoke "firefox-bin" directly, so make sure that executable is on the path; also don't forget to add the Firefox libraries to your LD_LIBRARY_PATH. If needed, we can invoke Firefox using a shell script (e.g. "firefox" or "run-mozilla.sh"), but in that case, we may not be able to stop Firefox until the server is shut down.
* Mac OS X: On Mac OS X, it should be enough to install Firefox.app in your /Applications directory. Note in order to control the browser accurately, we need to invoke the embedded Firefox executable (firefox-bin) directly in /Applications/Firefox.app/Contents/MacOS; if your browser isn't installed there, then you'll want to add the correct embedded location to your PATH environment variable as well as your DYLD_LIBRARY_PATH environment variable.

To setup Selenium on your Machine :
Extract selenium-remote-control-0.9.2-dist.zip

Interactive Mode
Selenium Server "interactive mode" is a way of rapidly prototyping tests that requires no coding whatsoever, so it's a good way to introduce new users to Selenium Remote Control. In interactive mode, you type your commands one by one into the Selenium Server command window; this allows you to immediately see the results of running your command in a working browser, on-the-spot. With that said, normally you'll be coding these tests in your favorite programming language, so the whole thing is completely automated.

Once you've got Java installed and ready to go, you can start the Selenium Server from the command line like this:

java -jar selenium-server.jar -interactive

If you want to use Firefox, try this:

cmd=getNewBrowserSession&1=*firefox&2=http://www.google.com


Example class :

import com.thoughtworks.selenium.*;
import junit.framework.*;
public class GoogleTest extends TestCase {
private Selenium browser;
public void setUp() {
browser = new DefaultSelenium("localhost",
4444, "*firefox", "http://www.google.com");
browser.start();
}

public void testGoogle() {
browser.open("http://www.google.com/webhp?hl=en");
browser.type("q", "hello world");
browser.click("btnG");
browser.waitForPageToLoad("5000");
assertEquals("hello world - Google Search", browser.getTitle());
}

public void tearDown() {
browser.stop();
}
}


You may need to add libraries to run and compile this class .You can find them from selenium-server-0.9.2 and selenium-java-client-driver-0.9.2 folders(in your extract location)

compile java class in unix :

javac -classpath temp.jar:temp2.jar: GoogleTest.java
javac -cp temp.jar:temp2.jar: GoogleTest (You can use tool instead of this eg : Idea)

Friday, February 8, 2008

Java Technologies to Learn in 2008

Top Five Java Technologies to Learn in 2008

Software Technology will always been in constant flux. Change will always be inevitable. So as a Java developer you need to continue to groom your career by learning new techniques and technologies. It's both a curse and a blessing. It's a blessing because Java, without a doubt, is where a lot of innovation happens. The question though is, out of the multitude of Java projects out there, which ones should we invest our limited bandwidth on? This is my attempt at answering this question.

Here is what I humbly believe to be the top 5 Java based technologies to learn in 2008:

#5 OSGI - Reality check, monolithic containers carry too much baggage and Java libraries are so richly cross dependent. The trend is there, a lot of frameworks are moving towards OSGI to bring some sanity in their deployment. Projects that have employed OSGI in anger are Eclipse via Equinox, Nuxeo and BEA Event Server,

links : http://dev2dev.bea.com/pub/a/2007/12/osgi-introduction.html

#4 JCR - Reality check, not all data fits well within a relational database. In most cases, users want to store their own documents and have those properly managed (i.e. versioned). JCR with it's Jackrabbit implementation is becoming the de-facto standard for maintaining data other than the structured kind. Some examples of projects that have used this in unexpected and innovative ways are Drools BRMS for managing business rules, Apache Sling for universal resource storage and Mule Galaxy for SOA governance management.

#3 GWT - Reality check, AJAX is here to stay and Java script is still a pain to work with. GWT is gaining traction like wildfire at the expense of other Java web technologies like JSF. A lot of projects have begun creating extremely cool products with it. Some impressive examples are Queplix a CRM, Compiere an ERP and GPokr a multi player Texas hold-em poker game.

#2 Groovy - Reality check, sometimes you have to write quick and dirty scripts to get your tasks done quickly. There's a lot of traction these days for dynamic scripting languages like Ruby. However if you want to truly leverage your existing skill set, then it's more efficient to take a evolutionary step. Groovy has come a long way since it's rocky beginnings. I believe Groovy is finally mature enough (it finally has a debugger) that it's safe to dip your toes in it. Furthermore, there's are a of books, books about frameworks (i.e. Grails) and tools (i.e. IntelliJ) that help you from getting lost.

#1 Cloud Computing - Reality check, sometimes it just isn't worth it to setup your own physical servers. Amazon's services are going to be an extreme boon to development productivity. One of the most time consuming efforts, and one that is too often taken for granted, is the deployment of a load and performance testing harness. In a lot of rigid organization, it is sometime problematic to acquire so much hardware for use only for short time periods. There aren't many tools out there yet for the Java developer (see: "Grid Gain Distributed JUnit"), however it's ramping up pretty quickly. So just as we create our builds from the cloud via Maven repositories, one shouldn't be surprised to find cloud based testing resources to be part of every developer's tool chain in the future.

With all these nice new shiny objects to play with, I'm constantly surprised why people keep claiming that Java is dying!

I'm certain you are all agreement with me on what belongs to this list. However if you've got some violent objections, I certainly would like to hear your view.