Friday, October 29, 2010

List of Tibco RV, EMS Tutorials , Tips from Javarevisited

Hi guys , just thought about some more topics to explain on this tibco tutorial series , let me know out of below which Tibco topics you would like to me cover first , please suggest if you have other topics in mind. I am now updating this post as most of the topics are already covered but I forgot to update this post.

I have covered difference between routing daemon and Tibco daemon in this part. basically main difference between both of them is the purpose. RVD is mainly for sending and receiving message in same network between two Tibco RV publisher and subscriber while RVRD is used to bridge two different network from two different countries, cities or even continent. Most of the investment banks has RVRD bridging there London to New-york traffic or London to Tokyo traffic. Bandwidth of these WAN networks are very important because if  you have just one slow Tibco subscriber that can bring down whole network link between two regions. We had an incident when one of out application is publishing huge amount of updates in MB and on other side we had a GUI on a slow desktop which is keep asking for resend, this problem is often referred as Tibco RV storm and its very serious issue while working with Tibco messaging. One important thing to note here is reliability parameter of tibco rv which actually defines how long publisher should hold the message if set very low can cause frequent retransmission request.

Friday, October 22, 2010

Tibco tutorial : Certified Messagging

This is in continuation of my previous tibco tutorial. tibco rv is most widely used middleware in enterprise world heavily used in banking and many global investment bank rely on tibco rv for there high speed messaging requirement. its used by many trading application to receive high speed data e.g. Market data. in reliable mode tibco provide reliable delivery of data but not guaranteed means if sender sends data to receiver via tibco multicast network , tibco tries best to deliver that data to receiver but there is no guarantee, data could be lost if receiver is too busy to receive it , if receiver is not running or receiver is hang. In some cases its possible to recover lost data by sending "Resend Request".

Tuesday, October 12, 2010

What are builtin Properties in ANT >> Tutorial Example

This is the fourth article of series "ant tutorial for beginners" here I have included some more fundamental concept in form of Q/A to provide you clear and concise description and situation where you apply these concept. Please let me know if you have any questions , comments I will be happy to reply those .

What are built in properties available in ant ?
Built in properties are those which ant provides by default , you need not have to declare these property you can just use it. You can divide them in two parts

Sunday, October 10, 2010

Top 30 Eclipse Keyboard Shortcuts for Java Programmer

This tutorial is about 30 Eclipse keyboard shortcuts, this list is by no means complete and I will suggest you guys to share eclipse shortcuts listed other than here to make this more useful.Eclipse is most used Java development IDE and knowing Eclipse shortcuts not only improve your productivity but also makes you more efficient, you will have more time for things you like to do. Using keyboard shortcuts also helps to impress colleagues and shows that you have good hold on tools you used for Java Development.

Saturday, October 9, 2010

How to write build.xml and run build in Apache ANT

This is the second article on Apache ANT tutorials for beginners series As I have always said that I like short , clear and concise tutorial which tells about few concept but in a clear and concise manner and put weight on fundamentals . I try to adopt same theory while writing my blog post while writing my experience coupled with concept which is important for a software developer point of view.

Friday, October 8, 2010

Hot to build project using Apache ANT ? ANT Build Tutorials for Beginners

Apache Ant tutorials for beginners

Hi Guys, today I would like to share some of my experience while working with ant build tool in form of short ant tutorials, ant is one tool which has gained its place in almost everywhere, it’s integral part of any project’s build system and provide foundation for complex, extensible build environment. I have been using ANT from my early programming days and I have seen some of the best designed build environments around ANT. In these ant tutorials for beginners we will see what is ant build tool? How to use ANT for building project? Fundamentals of ANT build tool, setting up ant build environment etc. I have created a series of ant tutorials and you can check next part of ant tutorials by following links ant tutorial part 2 and ant tutorial part 3

Thursday, October 7, 2010

MySql Tutorial : mysqldump utility in mysql

The mysqldump client is a backup program o It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both. However, mysqldump can also be used to generate files in CSV, other delimited text, or XML format.

