Knowledge is our wisdom & i want to share the knowledge which i learnt recent times. Keep following my blog for new updates
Sunday, February 26, 2012
To read Window’s close button event using java script for application specific processing like session clear etc.
Monday, February 20, 2012
Windows authentication using SingleSignOn within J2EE/.net application
Saturday, February 11, 2012
To deal with Java BigDecimal object within a financial application
Hi Guyz,
I am working for one of the UK government owned bank from last two years. I worked for International payments project. Personally, I have learned many things as a developer. Thought of share my technical learning’s in my personal blog to benefit others as well.
From the post title, you can come to know that I am going to write something about java.math.BigDecimal object usage. Let me explain the scenario here, so that you can understand the issue better. Since it is International payment, customer is free to select the payment currency from the list of available currencies to express the payment amount. Something likes 100.00 USD OR 50.00 GBP OR 34.98 EUR etc. As per the application design, we should not store the payment amount with decimals. We should store only in long values; we used to convert the payment amount based on currency decimal places. Ie 100.00 USD will be stored as 10000, 34.98 EUR will be stored as 3498, 45 JPY will be stored as 45 and 45.985 KWD will be stored as 45985 in payment amount column. If you see closely look these, the payment currencies are ISO currency codes which has it’s own currency decimal places to be allowed (For currencies like INR, GBP, USD, EUR you can have currency decimals maximum of 2 and all Dinars currency decimals maximum of 3 and for JPY no currency decimals to represent the payment amount).
We used movePointRight method available in java.math.BigDecimal to perform the above mentioned logic. Unfortunately my input type is primitive double which returns incorrect result. To add more details, if I pass payment amount as 77.80(double value) to the movePointRight method, it returns 77.79 (we were loosing one final decimal value). One of our UAT meetings, the user raised a concern asking how they are loosing ‘one cent’ if they enter payment amount as 77.8 EUR. When we debug the code, realized there was wrong amount conversion was happening if we use movePointRight method available in BigDecimal class for double/float arguments. We have written our own code to address this issue. But this issue can be addressed in a simple way. Ie, if we pass payment amount as string value to the movePointRight method it works fine.
Mentioned issue is clearly explained form the below mentioned example. You can run this program to get more information.
/*
* File: JavaDecimalBug.java
* Created/Last updated Date: Feb 7, 2012
* Created/Last updated by: Blx
* Last updated Time: 10:30:33 PM
* Copyright: BLX
*
* Revision History:
*******************************************************************
* Date Author Version Comments
*------------------------------------------------------------------
*
*/
package com.blx.laern.java.bug;
import java.math.BigDecimal;
/**
* @author Nanjundan Chinnasamy
* @version 1.0
*
*/
public class JavaDecimalBug {
/**
*
* @param value
* @param points
* @return
*/
private static long convertDecimalToLongByPoints(double value, int points) {
BigDecimal amountBD = new BigDecimal(value);
return amountBD.movePointRight(points).longValue();
}
/**
*
* @param value
* @param points
* @return
*/
private static long convertDecimalToLongByPoints(String value, int points) {
BigDecimal amountBD = new BigDecimal(value);
return amountBD.movePointRight(points).longValue();
}
/**
*
* @param args
*/
public static void main(String[] args) {
double paymentAmountInDub = 77.8;// 77.88, 77.97
String paymentAmountInStr = String.valueOf(paymentAmountInDub);
System.out.println(convertDecimalToLongByPoints(paymentAmountInDub, 2));
System.out.println(convertDecimalToLongByPoints(paymentAmountInStr, 2));
}
}
Result:
7779
7780
Saturday, February 4, 2012
Web application performance tips and tricks
I was interested in web application performance improvement topic earlier. When we (Myself and TechLead) discussed on this regard, he advised me to go through Yahoo Developer website on Web application Performance Improvement article (http://developer.yahoo.com/performance/rules.html). It adds more interests to go through similar topics earlier. After doing further Google search, found an interesting article from Balusc blog (http://balusc.blogspot.com/2009/09/webapplication-performance-tips-and.html) where he recommends few more option to enhance the web application performance, on top of the options mentioned in the above Yahoo developer Group website. It sounds more interesting.
So you might think, what am I trying to convey to my developer? J Did further search and come up with few more details on how we can design web application with the improved performance.
My analysis after referring an existing travel agent website below:
1) Use Of Content Delivery Network:
Reference#1 Yarta.Com (Website: http://uk.yatra.com/)
Style sheets downloaded from: http://css3.yatra.com
eg: http://css3.yatra.com/UK/include/css/uk-india-uk.css
Java script down laded from: http://js1.yatra.com
Eg: http://js1.yatra.com/UK/include/js/homepage.js
Images down loaded from: http://img1.yatra.com
Eg: http://img1.yatra.com/images/UK/AIR/continue_but.gif
Separate CNS referred to deliver specific content instead of delivering to Static content alone. This has been mentioned in my below diagram.
2. Points noticed during our analysis:
- All the images are gif format. It is very less in size. They tried to minimize total no of images in a page as much as possible
- Many of them embedded images along with Style sheet
- Same application used for both http & https. Based on the protocol type actions were defined
- A CSS Sprite (http://spritegen.website-performance.org/section/what-are-css-sprites) is a combination of smaller images into one big image. So that we can reduce total no of http requests
- Don’t have spaces as much as possible in CSS/JS. Static file download time is directly related to size of the files
This chuck of CSS:
.some-class {
color: #ffffff;
line-height: 20px;
font-size: 9px;
}
can be converted to:
.some-class{color:#fff;line-height:20px;font-size:9px;}
…and it’ll work just fine.
- Try to have many forms as much as possible. In other words, our form should not have complex/more inputs
http://sixrevisions.com/tools/faster_web_page/
CSS:
http://sixrevisions.com/css/css_code_optimization_formatting_validation/
Image:
Digg (shown above http://digg.com), you can see individual icons for user interaction. To reduce server requests, Digg combined several icons in one big image and then used CSS to position them appropriately.
JavaScript:
JSMIN - http://www.crockford.com/javascript/jsmin.html
YUI Compressor - http://developer.yahoo.com/yui/compressor/
Java Script code improver - http://jcay.com/id-190119110113039.html
5) Reference:
http://sixrevisions.com/web-development/10-ways-to-improve-your-web-page-performance/
Hope this will add more interest to you as well! Happy learning!
-NJN
Password Encryption using Java
Hi Guyz,
My Business Unit is in the process of creating a new development process tool something like Teamtracker for Internal purpose. I was identified as a secondary developer to complete the tool three weeks back. Almost 70% of the development activities have been completed so far. Within an application, we have list of users and their credential details, roles and projects etc.. and those details were stored in database as a plain text.
I found a very interesting article on Password Encryption using java code (http://www.devbistro.com/articles/Java/Password-Encryption). Beauty of this article is it is self explanatory, it doesn't require any third party jar files. With in 15 mins of time, I was able to complete the requirement.
Thought of sharing my learning’s to my readers as well. Hope you also enjoy! Happy programming.
Cheers
Nanjudan Chinnasamy
Monday, January 16, 2012
Way to Prevent Duplicate Request from Form in J2EE applications - 3
To fix duplicate form submission issue, you essentially need to implement the Synchroniser Token pattern.
This Synchroniser Token pattern is a common technique as follows:
- Your application generates a unique token (based upon date, time and session id maybe) with each request or submits from the browser and embeds it in each HTML page returned to the browser as a hidden field.
- When the user hits a submit button, at the server you check that the token in the page matches the token on the server.
- If it does, you carry on.
- If it doesn't, you don't accept the submitted data (you either fail or just show the user the last page with an error/warning).
- Once the token is checked you immediately create a new unique token.
Now, if the same page is submitted again (by pressing the refresh button) or an old page is submitted (by the user pressing Back) the tokens will no longer match, as the server token was changed, so you can reject the submission.
-Happy Programming,
-NjN
Wednesday, January 11, 2012
Steps to enable SSL in Tomcat server
http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
http://www.globalsign.com/support/faq/tomcat/09.php
Tomcat Server - conf/server.xml file SSL settings & to generate a keystore, follow the steps mentioned in Tomcat support document.
For JBOSS application server lovers, it will be very similar to Tomcat.
-NJN
Pega Decisioning Consultant - Mission Test Quiz & Answers
The Pega Certified Decisioning Consultant (PCDC) certification is for professionals participating in the design and development of a Pega ...
-
The Pega Certified Decisioning Consultant (PCDC) certification is for professionals participating in the design and development of a Pega ...
-
Hi Guyz, My Business Unit is in the process of creating a new development process tool something like Teamtracker for Internal purpose. I...
-
This blog is all about improving “Customer Service” further from the where we are now. It's an Ideation Blog. Like banks across th...