Monday 23 February 2015

snLibrary - Beginners Guide


snLibrary is a small Java library that though cannot be termed as a complete framework by itself, creates an environment - for the convenience of implementing Java based (/Web) Applications in organizations that do not have enough man power to monitor & maintain the deployment process. 

Organizations that do not have full time full fledged web-app server administrators who are dedicated to the upkeep of the applications and are not quite conversant about the working of each and every application hosted in the servers can make use of this 'snLibrary' for easy and trouble free deployment and implementation. 

What all can snLibrary provide you with?  Salient ones are:-

  1. Facilitates your application comply with Zero hard-coding.
  2. Independence between Developer, Tester & Web-server environments.
  3. Abstraction in Configurations on Development Machines, Testing Servers and Production Servers.
  4. Encapsulation of many commonly used useful utilities for the Developers.
  5. Downward compatibility for all class objects and methods.


If interested, let me now narrate you something about the history of the 'snLibrary'. However, if you think that you are not a 'history geek' and that History to you has always been a boring subject all through your successful career, you could also jump start into the waters for a sufficiently nice 'bath' in snLibrary!! by skipping this part!!.

History:-
I believe, it might have been sometime in 2005/2006 after I first put my hands into learning Java and developing Java applications sometime in 2001-02.  As a student of Java, (as most students do...), I started with the simple swing / awt based applications.  I had some interest in astrology and had taken up as a hobby during that time and therefore, wanted to make a computer application for calculating the astrological chart (given the date, time and place of birth) and further do a 'synastry' / match making upon it.  That was the time when we were searching for alliances for my brother and therefore, the synastry charges by local astrologers were not justified, considering the small pockets of my father who had by then retired from the central govt. service.  So it was necessary that I provide him with a small software that could do the initial screening at least, before he could actually perform his own detailed analysis & and thereafter consultation with some experienced practitioner of astrology.  

I had already written the software in 'C' much earlier (though I loved to have done it in LISP - which was my favourite subject during my college days); and having started understanding Java a bit, wanted to do it in Java, considering the terrific changes that were happening in the hardware and operating system (OS).  Java became the de-facto choice since it was known that Java was platform independent - meaning that it could run on any OS without the need for separate compilers at the place where it should execute.

So then, the first full fledged Java program was written and I called it snJatak. Many OOPs (Object Oriented Programming) concepts were of-course used and therefore, it became quite easy for me to convert that Java application into a full fledged Java-Web-application with just a few changes in the main code. 

After the initial rounds of test, it was hosted as well, and many felt it useful to have such a program freely available.  The challenge was that there was absolutely no help available from anyone, as such applications developed on Tomcat web-servers using Interactive Development Environments like NetBeans were uncommon in my office (or even Head Office) of work.  Even our Head Office, used Java Web-servers for their (only) few applications which underwent a very cumbersome procedure to compile the source codes and subsequently deploy. 

Having tasted success in the development of web-application using Netbeans and Tomcat, I ventured into developing small applications starting with local intranet for my office. 

Sometime later, we were assigned task of developing new web-based application and one of my sub-ordinate officers also started developing on the same platform.  For the purpose of testing and for ensuring smoothness as well as consistency, I held back the control of the web-server and therefore, every time there was a change in the code, I was called to deploy and that required few further changes here and there in the source code itself (and therefore necessarily, another round of compilation), as the database for production would not be that of the development!!.  

I decided that it was certainly not a good way of doing and therefore,  went on to develop something called  a library, that could get attached to an application, while all the application specific configurations could be done outside (ie. without affecting/touching) that library or even the compiled version of the application itself.  

"In programming I admonish hard-coded source codes."  and therefore, was born the 'snLibrary'.  As a library has to be re-usable, I removed many 'Classes' / 'Objects' and 'Methods' that were specific to snJatak while some related to the Date functions including Julian Date conversions were retained inside the package.

As mentioned above, this library had to be just a simple jar file that could be compiled with any java web-application and could provide a facility for importing configuration variables of different types (which we will see hereafter) and which values the programmer/developer wouldn't need to know at all when his/her web-application code went for deployment into the production.  

