Friday, December 31, 2010

Database connection using DataSource in Oracle using JNDI names, Server running on Weblogic 9.2

//Database connection using DataSource in Oracle using JNDI names, Server running on Weblogic 9.2:

JARs required:


//Java code
import java.sql.Connection;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DataSourceConnection {
public static void main(String[] args) {
Connection connection = null;
try {
Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
jndiProperties.put("java.naming.provider.url", "t3://");

InitialContext context = new InitialContext(jndiProperties);
DataSource dataSource = (DataSource) context.lookup("jdbc/obodb_XA_ds");
connection = dataSource.getConnection();
System.out.println("Connection successful.."+connection.isReadOnly());

catch (Exception e) {

Thursday, December 16, 2010

URL/Link for Advanced Servlets

Link for advanced servlets:

Hibernate loggers:

Thursday, October 28, 2010

Microsoft Outlook Emails back up

Microsoft Outlook back up file locations:

File->Import/Export->As a personal folder *.pst file

C:\Documents and Settings\deepak\Local Settings\Application Data\Microsoft\Outlook\

Friday, September 3, 2010

Important Utility forms

Here are the links to download some Important/Utility Forms:

PF Closing Forms- Form 19 and Form 10C:

Unix command to copy files between 2 Systems

Dear Reader,
Today I am writing Unix commands to copy files and directories in Unix systems without FileZilla or 
WinScp like User Interfaces.

Suppose you want to copy a file from one system (SOURCE) to another system (DESTINATION), Login into 
DESTINATION system. Go to the location where you want to keep the copied contents.

    SOURCE IP: X.X.X.113  (Type full numeric complete IP address in copy command).
    DESTINATION IP: X.X.X.50 (Type full numeric complete IP address in copy command).
    UserName for SOURCE IP: dm0945
    Password: System will ask once you enter the below copy command.    
    First login into DESTINATION IP system and move to destination directory, then type below command:
    scp dm0945@X.X.X.113:/home/dmodi/log/q2-2011-09-21.log  .    (Press Enter, it will ask password for X.X.X.113 system.
    The log file will be copied to current location of DESTINATION IP System. 
Above command will copy a file, if you want entire diectory to copy, tweak the above command as below:
    scp -r dm0945@X.X.X.113:/home/dmodi/log/q2-2011-09-21.log  . (Press Enter, it will ask password for X.X.X.113 system.
    Entire log directory will be copied to current location of DESTINATION IP System. 


Thursday, September 2, 2010

Desktop wallpaper sites

Good wallpaper sites:,why-the-bodyguards-lose-his-job-super-funny.html

Wednesday, September 1, 2010

IFSC codes of my banks

IFSC Codes:

SBI MG Road- SBIN0005778
UNION Chandra layout- UBIN0556343
United Shivaji nagar- UTBI0SHV823

Thursday, August 19, 2010

String comparison in Java

String class is an important API in Java but this is the most confusing also when asked in Interviews
regarding its comparison with another String. Here I am discussing the same.

The difference between == and equals(): Both operators can be used in Java, but the second one is a method.

"==" This is called the "Equal to" operator and is used to compare "primitive" types or check if 
you have equal object references(or do they refer to the same object in the heap). There are 8 primitive 
types in Java and you can usually identify them: 
byte, short, int, long, float, double, boolean, char

When used with Strings, one might assume that you are making a comparison with the String values, but no. 
We mentioned above that "Equal to" operator checks for object references when used with objects.

So let's assume the following code:
String s1 = "STRING ME";
String s2 = "STRING ME";
System.out.println("s1 == s2 is " + (s1 == s2));

This would output:
s1 == s2 is true

Why? The JVM does some optimization step with Strings(i.e the Strings get "pooled"). Basically, the JVM 
makes you point to the same Object reference that is pooled in the heap.

Let's make some modification with the Strings
s1 += "2";
s2 += "2";
System.out.println("s1: " + s1);
System.out.println("s2: " + s2);
System.out.println("s1 == s2 is " + (s1 == s2));

The output is now:
s1 == s2 is false

Why? Because Strings are "immutable", new Object references are actually created. The String was not actually 
modified, it is a new String object. They are now different object references.

Now, what most of us usually want is "OBJECT EQUALITY", and that's what the next thing is for "equals()"
All objects can use and override the equals() method. Any instance of a class you use or created automatically 
inherits this method. Without overriding, you use the default implementation of the Object class which is not 
very helpful. This works differently when used with the java.lang.String class as it does some character 
comparisons. You cannot override this method in String because String is a final class and cannot be extended.

Using a similar set of code, let's try to make modifications with the Equal To operator, for the String references 
to use the equals() method.

String s1 = "STRING ME";
String s2 = "STRING ME";
System.out.println("s1 == s2 is " + (s1.equals(s2) ) ); //true

s1 += "2";
s2 += "2";
System.out.println("s1 == s2 is " + (s1.equals(s2) ) ); //true
//Both will display "true".

So a final complete example with some added test cases:
public class StringAnother {
    public static void main(String[] args) {
        String s1="Hello";
        String s2=new String("Hello");
        String s3="Hello";
        String s4=new StringBuffer("Hello").toString();
        String s5="Hel"+"lo";
        System.out.println("s1==s2: "+(s1==s2));
        System.out.println("s1==s3: "+(s1==s3));
        System.out.println("s1==s4: "+(s1==s4));
        System.out.println("s1==s5: "+(s1==s5));
s1==s2: false
s1==s3: true
s1==s4: false
s1==s5: true

Wednesday, August 11, 2010

SVN plugin in myeclipse 6.5

SVN plugin in myeclipse 6.5:

MyEclipse-> Help ->Software Updates -> Find and Install -> Search for new features to install-> Next -> New Remote Site->

Now please enter values in text fields of Dialog box:

Name- SVN

Click on Ok/Next/Finish. You need only SVN/Subeclipse, Avoid any other libraries shown like JNA..

Ration card rules in bangalore

Taken from:

Life is so much easier if you have a ration card. Whether you buy the rations doled out or not, it is wiser to possess one, because it has its uses - whether it's at the passport office or the RTO.
For getting a ration card afresh, here's what you have to do:
•You have to fill in an application form available at any of the five range offices of the Food and Civil Supplies department.
•You will also need your voter identity card, and a court fee stamp of Rs 2.
•Attach proof of residence. For this, you can offer any one of the following - rent agreement document, tax paid receipt, telephone bill, gas bill, electricity bill, bank passbook; even a letter mailed to the house will do.
Submit these at the jurisdictional range office. There are five of them: East - near RBANMS college, West - Bhashyam Circle, Rajajinagar, North - Vyalikaval, South - 5th main road, Chamarajpet, Central - opposite Vishveshwaraiah museum.
Submit the documents, get an acknowledgement. An inspector from the department will visit your residence to check if you really reside there, after which he sends his report to the office. And the ration card is ready for you to collect in less than a month.
On the day you go to receive your card, pay Rs 45, and get a computerised card, complete with your photo in it.
Surrender certificate
In case you are applying for a ration card and you have held one earlier at another place, you have to get a surrender certificate from the previous place. A ration card will be issued afresh on the same day.
Deletion certificate
In case there has been a bifurcation in the family, if a member has married and moved away, the name has to be deleted. For this you have to get a deletion certificate and apply with the other documents. The card will be issued on the same day.
Addition certificate
If a child's name is to be included, produce the birth certificate. If you don't have one, get a certificate issued by the school authorities. The card will be issued on the same day.
According to officials at the Food and Civil Supplies department, Chamarajpet, there are three kinds of ration cards issued - yellow (earlier green) for those below the poverty line; blue card or the photo card for those above the poverty line; and the white card or what is called the honorary card, for those who want the card only for address proof purposes and not for rations. This is issued within 10 days of your applying for it.

Friday, August 6, 2010

List of JDBC drivers for Java

A List of JDBC Drivers
If you need to access a database with Java, you need a driver. This is a list of the drivers available, what database they can access, who makes it, and how to contact them.



Microsoft SQL Server

Oracle Thin

PointBase Embedded Server


Cloudscape RMI

Firebird (JCA/JDBC Driver)

Informix Dynamic Server

Hypersonic SQL (v1.2 and earlier)

Hypersonic SQL (v1.3 and later)

Microsoft SQL Server (JTurbo Driver)

Microsoft SQL Server (Sprinta Driver)

Microsoft SQL Server 2000 (Microsoft Driver)

MySQL (MM.MySQL Driver)

Oracle OCI 8i

Oracle OCI 9i

To test your driver once it's installed, try the following code:
//Java code

Class.forName("Driver name");
Connection con = DriverManager.getConnenction("jdbcurl","username","password");
//other manipulation using jdbc commands
catch(Exception e)

//Taken from a site:

Thursday, July 8, 2010

Facade Design pattern

Facade pattern hides the complexities of the system and provides an interface to the client using which the 
client can access the system. Call Center people are representation of entire product which company promotes.
This pattern adds an interface to existing system to hide its complexities. 

The interface JDBC can be called a facade. We as users or clients create connection using the “java.sql.Connection” 
interface, the implementation of which we are not concerned about. The implementation is left to the vendor of driver.

public interface Shape {
   void draw();

public class Rectangle implements Shape {
   public void draw() {
      System.out.println("Rectangle::  draw()");

public class Square implements Shape {
   public void draw() {
      System.out.println("Square::  draw()");

public class Circle implements Shape {
   public void draw() {
      System.out.println("Circle::  draw()");

public class ShapeMaker {
   private Shape circle;
   private Shape rectangle;
   private Shape square;

   public ShapeMaker() {
      circle = new Circle();
      rectangle = new Rectangle();
      square = new Square();

   public void drawCircle(){
   public void drawRectangle(){
   public void drawSquare(){

//Main Program
public class FacadePatternDemo {
   public static void main(String[] args) {
      ShapeMaker shapeMaker = new ShapeMaker();


Wednesday, June 30, 2010

Our Enggineering college is in 33rd Rank in all over India

My Engg college is in 33rd Rank in India in 2010:

Monday, June 28, 2010

Creating and Executing a Jar file using Command Prompt in Java

Dear reader,

I am writing an article today about creation and execution of Jar file in Java.
A jar file is nothing but a zipped file having Java classes and other files (may be xml, properties, manifest file etc).

Creation of Jar is quite easier however sometimes we face problem while executing a jar which has a main class
and if that requires some supporting Jar files too. By the way, if you know these things, you can ignore this 
article. But I do hope, please go through once and comment if find something better..

//Creating Jar and Running Jar file from Command Prompt
1) First Test your program without creating jar file, whether it is running or not.
//For this, first set classpath in Windows Operating System, we assume our package starts from "D:\smpp_new>" directory:
Directory structure:  D:\smpp_new>com\......\*.java

    Command_Prompt> set classpath=;%classpath%;.

//Compiling and creating packages with Classes in one command
    D:\smpp_new>javac -d . com\logica\smpp\test\

//Running your main class, We assume Main class is "" which is in below package
    D:\smpp_new>java com/logica/smpp/test/SMPPConnector

//If it runs, then fine.....we will go ahead creating JAR and running it....

2) Now create a Folder in parallel to your Starting package.. here in "D:\smpp_new>" as "META-INF". Then create a file "MANIFEST.MF" inside this META-INF folder, now your directory structure will be:
E.g:  D:\smpp_new>com\......\*.java

//Contents of MANIFEST.MF file:
    Manifest-Version: 1.2
    Main-Class: com.logica.smpp.test.SMPPConnector
    Created-By: 1.5 (Sun Microsystems Inc.)

    //Remember, after writing this, your cursor should be at the end of the line "Created-By: 1.5 (Sun Microsystems Inc.)", 
    //Not below this line. Manifest jar should not have "/n" type of things.

    //In case your jar is dependent on some classpath, which still needs at runtime, please mention it in MANIFEST FILE like below:
    Manifest-Version: 1.2
    Class-Path: ./DecryptionUtilityLib/commons-codec-1.3.jar ./DecryptionUtilityLib/coreUtil.jar
    Created-By: 1.5 (Sun Microsystems Inc.)

//Now create Jar file:
    D:\smpp_new>jar cfm smppconnector.jar META-INF\MANIFEST.MF com\*

//Run your Jar file:
    D:\smpp_new>java -jar smppconnector.jar

Friday, June 25, 2010

Thread safety and Synchronization at Class level in Java

Thread safety and Synchronization at Class level in Java

Can someone throw some light on the behaviour of class/object level monitor in java? Does one takes 
precedence over other? What happens when, class has both synchronized instance methods and synchronized static methods? 
Does calling thread has to acquire both class/object locks?

    Those locks are not related, and each needs to be obtained regardless of the other. Namely, if you have:
    class Foo{
        static synchronized void staticMethod(){}
        synchronized void instanceMethod(){}

    And then an instance: Foo f=new Foo();
    Then you have 2 unrelated monitors (one for class Foo, one for instance f ). Any threads attempting to invoke 
    staticMethod() will need to gain access to the (single) class monitor, and nothing else. Any threads calling 
    f.instanceMethod() will need to gain access to "f" monitor, and nothing else.
    If you need any access hierarchy, you'll need to do it programatically, which may look as follows (however, beware 
    - such nested locks pose some dangers of deadlocks unless used with care):
            // my code

    A synchronized method acquires a lock before it executes. For a class (static) method, the lock associated with the 
    Class object for the method's class is used. For an instance method, the lock associated with this (the object for 
    which the method was invoked) is used.

    class Test {
        int count;
        synchronized void bump() { 
        static int classCount;
        static synchronized void classBump() {

    It has exactly the same effect as:
    class BumpTest {
        int count;
        void bump() {
            synchronized (this) {
        static int classCount;
        static void classBump() {
            try {
                synchronized (Class.forName("BumpTest")) {
            } catch (ClassNotFoundException e) {

    I assume that since we are dealing with 2 different locks then Class lock will lock all static synch methods and 
    'this' lock will lock all synch instance methods.
Actually we should follow a standard policy here called "Don't Wake The Zombies", basically, rather than wake up a 
5 year old thread. However, if You ask only one synchronized static method can be called at a time. The answer is yes, 
for a given Class, only one synchronized static method can be called at a time. Synchronized static methods of different 
Classes, however, can be called at the same time, because the lock is on different instances of the Class object.


Wednesday, June 23, 2010

Applying Character code in java

Setting Character coding in Java for web applications:

HttpServletRequest request=null;
String charEncoding = "UTF-8"; //Can be taken from some configuration files too.

if(request.getCharacterEncoding() == null)

Thursday, June 17, 2010

Read a properties file inside jar file

Loading a Properties file into a Jar and running Main class from Jar:
//Issue: I have created my jar file. The main class get some configuration value from a *.properties. This file is contained into jar archive,
but when I run my application, I receive this error: "FileNotFoundException". Here properties file is a member of Jar file only.
//Package structure like:

Jar File->com/*.class

//build.xml, for creating jar file

//Java Code, loading properties file in java code
//Main class, main method
InputStream is;
Properties myProp=new Properties();
try {
is = getClass().getResourceAsStream("/smpp/");
System.out.println("Size of file :"+is.available());

//Here FileInputStream will not work as that is usable only for plain files, not for members inside a jar.
(It works in eclipse, because eclipse loads from the plain files, not from your jar file.)

//Running Jar:
java -jar HelloTest.jar

Wednesday, June 16, 2010

Java Decompiler software

Link for a good Java Decompiler software:
Software name: JD-GUI

Wednesday, May 26, 2010

java.lang.RuntimeException: Installation Problem??? Couldn't load messages: Can't find bundle

Weblogic 9.2 and Eclipse environment:-

java.lang.RuntimeException: Installation Problem??? Couldn't load messages: Can't find bundle for base name com.bea.xbean.regex.message, locale en_US
at com.bea.xbean.regex.RegexParser.setLocale(
at com.bea.xbean.regex.RegexParser.(
at com.bea.xbean.regex.ParserForXMLSchema.(
at com.bea.xbean.regex.RegularExpression.setPattern(

//Remove xbean_bea.jar and xbean.jar from classpath, it will definitely work.

ERROR - Digester.getParser(789) | Digester.getParser:
java.lang.UnsupportedOperationException: This parser does not support specification "null" version "null"
at javax.xml.parsers.SAXParserFactory.setXIncludeAware(
at org.apache.commons.digester.Digester.getFactory(
at org.apache.commons.digester.Digester.getParser(
at org.apache.commons.digester.Digester.getXMLReader(
at org.apache.commons.digester.Digester.parse(
at org.apache.struts.action.ActionServlet.initServlet(

//Replace xcersesImpl.jar and Exchange the position of Commons-Digester.jar with Commons-Digester2.0.jar

//Error: slf4j... Trace method not found
There are two log4j jar files, remove older one.

Caused by: com.ewp.core.exceptions.DataNotInitializedException: ProgramProgfile data is not initialzed. Intialize the data using 'loadProgramProfileTree' before trying this

at com.ewp.core.progprof.ProgramProfileLoader.getProgramProfile(
at com.ewp.core.progprof.ProgramProfileHelper.getProgramProfileById(

//Replace ServiceGateway.ear with another one.

java.lang.NoSuchMethodError: unpackEncodedString
at org.drools.lang.DRLParser.(
at org.drools.compiler.DrlParser.getParser(
at org.drools.compiler.DrlParser.parse(
at org.drools.compiler.PackageBuilder.addPackageFromDrl(
at com.ewp.rules.DroolsRulesLoader.buildPackage(
at com.ewp.rules.DroolsRulesLoader.loadAllRules(
at com.ewp.rules.RulesFactory.initializeRules(
at com.ewp.rules.RulesFactory.initRules(
at com.ewp.rules.RulesFactory.init(
at com.ewp.rules.RulesFactory.getRuleFactory(
at com.ewp.rules.RuleHandle.getRules(

//Remove antlr-3.0ea8.jar from classpath