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:

classes12.jar
weblogic.jar
xbean_bea.jar

//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://10.200.101.156:7001");

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

System.out.println(dataSource);
}
catch (Exception e) {
e.printStackTrace();
}
}
}

Thursday, December 16, 2010

URL/Link for Advanced Servlets

Link for advanced servlets:
http://www.exforsys.com/tutorials/j2ee/servlets-advanced.html

Hibernate loggers:
http://stackoverflow.com/questions/1380898/how-do-i-get-more-debug-messages-from-hibernate

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:
http://www.citehr.com/2983-employees-provident-fund-form-no-10-c-form-19-a.html

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.

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


---------------END---------------

Thursday, September 2, 2010

Desktop wallpaper sites

Good wallpaper sites:

http://www.vistadesktops.com/resolution.php?page=3&rid=9
http://safa.tv/370,why-the-bodyguards-lose-his-job-super-funny.html
http://www.flash-screen.com/free-wallpaper/

Wednesday, September 1, 2010

IFSC codes of my banks

IFSC Codes:

SBI MG Road- SBIN0005778
UNION Chandra layout- UBIN0556343
United Shivaji nagar- UTBI0SHV823
Yes bank KASTURBA ROAD BANGALORE- YESB0000022
End.

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: STRING ME2
s2: STRING ME2
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));
                
        System.out.println(s1.equals(s2));
        System.out.println(s1.equals(s3));
        System.out.println(s1.equals(s4));
        System.out.println(s1.equals(s5));
    }
}
/////Output:
s1==s2: false
s1==s3: true
s1==s4: false
s1==s5: true
true
true
true
true
----------------------------END--------------------------

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
Url- http://subclipse.tigris.org/update_1.6.x

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

Ration card rules in bangalore

Taken from: http://timesofindia.indiatimes.com/city/bangalore-times/Ration-card-rules/articleshow/16684790.cms

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.

IBM DB2
jdbc:db2://HOST:PORT/DB
COM.ibm.db2.jdbc.app.DB2Driver

JDBC-ODBC Bridge
jdbc:odbc:DB
sun.jdbc.odbc.JdbcOdbcDriver

Microsoft SQL Server
jdbc:weblogic:mssqlserver4:DB@HOST:PORT
weblogic.jdbc.mssqlserver4.Driver

Oracle Thin
jdbc:oracle:thin:@HOST:PORT:SID
oracle.jdbc.driver.OracleDriver

PointBase Embedded Server
jdbc:pointbase://embedded:PORT/DB
com.pointbase.jdbc.jdbcUniversalDriver

Cloudscape
jdbc:cloudscape:DB
COM.cloudscape.core.JDBCDriver

Cloudscape RMI
jdbc:rmi://HOST:PORT/jdbc:cloudscape:DB
RmiJdbc.RJDriver

Firebird (JCA/JDBC Driver)
jdbc:firebirdsql://HOST:PORT/DB
org.firebirdsql.jdbc.FBDriver

Informix Dynamic Server
jdbc:informix-sqli://HOST:PORT/DB:INFORMIXSERVER=SERVER_NAME
com.informix.jdbc.IfxDriver

Hypersonic SQL (v1.2 and earlier)
jdbc:HypersonicSQL:DB
hSql.hDriver

Hypersonic SQL (v1.3 and later)
jdbc:HypersonicSQL:DB
org.hsql.jdbcDriver

Microsoft SQL Server (JTurbo Driver)
jdbc:JTurbo://HOST:PORT/DB
com.ashna.jturbo.driver.Driver

Microsoft SQL Server (Sprinta Driver)
jdbc:inetdae:HOST:PORT?database=DB
com.inet.tds.TdsDriver

Microsoft SQL Server 2000 (Microsoft Driver)
jdbc:microsoft:sqlserver://HOST:PORT;DatabaseName=DB
com.microsoft.sqlserver.jdbc.SQLServerDriver

MySQL (MM.MySQL Driver)
jdbc:mysql://HOST:PORT/DB
org.gjt.mm.mysql.Driver

Oracle OCI 8i
jdbc:oracle:oci8:@SID
oracle.jdbc.driver.OracleDriver

