Saturday, October 03, 2009

Ways by which singleton can be created

Singleton classes can be created in 3 ways

Case 1:

package org.vijayan.sample;

public class Singleton {

/**
* Advanced Initialization
*/
public static final Singleton SINGLETON=new Singleton();
private Singleton(){
}

public static void main(String[] args) {
for(int i=0;i<4;i++){
System.out.println(Singleton.SINGLETON);
}
}
}


In this case the statically created object is made final and publicly exposed to everyone.

Case 2:


package org.vijayan.sample;

public class Singleton {

/**
* Advanced Initialization
*/
private static Singleton singleton=new Singleton();
private Singleton(){
}
public static Singleton getInstance(){
return singleton;
}
public static void main(String[] args) {
for(int i=0;i<4;i++){
System.out.println(Singleton.getInstance());
}
}
}


Case 3:


package org.vijayan.sample;

public class Singleton {

/**
* Lazy Initialization
*/
private static Singleton singleton=null;
private Singleton(){
}

public static Singleton getInstance(){
if(singleton==null){
singleton=new Singleton();
}
return singleton;
}

public static void main(String[] args) {
for(int i=0;i<4;i++){
System.out.println(Singleton.getInstance());
}
}
}


In this third case is preferable because it creates the object on-demand. But it can create issue when it is used in multi threaded environment.

So the code can be changed to case 4

Case 4:


package org.vijayan.sample;

public class Singleton {

/**
* Lazy Initialization
*/
private static Singleton singleton=null;
private Singleton(){
}
/**
*
* Will take care multi threaded environment but it expensive
*/
public static synchronized Singleton getInstance(){
if(singleton==null){
singleton=new Singleton();
}
return singleton;
}
public static void main(String[] args) {
for(int i=0;i<4;i++){
System.out.println(Singleton.getInstance());
}
}
}


Though it takes care multi threaded this will become a costly method. to make it a light-weight we can change the code to case 5

Case 5:


package org.vijayan.sample;

public class Singleton {

/**
* Lazy Initialization
*/
private static Singleton singleton=null;
private Singleton(){
}
/**
*
* Will take care multithreaded environment also less expensive
*/
public static Singleton getInstance(){
if(singleton==null){
synchronized (Singleton.class) {
if(singleton==null){
singleton=new Singleton();
}
}
}
return singleton;
}

public static void main(String[] args) {
for(int i=0;i<4;i++){
System.out.println(Singleton.getInstance());
}
}

}


This method is an efficient but complex one, this is also called as double-null checking method. more info on this can be found in http://en.wikipedia.org/wiki/Double-checked_locking

Output:

org.vijayan.sample.Singleton@10b62c9
org.vijayan.sample.Singleton@10b62c9
org.vijayan.sample.Singleton@10b62c9
org.vijayan.sample.Singleton@10b62c9

Please note all 4 times it returns the same object reference.

Synchronization usecases

Consider a class called A, it has m1() and m2() methods, 2 instance of this A class is created a1 and a2 and there are 2 threads t1, t2

Case 1: m1() and m2() are not synchronized

t1 uses a1 and calls m1()

t2 uses a2 and calls m2()

both thread t1 and t2 can run at the same time because both threads are using different objects.

Case 2: m1() and m2() are synchronized

t1 uses a1 and calls m1()

t2 uses a2 and calls m2()

both thread t1 and t2 can run at the same time because both threads are using different objects.
by default synchronization will acquire lock on the object, since here both are using different object locking will not happen.

Case 3: m1() and m2() are synchronized

t1 uses a1 and calls m1()

t2 uses a1 and calls m2()

both thread t1 and t2 cannot run at the same time because both threads are using same object.
if t1 first access m1() then t2 will have to wait for t1 to complete running m1()

Case 4: m1() is static and m2() is non static and both are synchronized

t1 uses a1 and calls m1()

t2 uses a1 and calls m2()

both thread t1 and t2 can run at the same time because though both threads are using same object when t1 first access m1() it is not accessing via a1 object rather it will use A class for accessing the static method that is A.m1() is what called. For doing the same A.Class object will be created and it will be synchronized using A.Class object and t2 will be using a1 object for locking since both objects are different they can work parallel.

Case 5: m1() is static and m2() is static and both are synchronized

t1 uses a1 and calls m1()

t2 uses a1 and calls m2()