Yes, that meant that the developer could work in his/her own 'Development Environment', the tester could work in his/her own 'Testing Environment' and the production could have its own 'Production Environment'.  Frequent changes in the code would require testing and deployment of the .war (Web-Archive) file on to the production but would not call for as many frequent changes during each deployment process thereby reducing work for the Production site web-administrator

Over the period of time, when I moved to my Head Office, I found that the developers at HO were not using any latest technologies that would have simplified their work to a great extent.  Hence I introduced Netbeans-IDE, Tomcat Server and also snLibrary.  Many applications were ported to the new environment.  Then came a time when a series of applications were developed at the HO as required by  different departments as and when they came up with their new found requirements. 

One of the first already running (or should I say 'failing') applications that I attended was known as the 'bidLine' application which is being used for online bidding of interest rates by Banks.   The application was used for getting good bids for rates of interest from popular banks for the Company's Provident Fund Trust money deposit. I was told to understand that the application 'hanged' after few minutes of starting the application,  whenever it was open for bids by the banks.  

While going through the source-code, I found that the issue was the most common mistake any programmer would make in a Java-Web-application environment - i.e., Failure to Close a Database Connection.  This was a serious mistake according to me and therefore, I sat down to correct the code myself and used the 'snLibrary' for the connection pooling.   Ever since, it didn't crash and users could bid online without the need by the administrator, to frequently revise the bid date-time.  Thereafter finding that similar problem was noticed with another application called, the Holiday Home booking application - which was a well sought after application, the same modifications were carried out and that too was a success. 

Many other applications and new applications also started utilizing the services of the library with the success of another major application called e-CFS (paribhavam) a Customer Feedback System (2008-09). Many additional methods were added and the 'snLibrary' grew on and on with many new features.  As it was designed to be used and re-used by the developers, I made it a point to properly document it using 'javadoc' itself so that the code and the documentation always went together

In 2009-10, as part of endeavour to better development environment, I introduced to my Head Office developers, the Version Control using SVN (Sub-Version) and thankfully in due course (though with some initial hesitation), coders have started using version control for their source codes. I have also ensured that the common libraries that are often used in various applications be consolidated at single source - which I call the 'commonlibs' repository of SVN.  This repository is accessible by anyone in the Corporation using his/her Active Directory (AD) credentials. The URL (Uniform Resource Locator) being 'https://svctl.ds.indianoil.in:9501/svn/commonlibs/trunk/'.  This URL can be 'checked-out' from the SVN and would download libraries under two folders namely - 'customlibs' and 'sharedlibs'.  snLibrary has been dedicated under 'customlibs' folder.

Today, it has many functionalities and hence, it has become necessary to have some sort of guide on the lines of FAQ (Frequently asked questions) - even though they might not be indeed frequently asked!!.  

Therefore, despite the fact that there exists a javadoc documentation inside the 'commonlibs-> customlibs' folder along with a README.txt file in the same folder, the next blogs herein will give an FAQ kind-of guide for the 'snLibrary'.

This I hope should ensure easy and greater understanding of the 'snLibrary' and its utility.

In the following blogs (under T - for Technical), I shall try to introduce the 'snLibrary' in particular in the order of the release of the various versions starting from 2010. 

- Happy Coding ........ 


Basic Configurations for NetBeans:-

There are some basic configurations that can be done before we startoff with NetBeans development.  I have provided within commonlibs a folder by name:
C:\commonlibs\sharedlibs\.netbeans\8.0\config\org-netbeans-api-project-libraries\Libraries
This folder contains a set of .xml files which should be copied to the similar path under .netbeans of the C:\Users\<DomainLoginID>\.netbeans in case of Netbeans 6.9 or earlier and into C:\Users\<DomainLoginID>\AppData\Roaming\NetBeans\8.0\config\org-netbeans-api-project-libraries\Libraries in case of 7.0 or later.  Once you restart NetBeans, you would have got all the necessary libraries in place which you can verify through option:- Tools->Libraries.

snLibrary - from Tools Libraries



It is also recommended good practice to set both No. of Spaces per Indent and Tab Size under 'Tools-> Options-> Editor-> Formatting' to 2 characters each.

For better Formatting 





No comments:

Post a Comment