Oracle OCI 9i
jdbc:oracle:oci:@SID
oracle.jdbc.driver.OracleDriver


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: http://www.devx.com/tips/Tip/28818

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 {
   @Override
   public void draw() {
      System.out.println("Rectangle::  draw()");
   }
}

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

public class Circle implements Shape {
   @Override
   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(){
      circle.draw();
   }
   public void drawRectangle(){
      rectangle.draw();
   }
   public void drawSquare(){
      square.draw();
   }
}

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

      shapeMaker.drawCircle();
      shapeMaker.drawRectangle();
      shapeMaker.drawSquare();        
   }
}
Code: https://www.tutorialspoint.com/design_pattern/facade_pattern.htm

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:

http://www.outlookindia.com/article.aspx?265887

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\SMPPConnector.java

//Running your main class, We assume Main class is "SMPPConnector.java" 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
    D:\smpp_new>META-INF\MANIFEST.MF

//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.)
    Main-Class: com.ewp.services.DecryptData

//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?

Answer:
    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):
    
    synchronized(Foo.class){
        synchronized(f){
            // 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() { 
            count++; 
        }
        static int classCount;
        static synchronized void classBump() {
            classCount++;
        }
    }

    It has exactly the same effect as:
    -------------------------
    class BumpTest {
        int count;
        void bump() {
            synchronized (this) {
                count++;
            }
        }
        static int classCount;
        static void classBump() {
            try {
                synchronized (Class.forName("BumpTest")) {
                    classCount++;
                }
            } 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.

-------------------------------------------END------------------------------------------

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)
request.setCharacterEncoding(charEncoding);

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:
com/*.java
smpp/test.propeties

Jar File->com/*.class
->smpp/test.properties


//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/EIF.properties");
myProp.load(is);
}
System.out.println("Size of file :"+is.available());
is.close();

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

http://www.softpedia.com/progDownload/JD-GUI-Download-92540.html

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(RegexParser.java:88)
at com.bea.xbean.regex.RegexParser.(RegexParser.java:78)
at com.bea.xbean.regex.ParserForXMLSchema.(ParserForXMLSchema.java:28)
at com.bea.xbean.regex.RegularExpression.setPattern(RegularExpression.java:2996)

//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(SAXParserFactory.java:390)
at org.apache.commons.digester.Digester.getFactory(Digester.java:534)
at org.apache.commons.digester.Digester.getParser(Digester.java:786)
at org.apache.commons.digester.Digester.getXMLReader(Digester.java:1058)
at org.apache.commons.digester.Digester.parse(Digester.java:1887)
at org.apache.struts.action.ActionServlet.initServlet(ActionServlet.java:1144)

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

operation
at com.ewp.core.progprof.ProgramProfileLoader.getProgramProfile(ProgramProfileLoader.java:162)
at com.ewp.core.progprof.ProgramProfileHelper.getProgramProfileById(ProgramProfileHelper.java:485)
at com.ewp.services.ExceptionHandlerServiceImpl.getErrorMsg(ExceptionHandlerServiceImpl.java:230)

//Replace ServiceGateway.ear with another one.


java.lang.NoSuchMethodError: unpackEncodedString
at org.drools.lang.DRLParser.(DRLParser.java:7325)
at org.drools.compiler.DrlParser.getParser(DrlParser.java:207)
at org.drools.compiler.DrlParser.parse(DrlParser.java:60)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:165)
at com.ewp.rules.DroolsRulesLoader.buildPackage(DroolsRulesLoader.java:155)
at com.ewp.rules.DroolsRulesLoader.loadAllRules(DroolsRulesLoader.java:68)
at com.ewp.rules.RulesFactory.initializeRules(RulesFactory.java:163)
at com.ewp.rules.RulesFactory.initRules(RulesFactory.java:259)
at com.ewp.rules.RulesFactory.init(RulesFactory.java:280)
at com.ewp.rules.RulesFactory.getRuleFactory(RulesFactory.java:406)
at com.ewp.rules.RuleHandle.getRules(RuleHandle.java:89)

//Remove antlr-3.0ea8.jar from classpath