both thread t1 and t2 cannot run at the same time because though both threads are using same object (A.Class object)

Why synchronization in java?

Consider the following programs

package org.vijayan.sample;

public class Main {

public static void main(String[] args) {
SampleFile file=new SampleFile("test.txt");
FileWriterThread mt1=new FileWriterThread(10000,"MT1", file);
FileWriterThread mt2=new FileWriterThread(20,"MT2", file);
mt1.start();
mt2.start();
}

}

package org.vijayan.sample;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public class SampleFile {

private File file;
public SampleFile(String fileName){
file=new File(fileName);
file.delete();
}
public void writeMessage(int count, String message){
try {
FileWriter writer=new FileWriter(file,true);
for(int i=0;i
writer.write(message+"-"+i);
writer.write("\n");
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

package org.vijayan.sample;

public class FileWriterThread extends Thread {

private SampleFile file;
private int count;
public FileWriterThread(int count, String name, SampleFile math){
super(name);
this.file=math;
this.count=count;
}
@Override
public void run() {
file.writeMessage(count, getName());
}
}

Output of the above program can result

MT1-1026
MT1-1027
MT1-1028
MT1-1029
MT1-1030
MT1-1031
MT1-1032
MT1-1MT2-0
MT2-1
MT2-2
MT2-3
MT2-4
MT2-5
MT2-6
MT2-7
MT2-8
MT2-9
MT2-10
MT2-11
MT2-12
MT2-13
MT2-14
MT2-15
MT2-16
MT2-17
MT2-18
MT2-19
033
MT1-1034
MT1-1035
MT1-1036
MT1-1037

Please note the bold lines carefully. In this case both thread is using same SampleFile Object and both thread is writing to a same file concurrently. Since there is no synchronized keyword for writeMessae() it is possible. if we make this method synchronized like below

public synchronized void writeMessage(int count, String message){
try {
FileWriter writer=new FileWriter(file,true);
for(int i=0;i
writer.write(message+"-"+i);
writer.write("\n");
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}

then the output will change to like the following

MT1-9994
MT1-9995
MT1-9996
MT1-9997
MT1-9998
MT1-9999
MT2-0
MT2-1
MT2-2
MT2-3
MT2-4
MT2-5
MT2-6
MT2-7
MT2-8
MT2-9
MT2-10
MT2-11
MT2-12
MT2-13

Output 2 indicates that though both thread is started running the second thread is waiting until first thread completes its operation. though it is providing desired output we may not want to make the second thread wait until full completion of thread 1. This can be achieved by changing the program to following ways.


package org.vijayan.sample;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public class SampleFile {

private FileWriter writer;
public SampleFile(String fileName){
File file=new File(fileName);
file.delete();
try {
writer=new FileWriter(file,true);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
writer.close();
}
public void writeMessage(int count, String message){
try {
for(int i=0;i
synchronized (writer) {
writer.write(message+"-"+i);
writer.write("\n");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Output:

MT1-1218
MT1-1219
MT2-0
MT2-1
MT2-2
MT2-3
MT2-4
MT2-5
MT2-6
MT2-7
MT2-8

Please note adding a synchronized block requires some extra code and it always needs to be done carefully.

Monday, September 14, 2009

equals(), hashCode() and toString() methods in Object


//hashCode in Object class

public native int hashCode();

//Java doc for hashCode()

int java.lang.Object.hashCode()


Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

* Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
* If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
* It is not required that if two objects are unequal according to the java.lang.Object.equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

//equals() method in Object class
public boolean equals(Object obj) {
return (this == obj);
}


package object;

public class User {

private String firstName;
private String lastName;
private Integer mark;
public User(String firstName,String lastName, Integer mark){
setFirstName(firstName);
setLastName(lastName);
setMark(mark);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getMark() {
return mark;
}
public Integer setMark(Integer mark) {
this.mark = mark;
}
}


package object;

public class ObjectTest {

public static void main(String[] args) {
User user1=new User("Vijayan", "Srinivasan", new Integer(100));
User user2=new User("Vijayan", "Srinivasan", new Integer(100));
System.out.println("[user1==user2]="+(user1==user2));
System.out.println("[user1.equals(user2)]="+user1.equals(user2));
}
}


So both case it is giving false becasue, both of the statements uses the same logic to compare 2 objects. For getting this right we have to do the following.

//Override equals() method in User class

public boolean equals(Object object) {
if(object instanceof User){
User user=(User) object;
return
equals(firstName,user.firstName) &&
equals(lastName,user.lastName) &&
equals(mark,user.mark);
}
return false;
}

// Implementation of toString() in Object class
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}


Although it is sufficient that overriding equals methods alone sufficient here it is adviced to override also for better performance. //Why?


// implementation of put() method in Hashtable class

public Object put(Object key, Object value) {
// Make sure the value is not null
if (value == null) throw new NullPointerException();

// Makes sure the key is not already in the hashtable.
HashtableEntry e;
HashtableEntry tab[] = table;
int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length;

for (e = tab[index] ; e != null ; e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) { //<------ Look here
Object old = e.value;
e.value = value;
return old;
}
}


Please note if we have proper hashCode() impelentation there is no need of calling the equals() method at all. Hence if the object is different we can let the Hashtable know ahead of calling equals() method. That is the reason it is always important to implement hashCode() when ever we override the equals()

Wednesday, September 09, 2009

Seting gnome on Linux VNC server

In redhat linux, when we start VNC server, by default it used to start with a simple termial based view. Inorder to start it as gnome based session the following command can be used

  1. Set the vnc session as gnome
    > vi ~/.vnc/xstartup (remove all the lines and add only the following lines)
    unset SESSION_MANAGER
    vncconfig -iconic &
    gnome-session &
  2. Start VNC server
  3. > vncserver - geometry 1024x768
Use the correct ip address and X-display id to connect to the VNC e.g. 10.66.92.127:1

Monday, September 07, 2009

Visio type tool on SAAS

Most of would have used Microsoft Visio for creating various diagrams such as Class, Network, Flowchart etc., Here is a tool that does everything online ( http://creately.com/ ). This tool has developed in Flex also allows us to save and collaborate among team members.

Thursday, August 20, 2009

Jboss JDBC Driver Loading Issue

If we configure data source throug *-ds.xml (e.g. mysql-ds.xml) file in Jboss and the corresponding JDBC driver jar is only available in a WEB-INF/lib folder of an application, even though the same application tries to get a connection through configured data source, first time it will throw an ClassNotFoundException. As the class would not have loaded until the first call.

But if we try to get connection second time it will work with out any exception. This problem can be rectifed by keeping the copy of the JDBC driver jar in /server//lib folder (e.g. c:\jboss 4.0.2 \server\default\lib). This will ensure that the driver jar will be loaded in to ClassLoader at the time of server starting.

Monday, August 17, 2009

Incorrect arguments to mysql_stmt_execute

When we use MySQL connector mysql-connector-java-5.0.4-bin.jar with PreparedStatement contains more number of columns we may get the following Exception
java.sql.SQLException: Incorrect arguments to mysql_stmt_execute
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)

To fix this issue we have to use mysql-connector-java-5.1.8-bin.jar

Tuesday, June 30, 2009

Observer and Observable Example

In Java we have Observer interface and Observable class, Below program gives a sample use of Observer and Observable

import java.util.Observable;

public class Employee extends Observable {
float salary;

public void setSalary(float newSalary) {
salary = newSalary; // salary has changed
setChanged(); // mark that this object has changed, MANDATORY
notifyObservers(new Float(salary)); // notify all observers, MANDATORY
}
}

import java.util.Observable;
import java.util.Observer;

public class Manager implements Observer {

public void update(Observable obj, Object arg) {
System.out.println("A change has happened and new salary is " + arg);
}
}


public class Demo {
public static void main(String[] args) {
Employee e = new Employee();
Manager m = new Manager();
e.addObserver(m); // register for observing
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if (i == 5) {
e.setSalary(100);
}
}
}
}

அழகாக தெரிகிறது தமிழ்...

உனக்கு வாழ்த்து
எழுதும்போது மட்டும்
அத்தனை அழகாக
தெரிகிறது தமிழ்...

உன் பெயரை
உச்சரிக்கும்போது மட்டும்
சுகமாக ஒலிக்கிறது
என் குரல்...

என்னோடு நீ
இருக்கும்போது மட்டும்
சொர்க்கமாக தெரிகிறது
இந்த உலகம்...

என்னோடு நீ
நடக்கும்போது மட்டும்
சிறியதாக குறைகிறது
சாலையின் நீளம்...

மொத்தத்தில் உனக்காக
இந்த வாழ்த்து மடல்
எழுதுவதில் என் மனம்
சந்தோசத்தில் நிறைகிறது...

இனிய பிறந்தநாள்
வாழ்த்துக்கள்!!!

விஜயன் சீனிவாசன்

Monday, June 29, 2009

Reading CSV Files Using csvjava 2.0

Recently I have gone through a new CSV Reader called csvjava 2.0 It is a very simple tool which has only 2 classes CSVReader and CSVWritter but yet very powerful. Below I have wrote one sample program using CSVReader class of csvjava 2.0.

This CSV Reader supports all escapping that has been supported by CSV file format.

e.g.
Hi Vijayan This is a Test,"""Simple Test with , and """,A,B,CV
Will be treated as follows
Column 1: Hi Vijayan This is a Test
Column 2: "Simple Test with , and ""
Column 3: A
Column 4: B
Column 5: CV

import java.io.FileNotFoundException;
import java.io.IOException;

import com.csvreader.CsvReader;


public class CSVReaderSample {

public static void main(String[] args) {
try {
CsvReader reader=new CsvReader("Vijayan.csv");

while(reader.readRecord()){
System.out.print(reader.getCurrentRecord()+")");
System.out.print(reader.get(0));
System.out.print("\t");
System.out.print(reader.get(1));
System.out.print("\t");
System.out.print(reader.get(2));
System.out.print("\t");
System.out.print(reader.get(3));
System.out.print("\t");
System.out.println(reader.get(4));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Friday, June 26, 2009

Java FTP Sample Code

Writing FTP Code using ANT is very simple compare to we write the same using FTPClient class. This post will explain you how to do basic FTP operation through ANT FTP task classes.

import java.io.File;

import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.optional.net.FTP;
import org.apache.tools.ant.types.FileSet;

public class FtpUsingAnt {

public static void main(String[] args) {
ftpGetSample();
ftpDeleteTaskSample();
}


public static void ftpGetSample(){
FTP ftp=new FTP();
FTP.Action action=new FTP.Action();
action.setValue("get");
ftp.setAction(action);
ftp.setServer("server.com");
ftp.setUserid("user-name");
ftp.setPassword("password");
ftp.setRemotedir("/remote-folder");
FileSet fileSet=new FileSet();
File dir=new File("c:\\local-folder");
fileSet.setDir(dir);
fileSet.setIncludes("**/*.csv");
ftp.addFileset(fileSet);
callAntTask(ftp, "ftp");
}


public static void ftpDeleteTaskSample() {
FTP ftp=new FTP();
FTP.Action action=new FTP.Action();
action.setValue("del");
ftp.setAction(action);
ftp.setServer("server.com");
ftp.setUserid("user-name");
ftp.setPassword("password");
ftp.setRemotedir("/remote-folder");
FileSet fileSet=new FileSet();
File dir=new File("."); // Not Needed
fileSet.setDir(dir);
fileSet.setIncludes("**/*.csv");
ftp.addFileset(fileSet);
callAntTask(ftp, "ftp");
}


public static void callAntTask(Task task, String taskName){
DefaultLogger logger=new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_DEBUG);
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);

Project project=new Project();
project.addBuildListener(logger);
task.setProject(project);
task.setTaskName(taskName);
task.execute();
}

}

Monday, June 22, 2009

How Class.forName() registers driver?

Most of the time for registering driver to DriverManager, we use the following code.

Class.forName("com.mysql.jdbc.Driver");

But Class.forName() method will not do any registration of Driver with DriverManager. If that is the case how DriverManager.registerDriver() (registration) is called?

static {

try {
java.sql.DriverManager.registerDriver(new Driver());
} catch (java.sql.SQLException E) {
throw new RuntimeException("Can't register driver!");
}

}

This is snippet is taken from com.mysql.jdbc.Driver class's source code. So if you closely watch this code, when ever
 Class.forName("com.mysql.jdbc.Driver");
is invoked as soon as the class is loaded in to the memory, all static blocks of that classes are also being invoked. Insite one of the static block all driver classes are registering them self to DriverManager.

Thursday, June 18, 2009

வட்டத்தின் இரு புள்ளிகள்

நீயும் நானும்
வட்டத்தின் இரு புள்ளிகள்...
நான் சென்னையிலும்,
நீ பெங்களுரிலும் இருந்தபோது,
விட்டத்தின் இரு முனைகளில்
ஆளுக்கு ஒன்றாய் நின்றோம்...

நான் அமெரிக்கா சென்றவுடன்
நீ விட்டத்தின் முனையிலிருந்து
வட்டதின் மையத்திற்கு
இடம்பெயர் ந்தாய்...

நானும் பெங்களூர் வந்தவுடன்
என்னையும் ஈர்த்துக்கொண்டாய்
வட்டத்தின் மையத்திற்கு...

என்றுதான் இத்தனைநாள்
நினைத்திருந்தேன், அனால்
இன்றுதான் உணர்கிறேன்
நீ இருக்கும் இடத்திலேயே
இருந்துகொண்டு வெற்றிடங்கள்
அனைத்தையும்
உன் நட்புப் புள்ளிகளாலும்,
அன்புப் புள்ளிகளாலும்,
நிறப்பி இருக்கிறாய் என்று...

இனிய பிறந்தநாள்
நல்வாழ்த்துகள்!!!

அன்புடன்,
விஜயன் சீனிவாசன்

உனக்கும் எனக்கும்

உனக்கும் எனக்கும்
எத்தனையோ நண்பர்கள்
நம் அறிமுகத்திற்கு
முன்னறும் பின்னறும் ...

இருப்பினும்
நமது நட்ப்பில் மட்டும்
வித்தியாசத்தை உணர்கிறோம்
நீயும் நானும்...

இடையில் எத்தனையோ
எற்றங்கள் இறகங்கள்...
இருப்பினும்
எதுவும் மாறவில்லை,
நம் இருவருக்கும்
இடையில்...

என்ன தவம் செய்தேனென
தெரியவில்லை எனக்கு...
எததனையோமுறை கேட்டும்
சொல்லத் தெரியவில்லை உனக்கு...

ஒன்று மட்டும்
என்மனம் திரும்ப திரும்ப
என்னிடம் சொல்கிறது,
உன் நட்ப்புமட்டுமே
என்னை
ஒவ்வொரு நொடியும்
சுவாசிக்கவைக்கிறது....


என் மனமாற்ந்த நன்றிகள்
உன் பிறந்தநாளுக்கு...

இதையெல்லாம்
உன்னிடம் சொல்ல
எனக்கு ஒரு வாய்ப்பு
தந்ததற்க்கு....

இனிய பிறந்தநாள் வாழ்த்துக்கள்!!!

நட்புடன்,
விஜயன் சீனிவாசன்

என் இரவுகள்...

என் கனவுகளின்
தொழிற்சாலை
நீ

ஒவ்வொரு நாளும்,
அலுவலகம் விட்டு
வரும் போதும்
இன்னுமொரு
தொழிற்சாலையில் தான்
அடியெடுத்துவைக்கிறேன்.

சில மணிதுளிகள்
அன்றைய நிகழ்வுகளை
வெள்ளோட்டம் விடுவேன்
என் விழித்திரையில்.

பின்னர் தலையணை
கட்டியணைத்து...
கனவுத் தொழிற்சாலைக்குள்
மெல்ல மெல்ல நடந்து செல்வேன்...

நீ அன்று அன்போடு
வழியனுப்பி வைத்திருந்தாள்...

மாறாக,
வீடு சேர்ந்த
சில நொடிக்கெல்லாம்,
தலையணை நனைத்திருப்பேன்...
என் கண்ணீர் துளிகளால்...
நீ ஏதோ ஏசியிருந்தால்...

இப்படித்தான் நகர்கின்றன
என் இரவுகள்..

உன் நினைவுகளோடு,
விஜயன் சீனிவாசன்.

திருடி வைத்திருக்கிறேன்

உனக்காக
ஒரே முறையில்
ஒரு கவிதை
எழுதியதாக
நினைவில்லை

ஒரு நாளும்
விடுபட்ட அழைப்பு
கொடுக்காமல்
என் விழிகள்
உறக்கம்
கொண்டதாக
நியாபகம் இல்லை

இதுவரையில்
விடிந்த உடன்
உன் காலை வணக்க
குறுந்தகவல் தேட மறந்ததில்லை

தினம் தினம்
இப்படி எததனையோ
என் செயல்கள்
அணிச்சை செயல்களாக
அரும்பிக் கொண்டுள்ளன...

உன் கூந்தல் ஏறி
உதிர்ந்த பூக்கள்
எதையும்
எடுத்து வைத்து
இருக்கவில்லை நான் ...

கடைசியாக
நீ என்னை
சந்தித்த போது
கைது செய்யவில்லை
காற்றிலே
கலந்திருந்த
உன் முகப்பூச்சு
வாசணையை

ஆனாலும்
ஒன்றை மட்டும்
திருடி வைத்திருக்கிறேன்...
அது உன் இதயம்...

எங்கே வைத்திருக்கிறேன்?
என்று மட்டும்
கேட்காதே?
ஏனென்றால்
வைத்திருந்த இடத்தை
தேடதான் திருடி
இருக்கிறேன் உன்
இதயத்தை!!!

உன்னிடம் சொல்ல சொன்னார்...

இறைவா இன்னுமா
இரக்கம் வரவில்லை
உன்னக்கு?

என்னவளை இன்னும்
எத்தனை தோல்வி படிகளை
ஏற சொல்லுவாய்?
என்றேன் இறைவனிடம்...

கவலை கொல்லாதே
கண்மணியே...
நிச்சயம் ஒருநாள்
தோல்வி படிகள்
முடிந்திருக்கும்...

அன்று
நீ நிற்கும் உயரம்
அனைவரையும்
அயரவைக்கும்...
என்று சொல்ல
சொன்னார் உன்னிடம்...

உனக்காகவே,
விஜயன் சீனிவாசன்

இதோ பிறக்கப் போகிறது

இதோ
பிறக்கப் போகிறது
ஒரு பூவின்
பிறந்தநாள்
இன்னும்
சில மணிநேரத்தில்...

வாழ்த்து மடல்
தயாரிக்க
ஏதேதோ எழுதி
வாசித்துப் பார்த்தேன்...
எதுவும் ஒலிக்கவில்லை
உன் பெயரை
விட சிறப்பாக ...

இருந்தும்
இதோ
ஒரு சில வரிகள்
உனக்காகவே ...

இதுவரை
இல்லாத வகையில்
இனிதே துவங்கட்டும்
இந்த பிறந்தநாள் ...

எட்டாத
உயரத்தை
இனி எட்டட்டும்
உன் முயற்சிகள்யாவும் ...

என்ற வாழ்த்துகளுடன்
நிறைவு செய்ய
நினைத்தேன் ...

ரோஜாவை மட்டும்
வாழ்த்திவிட்டு ...
தோட்டக் காரர்களை
மறந்த உணர்வோடு ...
மீண்டும் தொடர்கிறேன் ...

உன் பெற்றோருக்கும்
வாழ்த்து சொல்ல ...

வாழ்த்த வயதில்லை
என்றாலும்,
நன்றிகலந்த வணக்கத்தை
தெரிவிக்க விரும்புகிறேன்..

உன்னை தோழியாக
தந்ததனால்…

இனிய பிறந்தநாள் வாழ்த்துகள் !!!
விஜயன் சீனிவாசன்

முதல் பிறந்தநாள் வாழ்த்து

ஏதோ ஒரு மாலை வேளை
Yahoo! Chatல் உன்னை
பதிவு செய்ததாக ஞாபகம்...

Hi! என துவங்கியது
நமது உரையாடல்...

சில நிமிடங்களில் இருந்த
உரையாடல் நீளம்
இப்போது
சில மணி நேரமாக
நீண்டிருகிறது...

சிலரது நட்பை
பெற நாட்கள்
பல தேவைப்படும்...

சிலரது நட்பு
தானாக உருவாகும்...

உருவாக்கிய நட்பக்கட்டிலும்,
உருவாகிய நடப்பை
பெரிதும் மதிப்பவன்- நான்

இந்த வகையில்
உருவாகிய நடப்பு
நம் நட்பு

இதை இன்று
உன் பிறந்தநாளில்
நினைவு கூர்வதில்
நம் நட்பின் ஆழம்
நீள்வதாக உணர்கிறேன்...

இனிய பிறந்தநாள் நல்வாழ்த்துக்கள்...
விஜயன் சீனிவாசன

இப்படித்தான் விடிந்தது இன்று

மெல்ல மெல்ல
இதையத்தை துளையிட
எங்கு கற்றுகொண்டாய்?

ஒவ்வொரு முறை
நீ அனுப்பும்
குறும் தகவல்கள்
என்னை
கொஞ்சம் கொஞ்சமாய்
கரைப்பதை
நீ அறிவாயா?


காற்றில்லாத உலகம்
உன் கனவில்லாத
உறக்கம்
இரண்டிற்கும்
வித்தியாசம்
ஏதும் தெரியவில்லை
எனக்கு.

எப்போதும் சீக்கிரம்
துயிலெழ
மறுக்கும் என் விழிகள்
இன்று
அதிகாலையிலேயே
விழித்துகொண்டது
நீ இல்லாத தூக்கம்
பிடிக்காததால்...

எழுத்தவுடன்
உன் விடுபட்ட
அழைப்பை
கண்டதும்
கலங்கிப்போனது
சந்தோசத்தால்
என் கண்கள்...

சிலமணி துளிகள்
பின்னர் மற்றுமொரு
குறும் தகவல்
ஆசை ஆசையாய்
திறந்தேன் நீ
அனுப்பியிருப்பாயென...

நண்பனின் காலை
வணக்கமது..

இப்படித்தான் விடிந்தது
இன்று எனக்கு..

2007 புத்தாண்டு வாழ்த்துக்கள்

ஏதோ நேற்றுதான்
புத்தாண்டு வாழ்த்து
அனுப்பியதாக நியாபகம்
2006 க்காக...

362 நாட்கள் கடந்துவிட்டது
என்பதே இன்னுமொரு
புத்தாண்டு வரும்போதுதான்
நினைவுக்கு வருகிறது...

இடைப்பட்ட நாட்களில்
எத்தனையோ சோதனைகள்
எத்தனையோ சாதனைகள்
உங்களை சந்த்திதிருக்கலாம்...

இனிவரும் புத்தாண்டில்
உங்களை சந்திக்க
நடுங்கட்டும் சோதனைகள்...
சட்டைப்பை பிடிக்காமல்
சிந்தட்டும் சாதனைகள்...
இவையாவும் மெய்பட
இறைவனும் துணையிருக்க
வாழ்த்துகிறேன்!!!

புத்தாண்டு நல்வாழ்த்துக்கள்!!!

அன்புடன்,
விஜயன் சீனிவாசன்

2006 புத்தாண்டு வாழ்த்துக்கள்

இதுவரை இல்லாத
ஏதோ ஒரு சிறப்பு
இந்த புத்தாண்டில்
இருபதாக உணர்கிறேன்...

முதல் முறையாக
உங்களை வாழ்த்த
ஒரு வாய்ப்பளித்ததால்...

முதல் முறையாக
இருந்தாலும் முழுமையாக
வாழ்த்த விரும்புகிறேன்...

உங்கள் கனவுகள் அனைத்தும்
வரவிருக்கும் நாட்களில்
நனவாக வேண்டுமென்று...

இனிய புத்தாண்டு நல்வாழ்த்துக்கள்!!!

அன்புடன்,
விஜயன் சீனிவாசன்

உன் பிரிவில்


உனக்கு தெரியாத நான்


பொங்கல் திருநாள்


பிரிவில் ஓர் பிறந்தநாள்


நான் மட்டும் தனியாக


நண்பனே...


மாணவியின் பிறந்தநாள்

எவருக்கு தெரியும்
என் அத்தை மகளை
சி மொழியில் பேசவைக்க
என்ற என் நண்பனின் கேள்வியில்
எனக்குள் நீ பிறந்தாய்
எஸ் எஸ் ஐ ஓய்வறையில்....

அன்ன நடையுடன் உன் தோழியும்
பின்னல் ஜடையுடன் நீயும்
ஜன்னல் வழி பார்வையிலே
என்னை விழி நோக்கியதில்
மின்னலென நீ பிறந்தாய்
மறுநாள் வரவேற்பறையில்...

நண்பனின் அறிமுகத்தில்
உறவுப்பெண் நீயல்ல
உன் தோழியென நான் அறிந்தேன்...

நான் அதுவரை
உள்ளத்தில் உற்றெடுத்து
உதட்டுவழி வரமறுத்த
வார்த்தைகளை தாள் திறந்தேன்
மறுபடியும் நீ பிறந்தாய்
பிறிதொருநாள் வகுப்பறையில்....

மூன்றுநாள் விடுமுறையில்
தொலைபேசி சிணுங்கள் வழி
தொலைவரிந்த நொடிப்பொழுதில்
தொகை அறியா முறைவரைக்கும்
தொடராக நீ பிறந்தாய்
சில்லென்று செவிப்பறையில்...


என்னோடு நீ நடந்த
கோவிலின் அடிச்சுவடுகள்,
அஞ்சலாய் நீ அனுப்பிய
அரைசேலை புகைப்படம்,
ஆயிரம்முறை நீ பிறந்தாய்
அனுதினமும் என்கனவறையில்...

இந்தனை பிறப்பை அறிந்த நான்,
ஓர் பிறப்பை மட்டும் அறியேன்.
என்னென்றால் அன்றுவரை நீ
இரகசியமாய் கருவறையில்...

இனிய பிறந்தநாள் வாழ்த்துக்கள்!!!
விஜயன் சீனிவாசன்

கனவுப்பாதை

பள்ளி நாட்களில்
முழு ஆண்டு விடுமுறைக்காக
நாட்களை எண்ணிக்கொண்டிருந்தேன்...

கல்லூரியில் கால்பதித்த காலத்தில்
நல்லதொரு வேலைக்காக
இறுதியாண்டை நோக்கி
வருடங்களை இழுத்துவந்தேன்

இன்று அலுவலகத்திலிருந்துதான்
இதை எழுதுகிறேன்
அடுத்துவரும் செலவுகளை நினைத்து
அடுத்த ஒன்றாம் தேதியை
எதிர்பார்கிறேனேன்று...

என் கனவுப்பதை
கண்முன்னே
கரைவதறியாமல்...

இதே நாள் அன்று...


எதை கேட்பான் ஆண்டவன்?


என் தமிழ் ஆசை


Autograph Book ல்


ஆதிக்க மரங்கள்


Wednesday, June 10, 2009

Automatically Toolbars are added in MS-Outlook

Recently I faced this problem, When ever I used to open a new email in Outlook One more standard toolbar used to added to my toolbar list. which can be removed from the view and cannot be deleted.

To fix this problem I have followed this approach. All the toolbar customizations are stored a file called "outcmd.dat" under C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook. After deleting this file the problem has been fixed.

Tuesday, June 09, 2009

Unzip Using Ant Code


package com.test.ant;

import java.io.File;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;

public class AntUnzip {

public static void main(String[] args) {
File src = new File("1.zip"); // Source Zip File Name
File dest = new File("test"); // Destination Folder Name
Expand expand = new Expand();
expand.setSrc(src);
expand.setDest(dest);
callAntTask(expand, "Unzip");
}

public static void callAntTask(Task task, String taskName) {
DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_DEBUG);
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
Project project = new Project();
project.addBuildListener(logger);
task.setProject(project);
task.setTaskName(taskName);
task.execute();
}

}

ClassNotFoundException vs. NoClassDefFoundError

Many a times we will come across these exceptions, though they look similar there is a clear difference between these two classes.

package com.test;

/**
* @author Vijayan Srinivasan
* @since Sep 22, 2010 9:16:46 PM
*/
public class A {

public void print() {
System.out.println("I am A");
}

}


package com.test;

/**
* @author Vijayan Srinivasan
* @since Sep 22, 2010 9:16:46 PM
*/
public class B {

public static void main(String[] args) {
try {
Class clazz = Class.forName("com.test.A");
A a = (A) clazz.newInstance();
a.print();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}

}


package com.test;

/**
* @author Vijayan Srinivasan
* @since Sep 22, 2010 9:16:46 PM
*/
public class C {

private A a = new A();

public static void main(String[] args) {
new C().a.print();
}

}

First compile all these classes. Once compilation is complete, then run the class B and C
You will get the following output.

C:\Test\bin>java com.test.C
I am A

C:\Test\bin>java com.test.B
I am A

Now delete class A and re-run the classes B & C

C:\Test\bin>java com.test.C
Exception in thread "main" java.lang.NoClassDefFoundError: com/test/A
at com.test.C.(C.java:12)
at com.test.C.main(C.java:15)
Caused by: java.lang.ClassNotFoundException: com.test.A
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 2 more

C:\Test\bin>java com.test.B
java.lang.ClassNotFoundException: com.test.A
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.test.B.main(B.java:15)