Friday, October 5, 2012

Screenprint using Fireshot


Last week I have come across a tool called “Fire Shot”. I admired about the techniques and the various options provided by that tool.

It is used to capture the screen prints and can be directly saved as image, pdf etc.. The beauty is if you have a lengthy screen which requires page scrolling, the entire page can be captured as a single image.


Wednesday, September 5, 2012

Google plus launches tool for business?


From the post title, open source developers and small business entrepreneurs will be vey happy to see such a great initiative from google. Yes, It’s google plus tool available freely by 2013. We could have use these tools effectively for sharing the data and meeting the friends and colleagues across the world. Sounds good?!

You can see more details from the below mentioned link. Happy reading!
http://mashable.com/2012/08/29/google-plus-for-business

_NjN

Thursday, August 30, 2012

How to know the version of the java/j2ee application deployed?



Many occasions, you might have come across the circumstances where you may want to know the version of the application deployed for particular instances like System testing, UAT and production. Possible situations are,
1. As part of post deployment activity, you may wanted to ensure the whether the deployed build(s) is successfully deployed or not.
2. To see the version of the build deployed in production (to know the stable version of the build). You might have seen many open source applications for this. 

Ant target to achieve the same:


Java Class file that can read the MANIFEST.MF file attributes:
Code is self explanatory.   We have a small piece of Code to get the ServertContext from FacesContext.  If you are not using JSF, replace with relevant code base.





JSF presentation file used to display the MANIFEST.MF file attributes:
Below is the design view of the presentation. Bean attribute values will be populated using VersionInfoMFReader.java class file as mentioned above. Here, presentation values will be populated from the bean as below.




We have implemented the above version info reader in our application. Sample application screen print attached below. 







Tuesday, July 24, 2012

Garbage to Electricity, What does it mean to IT?


Recently, I had gone through the article on “technology to convert solid waste to electric energy”. Just admired about the innovative thought, who really thinks of others need. I* am sure, it will be great news for those who live in an electricity shortage places across the globe.
Now, I am envisaging a similar situation, one related to information technology and how this could influence the software applications. Let’s think about the quantum of application logs that are being archived on daily basis. Most of the times, we consider application logs as garbage, until we’d truly need it to resolve any critical technical incidents. My simple question to you – Have you ever taken a closer look at these logs? May it be data related or scenario based issues?  

I strongly believe these application logs are yet important information which could be used to analyze issues, and findings, which in turn might allure to a new requirement. Those might not only improve the overall application performance or quality, but as well to improve the overall customer, front line staff (if it is branch based application) and application management staff satisfaction and experience.

What do you think?

Honestly, how many invest on overall application improvement activities?

Monday, June 25, 2012

Wanted to generate PDF and MS Excel Reports within Java application?


Do you want to develop a reporting capability within java based application? I have shared my knowledge/experience on reporting projects which I have worked earlier. Happy to hear if from you if you have any concerns/suggestions.

To work with PDF Reports:

We have used FOP and iText earlier (not both in a same project) to create a pdf report using Java. Please read the below for each of its pros and cons.

FOP:
It is an open source Java API to create a PDF report dynamically in a template format. If you have a XML data and formatting object template (xsl), creating PDF report using FOP is very easy.  I would say only 3 lines of code will help you to create a PDF report.

XSLFO is a XSL formatting objects and can be used for formatting XML data and to generate PDF report. Using FOP, it is easy for us to generate a read-only pdf. At the same time, we can’t alter an existing pdf or we can’t apply any security within a pdf using FOP. Want to know more? Have a look @ http://www.codeproject.com/Articles/37663/PDF-Geneartion-using-XSLFO-and-FOP

iText:

It is an open-source and more powerful java api for creating a PDF file using java. Using iText, developers can create a PDF file with digital signature and security (including having permission for opening a document, print/copy the pdf). In addition to that, we can manipulate, split and concatenate the existing PDF(s) within Java program. Also, we can build a form within PDF document. Good set of working examples are available @ http://itextpdf.com/

You can choose the right framework to address your pdf needs.


To work with Excel Reports:

We have used POI and JExcel earlier (not both in a same project) to create a Microsoft   xls (spread sheet) report using Java. Please read the below for each of its pros and cons.

POI:
It is an open source Java API to read/write/modify Excel spread sheets dynamically if you have a template already (xsl). Say implementing the POI will be very easy if you already have the xml data response and xsl template for your report. As I understand, POI is not improved as much like JExcel in terms of protecting the xls spread sheet data. Want to learn more, please look at http://poi.apache.org

JExcel:
It is an open source Java API to read/write/modify Excel spread sheets dynamically. If you want to apply security OR to derive a new data (Sum, average etc) using the existing data, JExcel will be the right option. It is a Java API, we wanted to write Java code for column alignment, font, style etc.  Also, it supports copying charts and images into excel sheet. Want to know more? Visit http://jexcelapi.sourceforge.net/

