Friday, November 28, 2008

Calling Struts Action by Javascript

To call a struts action by Javascript on an event, you need to write a function which is invoked when the event occurs and this function makes an AJAX call. The AJAX call can send a request to the same URL which is provided in action attribute of form tag or html:form tag.

e.g. In case your action URL is something like
"/registerUserAction.do?action=forgetPasswordForward"
that you provide in action attribute of html:form, you can pass the same url to the mentioned code snippet below:


function makeRequest(url, callbackfunction)
{
var http_request = getXMLHttpObject();
url = url + "isComingFromAjax=true";

if (url.indexOf('?') != -1)
{
url = url + "&" ;
}
else
{
url = url + "?" ;
}

url = url + "isComingFromAjax=true";
http_request.onreadystatechange = callbackfunction;
http_request.open('POST', url.substring(0, url.indexOf('?')), true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(url.substring(url.indexOf('?') + 1));
}

Some of points to be considered in given code snippet:
1. callbackfunction is the function which will be invoked when response is received
2. "isComingFromAjax=true" parameter has been added as a extra parameter to differentiate between the normal action request and the AJAX request to do any special handling on the server side.

I have not covered details of creating XMLHttpRequest Object and other AJAX related things assuming you know it. You can write the logic for handling the response received from server in callbackfunction.

Tuesday, November 18, 2008

Choosing a LCD

Well, few months back I got confused when I saw so many LCDs of Sony, Hitachi, Philips, Samsung Sansui. I visited many showrooms and what I discovere that in one showroom I found Samsung as the best and in other Sony was the best, if you get confused obviously most people would end up with Sony. But then I realised dealers promote one or the other brand and they keep that unit in best settings.So, I jumped into a shop and got the remotes of all LCDs and when I set all of them on same brightness, sharpness level, it was a minute job for me to go for hitachi. Shopkeepers will tell you about so many factors, but only two are important Contrast ratio and response time, the time taken between the result on screen and when the button is pressed. This is how I decided and its been six months no problems. Till then there are new models but you can use the same approach to decide about a LCD.

Monday, November 10, 2008

Words for Sounds and Expressions - Hindi Comics

I build up this knowledge during my childhood and I found it very funny and hilarious when I visualize and use them today. Here are a few examples:

Chapaak - Sound of falling into water
Dhadaak - Sound of being hit by a wooden material, chair etc which broke after you are hit.
Dharram - Person falling into some wooden or steel material.
Dhaaen - Sound of firing of Gun.
Bu. Hu. hu.. hu... - Weeping
Subak.. Subak - Sobbing
Sarraaat - Motar bike moving.
Gulup.. Gulup.. - Drowing in water
Dhamaka - Blast, they will just make some clouds and right "Dhamaka" in middle.
Sudok.. Sudok.. - Having some liquid with a straw

And finally a big fight between two people:
Make clouds and write on all directions following words - Mukka, Laat, Thappad, Ghussa.
And if the person is being severly beaten write in middle "Dhunae par Dhunae".

Hope this is going to remind you of childhood. If I have missed some of them, please let me know.

Thursday, November 6, 2008

Old Honda City - Value for Money

I am crazy about cars, I was always a fan of old honda city ever since it was launched. Finally I owned it, got it in 2004, 40K done and I am so satissfied with the ride, handling and comfort I enjoy driving this car. My hometown is in Jammu and twice I have been there in my old honda city. First time I drove it on my own upto Jammu and was so glad with the comfort and fun I had all the way to my hometown. Second time, I hired a driver who drove me to Jammu and then I got the feeling of comfort and luxury that old honda city can provide on back seat.

Six months back I went to a marriage, a friend of mine has recently purchased a brand new zen, he asked me for a test drive to know why I didnt purchased a new car, reluctantly I gave him keys, we went for a drive of 2 Kms and when he handed me back the keys, he said "Get me one like this, or give your city to me and take away my new zen and tell me how much more you want". What a compliment man !! But, the compliments keep pouring in because I love my car and take care of it like a baby.

If you love honda cars and dont have budget to buy new honda city, go for a honda city from 2002-2004, this is really a value for money, make sure to evaluate it technically before buying it. Take a help of mechanic unless you know everything about under the hood. Here is a quick checklist

a) Number of previous owners.
b) Accident History - Misalignment of car frame, for this check the four wheel alignment of car or get it done from some showroom before buying it.
c) Check Service Records, most important, a person who maintains his car will surely maintain service record, also car that has been regularly serviced at showroom will always be in good condition.
d) Check the condition of tyres.
e) Check number of kilometers done, this will help to judge daily usage of car.
f) Try to talk to owner regarding the route on which he daily use the car, you can guess the wear and tear according to traffic condition on the road.
g) Try to see 4-5 options and analyse the above all parameters to go for best buy.
h) Finally, if everything seems ok, bargain but dont cancel the deal for few thousands, as there are few well maintained running on road.

There are some good dealers in NCR who will provide you warranty as well and free services for the first year, so what else you want, you will get luxury, comfort, warrantly, free services of a Honda at the cost of a new small car.

Tuesday, November 4, 2008

Differences between Delete, Drop and Truncate Statements

DELETE, DROP and TRUNCATE statements differ in their nature itself.

  • DELETE statement is a DML (DATA MANIPULATION LANGUAGE) statement.
  • DROP AND TRUNCATE statements are DDL (DATA definition language) statements.

A DML action can be rolled back if the data is not committed, but DDL actions cannot be rolled back until Oracle 9i. With Oracle 9i FLASH BACK enabled even some of the DDL statements can be rolled back.

Delete

A delete statement deletes the data from a table. A delete statement can have a “where” clause, which need to be satisfied for the data to be deleted from the table.

Actions of Delete statement

  • Deletes the data from the current table space.
  • Modifies the undo table space with the delete records.
  • Executes all the before / after statement and row level triggers.
  • Updates the indexes (makes the index empty if the where clause is omitted).
  • Constraint checks are performed before deleting the rows

Syntax of a delete Statement:

DELETE FROM table [WHERE condition]

Truncate

Truncate drops all the records in a table. But as it is a DDL statement data cannot be retrieved. Usually truncate is faster than delete statement because there is no need to change or update the UNDO table space with the deleted records. Truncate is an implicit commit Statement. Truncate statement deal locates the space.

Actions of Truncate Statement

  • Removes all the records from the current table space.
  • Updates the indexes.
  • High watermark of the truncated table is reset.
  • Integrity Constraint checks are performed

Syntax of a Truncate Statement:

TRUNCATE TABLE table_name;

DROP STATEMENT

A drop statement removes the table object from the database. Structure and the data will be removed from the database. Action cannot be rolled back (but only by FLASH BACK from Oracle 9i).

Actions of a Drop Statement:

  • Constraint checks are performed before dropping.
  • All the data and structure of the table will be removed.
  • Updates the corresponding data dictionary views like dba_objects, dba_tables, user_tables e.t.c.
  • Updates the Status as “INVALID” for all the dependent objects.
  • Deallocates the Space

Syntax of a Drop Statement:

DROP TABLE table_name;
DROP TABLE table_name cascade constraints;

If “cascade constraints” is specified all foreign keys that reference the table are dropped and then table is dropped.

Java 8 streams performance on mathematical calculations

Java 8 Streams API supports many parallel operations to process the data, it abstracts low level multithreading logic. To test performance d...