MySQL tutorial and commands part 3

Hi Guys , here are some more mysql commands which is useful in day 2 day work.

Method for converting current time stamp to date:
select from_unixtime(left(1201159475416, 10));
this  method is used to convert the timestamp to the date time format in mysql ,left() method will return 10 char from the specified string  if we store time stamp value in millisecond.

Wednesday, October 6, 2010

MySQL tutorial and commands part 2

Here are some more mysql commands from which is very useful for anyone working with mysql database.
this are very useful for application developer which is going to use mysql database for there applications.

Increasing no of connections for mysql
You can increase this value in main config file (e.g., /etc/my.cnf) using this syntax:


Tuesday, October 5, 2010

MySQL tutorial and commands Part 1

Here is first set of my basic mysql commands which I have used in my day to day life while working with mysql database.

For Checking Wheather MySQL Server is running or not
ps -auxwww | grep mysql

Starting mysql
go to mysql installation directory and execute below command

How to use Regular Expression in Unix Linux

-->One of the most powerful tools available to programmers are Regular Expressions, if you are good with regular expressions you can solve many day to day problem extremely quickly e.g. find all the lines with ERROR in log file , find count of any particular ID in log file , find exceptions etc.

Monday, October 4, 2010

Improving Performance of java application

This is a big topic to discuss as there are many approaches which involves to analyze performance of an application starting from profiling application to finding bottleneck.

here I am putting some of the basic tricks for improving performance which I learnt in my early days in java , I will keep posted some approach , experience on performance improvement as and when time allows.

for now here are naive's tips for making your program run faster.

1. Use bit shift operator for multiplying and divide by 2 , computers are very fast with bitwise operation.

2. Use stringbuffer in place of string if you are doing lots of string manipulation it will reduce memory by avoiding creating lots of string garbage. If you are using java5 then consider stringbuilder but that is not synchronized so beware.

3. try to make variable , class , method final whenever possible that’s allow compiler to do lots of optimization e.g. compile time binding so you will get faster output.

4. static methods are bonded compile time while non static methods are resolved at runtime based on object type so static method will be faster than non static.

5. don't call methods in for loop for checking condition e.g. length() size() etc.
instead of doing this , use modified version

for(int i=0; i<vector.size();i++)

int size = vector.size();
for(int i=0; i<size;i++) 

if you like to know about FIX protocol and its usage in Electronic trading or Derivatives trading e.g. Futures and options , foreign exchange and other asset class , Please see my FIX Protocol Tutorials series. I have shared my experience in investment banking and finance domain as form of short tutorial and could be used as start guide for any one new in FIX protocol and can compliment official FIX Protocol Technical specification in simple words.

If you are going for any FIX Protocol Job Interview you can quickly benefit from my FIX Protocol Interview Questions, those are questions mostly asked in Interview for a FIX developer position. It not just help in as quick reference for Interview but also opens new area of learning for new comers.

hope this would be useful.

Networking Basics for FIX Connection in Unix Linux

Knowledge of networking basics are extremely important if you are dealing with FIX connection , FIX stands for Financial Information Exchange protocol and its the most popular protocol for electronic trading and supported by many brokers , exchanges etc.

here I am discussing few important network related information which is quite useful for FIX connection establishment.

Sunday, October 3, 2010

How to avoid deadlock in Java Threads

How to avoid deadlock in Java is one of the question which is flavor of the season for multithreading , asked more at a senior level and with lots of follow up questions , though question looks very basic but most of developer get stuck once you start going deep.

questions starts with "What is deadlock ?"
answer is simple , when two or more threads waiting for each other to release lock and get stuck for infinite time , situation is called deadlock . it will only happen in case of multitasking.

Top 10 Most useful cvs commands in linux/unix

This article is in continuation of my earlier article Top 10 basic networking Commands in Unix  and 10 tips of working fast in unix  to read more see here 10 tips of using find command in linux.