If you unable to follow the examples used in the above links, any issues or sample codes, reach put to me.

_NjN

Saturday, June 23, 2012

“Lines of Code” Calculator


Are you finding difficulty in calculating “Lines of Codes” written in java based application? I can strongly recommend the open source tool “LOC Calculator” to do the same. It comes with very simple UI screen which is used to calculate the LOC in 10 seconds of time. Sounds interesting? Try the LOC calculator @ http://code.google.com/p/loc-calculator/


Cheers,
_NjN

Friday, June 1, 2012

Password Encryption (Hex Code) using java


In my early blog (http://nanjundanonlinedictonary.co.in/2012/02/password-encryprion-using-java.html), I had articulated the easy way of password encryption using java. The program would result an encrypted text in a hash format but not in a hex code as we can see in Spring ACEGI framework. Here in this article, we are specifically focus on possibilities to convert SHA hash password SHA hex password.

Old Code:
  
byte rawBytes[] = md.digest();
String hashPassword = (new BASE64Encoder()).encode(rawBytes);
  

New Code:

byte rawBytes[] = md.digest();
StringBuffer strBuffer = new StringBuffer();
      for (byte rawByte : rawBytes) {
        strBuffer.append(Integer.toHexString((int) (rawByte & 0xff)));
      }
String hexText = strBuffer.toString();

Saturday, May 19, 2012

How to update the Log4J logger level dynamically for a web application?


Are you looking for an option o update the Log4J logger level dynamically for a web application? If so, here is the solution for people like you to update the logger which doesn’t require any log4j,xml file configuration change or serve restart.

Here we had developed a jsp page that will show the current loggerName, loggerlevel and the list of logger levels lits it can take. Now, you can select the new log level from selectbox to set the new logger on the fly.

Here is the code sample. Wanna try?


<%@ page import="org.apache.log4j.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Dynamic Log4J control
<%
            Logger logger = Logger.getRootLogger();
            logger.setLevel(Level.toLevel(
                                    request.getParameter("selectedLevel"), Level.INFO));
%>


           

                       

           

           

                       

                       

                       

           

           

                       

                       

                       

           


                       

Dynamic Log4J control


                       
Current Log Level Logger Name Set New Log level
${rootLogger.level} ${rootLogger.name}

Friday, April 13, 2012

Ear comparator


Many Occasions, we might end up with comparing two ear/war files in our project for some reasons. Here is the link for EAR comparator utility (Good stuff Joseph! – The mastermind behind this tool). You may think it will be good if you have some utility to compare such circumstances.

I have link below for ear files comparator utility. I strongly recommend this tool to make your job easier. 


Anymore suggestions? Drop those in comments section.

Cheers,
-NjN

Sunday, April 8, 2012

To start work with Maven (more than a build and deploy tool)


So far I have used ant as a build tool in all my projects. When I recently gone through the articles, found Maven used widely in most of the Java/J2EE applications. I tried to install maven in my machine recently. But found many issues and it was very difficult to follow the setup to complete my very first build.

I have found an excellent material to work with Maven. It has step by step guide with the screen prints. I found the below link is very interesting to follow. Hope this will useful to you as well.


Friday, April 6, 2012

How to work with browser specific Style sheets

If you would have worked with web applications I am sure you might had difficult time to deal with applying the style sheets specific to browser and its’ version.
Have found nice information on applying the browser specific style sheets recently.  Wanted to share with you guys.
Below article explains very well on conditional based approach (browser & version) to apply the different CSS files. This is most commonly used approach as well. 

CSS cross browser selector comes with noticeable approach, where we no need to write different CSS files. Within the same CSS file we can mention the style classes based on the brower&version.

The second will be most preferable if we have css file with lesser contents. What do you think?

Monday, March 19, 2012

Java Anti Patterns:


I had gone through core java design patterns last week (I am sure I will consolidate my learning with simple examples and post you in my blog. I will try to keep as much as my own examples).

We have a proverb in our native language that “If you wanna become good doctor, you should have killed 100+ patients”. What they try to say here is if we want to give the best, we should have experience/come across as many nastiest.  

So, before I start my Java design patterns, I had gone through few Java Anti patterns which are readily available in the internet. I found the below link gives you Insite on Java Anti patterns. Hope you enjoy as well.

Please share me if you find any good link for Java Anti patterns.

http://www.odi.ch/prog/design/newbies.php

Friday, March 2, 2012

To get the newly stored record auto generated key (primary key) with in hibernate


I have seen few hibernate (ORM framework) codes have always uses saveOrUpdate method to create a record newly or to update the existing records. Most of the occasions, we were dam sure that a new record is gonna insert. Such occasions, we can use save method itself. No harm.  

Here I am going to discuss some peculiar scenario where we may need to get the primary key of the newly added record to send as a response to UI.

For Example, I am capturing required employee details and creating a new Employee record. Usually we used to display feedback as Info message in the screen stating “Employee record has been added successfully. as a response. Sometime we may need to display meaningful info message using the generated unique key for newly created record like “Employee record (1000001) has been added successfully.” Here, 1000001 is the primary of the newly inserted record.

To address the above requirement, I have seen few codes (mostly written by beginners), they used to call the save command (insert query) and use another select statement which gets you the recent record primary key column. It may work fine for the single user/thread environment. The same may not be true for multi thread environment. To address this issue in a multi threaded environment, below code may be useful for you to achieve the same.

Here, employeeObj is the hibernate object POJO for Employee Table. If we use hibernate save command, which will intern returns you the Serializable interface can cast to the primary key of the newly inserted record like below.  


//Plain Hibernate
Serializable t_pk  = t_session.save(employeeObj);

//Hibernate with Spring framework
Serializable t_pk  = getHibernateTemplate().save(employeeObj);


Long newEmployeeId = (long) t_pk  ;


Any thoughts? Please drop your comment.  


Cheers,
-NjN

Sunday, February 26, 2012

To read Window’s close button event using java script for application specific processing like session clear etc.


We are in very rapid technology transition world. Writing an application which is comparable to all the browsers and environments will be a tedious task for the developers like me.

Let me write a common & interesting issue with the web application session handling. While developing the web application, we will be clear about the scope of the variable to be used with in a web application (Like application, Session, Request and page scope etc). The entire logged in user specific details usually will be stored as session attributes. If we clear all session attributes, prior to closing the web application, its fine. No Harm. The same can be turned to be a headache if HttpSession was not handled properly. However if you use IE6, browser session automatically collected. In IE7, the same session will be used irrespective of the tabs opened within a browser instance. For IE8, same session will be used for all the browser/tab instances opened in a machine.

In a typical web application, we will be providing a Close/LogOff kind of buttons, so user could follow some basic process to exit the web application, using the button, we can handle the HttpSession. Also, we can’t assume that everyone would follow the process (It’s like turning off the PC. Sometimes we used to press the power button instead of shut down our PC). Now, the question is how can we handle, user session attributes such occasions as well.

Below example is self explanatory to address the above mentioned issue specifically for IE. Write to me if anything unclear.



Monday, February 20, 2012

Windows authentication using SingleSignOn within J2EE/.net application


Today I am going to write about Windows authentication using SingleSignOn method with-in j2EE and asp.net applications. Hope you will enjoy.

Consider the scenario where you are developing a web application, which can be used with-in an organization (Intranet environment) and also in Would Wide Web (Internet environment). Both the environments, application business logic would be. The only key difference would be, the authentication mechanism used among these two applications.

With in Internet environment, we may end up with displaying login page, where need to get the username and password from user and the same will to be validated in backend. Once authentication successful, we would be invoking application page.

Incase of Intranet environment, we know that the request is coming from trusted domain.  Hence we can go with Windows authentication using SingleSignOn option, to not to prompt username and password to login the application. Here, we can read the login username using windows shell script and set password can be set as some unique text and we can click the login submit button using java script. If request contains the password mentioned in html/jsp, we can consider request is intranet users, So we can consider the request as valid one, BUT we should check the username is correct and has correct privilege to access the application.

HTML code sample here explained for Windows authentication using SOO with in login page. Similar login page can be created for Internet application as well.  The only difference would be, we would be end u with calling setFocusForText java script mention in onload and anywhere with in th page.

<HTML>
<HEAD>
<TITLE> This is Windows authentication SOO testing TITLE>
HEAD>
<script type="text/javascript">
function setFocusForText() {
            document.getElementById("userNameText").focus();
            var wshShell = new ActiveXObject("wscript.shell");
            var userNameFromWin=wshShell.ExpandEnvironmentStrings("%username%");
            document.getElementById("userNameText").value=userNameFromWin;
            document.getElementById("passwordText").value="~~~~";
            document.getElementById("loginMe").click();
}
script>
<BODY onload="javascript:setFocusForText();">
<form id="loginForm" >
            <input type="text" id="userNameText" value=""/>
            <input type="password" id="passwordText" value="" />
            <input id="loginMe" value="Login" type="submit" />
form>
BODY>
HTML>


Do you think, hard coding the password with in html is venerable? If so, follow my previous blog to implement password encryption algorithm and store the same. And also, user can’t see the SSO page since it is kind of auto submit page. Page load would happen with in fraction of seconds.

Any other queries in your mind? Add it in comments section. Happy to respond to you. 

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


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 ...