Here is my list of most useful commands in Linux , its important that we know this and use it regularly while working with files folders which is in CVS.

Top 10 basic networking commands in linux/unix

Networking is an essential part Unix and it offer lots of tools and command to diagnose any networking problem. When I was working on FIX Protocol we get lot of support queries to see whether FIX Sessions are connected or not. Since FIX Protocol uses sockets you can use net stat , telnet and other networking command available in Linux for finding problem and solve that.In this article I will show you basic networking commands in Unix and for what purpose they are used. with the combination of grep and find command on them you can troubleshoot most of networking problem.

Saturday, October 2, 2010

Tibco tutorial : Tibco RV tips and commands

This is third post on series of "tibco tutorial" , In this article I am posting some of the most useful command which I used while working in tibco rv in many application , they are extremely useful and must be in developers top of head who is working in tibco rv.

Before writing these "tibco tutorial" series I looked for some introductory simple tibco tutorial which explains concept of tibco rv in simple word and give us working knowledge of tibco but I did not found any. tibco is most heavily used middleware solution on enterprise world and form backbone of many large enterprise including global banks.

Tibco Tutorial: Fundamentals of Tibco RV messagging.

This is in continuation of my  tibco tutorial series where I will discuss tibco rv on application developer point of view as middle ware or messaging solution.As discussed in earlier tibco tutorials, tibco is used for communicating between two systems e.g. client and server or server to server , here we will see some of the basic terms used in tibco rv  world.

TIBCO Tutorial : TIBCO Rendezvous or TIBCO RV messaging

TIBCO Tutorial:  TIBCO RV messaging
When I started working with a big investment bank I come across a new messaging technology called TIBCO Rendezvous or commonly called as TIBCO RV, I have heard Java Messaging Service (JMS) before but never heard about this TIBCO Rendezvous and it was so extensively used in my application that most of support issue was caused by this mysterious TIBCO RV. We had several TIBCO Topics also called TIBCO Subject separate for both Production and Non PRODUCTION environment but still since I don’t had basic knowledge of this technology I was afraid to do some experiment because there was always a risk to affect production environment.
At that time I have searched for TIBCO tutorial and I didn't find anything which can help an application developer who wants to use TIBCO as middleware solution, so I decided to write my own experience in a form of short , concise and clear  TIBCO tutorial  Every post of this series will have something to offer in a short and clear format which I like and I hope you too for details you can always refer to TIBCO Rendezvous or TIBCO EMS specification or documentation .

What is Abstraction in java - Java abstraction tutorial and example

What is abstraction ?
Abstraction in Java or Object oriented programming is a way to segregate implementation from interface and one of the five fundamentals along with Encapsulation, Inheritance, Polymorphism, Class and Object.  Abstraction in Java is achieved by  using interface and abstract class in Java. An interface or abstract class is something which is not concrete , something which is incomplete. In order to use interface or abstract class we need to extend and implement abstract method with concrete behavior. One example of Abstraction is creating interface to denote common behavior without specifying any details about how that behavior works e.g. You create an interface called Server which has start() and stop() method. This is called abstraction of Server because every server should have way to start and stop and details may differ. As I said earlier Abstraction in Java is implemented using abstract class and interface as discussed in next section. In fact What is abstraction in Java, Difference between Abstraction and Encapsulation  is also a very popular core Java interview because strong OOPS skill is one of the primary requirement for Java developers.

Fundamentals of Object Oriented Programming in Java

I remember when I was doing my engineering , OOPS concept was in first semester. Back then it looks like some alien things to me, because I have never done programming and even the smallest program we get to write e.g. checking whether number is palindrome or not , or printing Fibonacci series , we never really needed to use OOPS. When needed, I just memorize things and written down in exam :). That worked, I passed the exam but effectively I didn't learn OOPS or Object Oriented Programming on those days.

It's when, I started learning java (an almost truly object oriented programming language) and introduced to concept like abstract classes, interface, and method overriding; some thing started to going in my mind. This blog post is very basic in nature, but I really hope it could help beginners on understanding things like class, objects, abstraction , polymorphism, inheritance ,encapsulation , composition , cohesion , coupling , interface programming etc.

What is the difference between Enumeration and Iterator ?

What are differences between Enumeration and Iterator  This question is from early ages of interview , I have not seen this question on recent interviews but it was common during 2006-2007 , now days questions like implementation of HashMap, ConcurrentHashMap etc has take its place, nonetheless its very useful to know fundamental difference between Iterator and Enumeration. Some time its also asked as  Iterator vs Enumeration or Enumeration vs Iterator which is same. important point to note is that both Iterator and Enumeration provides way to traverse or navigate through entire collection in java

Difference between HashMap and HashTable? Can we make hashmap synchronized?

HashMap vs Hashtable in Java
Difference between HashMap and Hashtable in Java question oftenly asked in core Java interviews to check whether candidate understand correct usage of collection classes and aware of alternative solutions available. Along with How HashMap internally works in Java and ArrayList vs Vector, this  is one of the oldest question from Collection framework in Java. Hashtable is a legacy Collection class and it's there in Java API from long time but it got refactored to implement Map interface in Java 4 and from there Hashtable became part of Java Collection framework. Hashtable vs HashMap in Java is so popular a question that it can top any list of Java Collection interview Question. You just can't afford not to prepare HashMap vs Hashtable before going to any Java programming interview. In this Java article we will not only see some important differences between HashMap and Hashtable but also some similarities between these two collection classes. Let's first see How different they are :

What is the difference between Synchronized Collection classes and Concurrent Collection Classes ? When to use what ?

Collections classes are heart of java API though I feel using them judiuously is an art.its my personal experience where I have improved performance by using ArrayList where legacy codes are unnecesarily used Vector etc. JDK 1.5 introduce some good concurrent collections which is highly efficient for high volume , low latency system.

Friday, October 1, 2010

What is the use of class “java.lang.Class” ? why do we need Class.forName() and Class.newInstance() method if we can create object using new()?

java.lang.Class is one of the most important class in java but oftenly overlooked by java developers.

Every time JVM creates an object, it also creates a java.lang.Class object that describes the type of the object.

All instances of the same class share the same Class object and you can obtain the Class object by calling the getClass() method of the object. This method is inherited from java.lang.Object

Suppose you create two instances of class called Person e.g.

Person A = new Person();
Person B = new Person();

if(A.getClass() == B.getClass()){
System.out.println("A and B are instances of same class");
System.out.println("A and B are instances of different class");

In this case it will print "A and B are instances of same class" because they are both instance of clas Person.

We need forName() and newInstance() because many times it happens that we don’t know the name of the class to instantiate while writing code , we may get it from config files ,database , network or from any upstream.

this we called reflective way of creating object which is one of the most powerful feature of java and which makes way for many frameworks e.g. Spring ,Struts which uses java reflection.

What is the problem while using "==" in autoboxing world in Java 5 ?

Some of the JVM cache objects of some wrapper class e.g. Integer from -128 to 127 and return same object which if compare via “ ==” can return true but after this range this validity doesn’t work and to make it worse this behavior is JVM dependented so better avoid this kind of check and use equals() method.


Integer i1 = 260;
Integer i2 = 260;

if (i1 == i2)
System.out.println("i1 and i2 is equal");
System.out.println("i1 and i2 is not equal ");

Here you will most probably get "i1 and i2 is not equal " at least in my machine.
because in this case, unboxing operation is not involved. The literal 260 is boxed into two different Integer objects ( again it varies between JVM to JVM) , and then those objects are compared with ==. The result is false, as the two objects are different instances, with different memory addresses. Because both sides of the == expression contain objects, no unboxing occurs.

Integer i1 = 100;
Integer i2 = 100;

if (i1 == i2)
System.out.println("i1 and i2 is equal");
System.out.println("i1 and i2 is not equal ");

Here, most probably you will get the text "i1 and i2 is equal".
Because int values from -127 to 127 are in a range which most JVM will like to cache so the VM actually uses the same object instance (and therefore memory address) for both i1 and i2. As a result, == returns a true result.

this is very indeterministic and only shown by example since some JVM do optimization at certain integer value and try to return same object every time but its not guaranteed or written behavior.

So best is to avoid this kind of code in post java 1.5 and instead use equals() method to compare which is more deterministic.

How do you find length of a Singly Linked list

Hi Guys,

Here is one of the classical questions asked to me on an interview with multinational Investment bank after that this question asked to me on several times in other interviews also . what makes this question interesting is that java developers are not that great with data structure relative to C++ developer which is obvious because of fundamental difference between this two language.C++ is more of system programming language while java is more on application programming , also rich set of java API allows programmer to skip this kind of basic programming techniques.

How to check if a thread holds lock on a particular object in Java

Think about a scenario where you would have to find at run time that whether a java thread has lock on a particular object e.g. find out whether thread NewsReader has lock on NewsPaper object or not ?

How to check if a thread holds lock in JavaIf this questions came in any core java interview then I would automatically assume that there could be at least two answer one is hard earned raw answer which programmer would like to figure out based on fundamentals and other could be some rarely used API calls which is available in java , by the way this is actually asked to me in an interview of one of the biggest global bank.

Why String is immutable or final in Java

This is one of the most popular String Interview questions in Java, which starts with discussion of,  What is String, How String in Java is different than String in C and C++, and then shifted towards what is immutable object in Java , what are the benefits of immutable object , why do you use it and which scenarios do you use it. This is some time also asked as "Why String is final in Java" . Though there could be many possible answer for this question, and only designer of String class can answer this , I think below two does make sense

1) Imagine StringPool facility without making string immutable , its not possible at all because in case of string pool one string object/literal e.g. "Test" has referenced by many reference variables , so if any one of them change the value others will be automatically gets affected i.e. lets say

String A = "Test"
String B = "Test"

Now String B called "Test".toUpperCase() which change the same object into "TEST" , so A will also be "TEST" which is not desirable.

2)String has been widely used as parameter for many Java classes e.g. for opening network connection, you can pass hostname and port number as string , you can pass database URL as string for opening database connection, you can open any file in Java by passing name of file as argument to File I/O classes.

In case, if String is not immutable, this would lead serious security threat , I mean some one can access to any file for which he has authorization, and then can change the file name either deliberately or accidentally and gain access of those file. Because of immutability, you don't need to worry about those kind of threats. This reason also gel with, Why String is final in Java, by making java.lang.String final, Java designer ensured that no one overrides any behavior of String class.

3)Since String is immutable it can safely shared between many threads ,which is very important for multithreaded programming and to avoid any synchronization issues in Java, Immutability also makes String instance thread-safe in Java, means you don't need to synchronize String operation externally. Another important point to note about String is memory leak caused by SubString, which is not a thread related issues but something to be aware of.

4) Another reason of Why String is immutable in Java is to allow String to cache its hashcode , being immutable String in Java caches its hashcode, and do not calculate every time we call hashcode method of String, which makes it very fast as hashmap key to be used in hashmap in Java.  This one is also suggested by  Jaroslav Sedlacek in comments below. In short because String is immutable, no one can change its contents once created which guarantees hashCode of String to be same on multiple invocation.

5) Another good reason of Why String is immutable in Java suggested by Dan Bergh Johnsson on comments is: The absolutely most important reason that String is immutable is that it is used by the class loading mechanism, and thus have profound and fundamental security aspects. Had String been mutable, a request to load "" could have been changed to load "mil.vogoon.DiskErasingWriter"

Security and String pool being primary reason of making String immutable, I believe there could be some more very convincing reasons as well, Please post those reasons as comments and I will include those on this post. By the way, above reason holds good to answer, another Java interview questions "Why String is final in Java".  Also to be immutable you have to be final, so that your subclass doesn't break immutability.  what do you guys think ?

Few more String related post from Javarevisited, you may like: