Saturday, June 25, 2011

List of special bash parameter used in Unix or Linux script


Meaning of bash parameter used in Unix script

Many of us use bash script for doing housekeeping and other stuff but occasionally and not much aware of special bash parameters. When I was new to bash shell and Linux and looking on some already written bash script I used to get baffled with special bash symbols like $@, $_, $1 etc. I did know that they are bash parameter and has special meaning but I don't have all meanings of special bash parameter on top of my head and I always go to Google and search endlessly for those special bash parameter, some time I got and found meaning of those special bash script parameters quickly but sometime I need spend some time to get what I am actually looking for, so I thought to document meanings and expansion of those special bash parameters or bash script parameters.

This bash script parameter tutorial is in continuation of my earlier UNIX tutorials find examples in UNIX, grep command examples in UNIX, and UNIX networking commands tutorial if you haven’t read already you may find them interesting and useful.

Thursday, June 23, 2011

3 example of converting array to ArrayList and ArrayList to array in Java program

How to change from array to ArrayList and ArrayList to array in java
Have you encountered any situation where you quickly wanted to convert your array to ArrayList or ArrayList to array ? I have faced many such situations which motivate me to write these quick Java tips about converting array to ArrayList and ArrayList to array in Java. Both array and ArrayList are quite common and every Java developer is familiar with this. Former is used to store object and primitive type while later can only hold objects. Array is part of standard Java  fundamental data structure while ArrayList is part of collection framework in Java. Most of the time we store data in form of object in either Array or ArrayList or sometime we find either of them suitable for processing and we want to convert from one array to ArrayList or ArrayList to array in Java. This short array to ArrayList tutorial in Java will explain how quickly you can convert data from each other. So when you face such situation don't bother just remember this tips and you will get through it. If you compare array vs ArrayList only significant different is one is fixed size while other is not. This article is in continuation of my post Difference between Vector and ArrayList in Java and How to Sort ArrayList in Java on descending order. On related not from Java 5 onwards ArrayList class supports Generics in Java, which means you can convert an ArrayList to String into an String array or ArrayList of Integer into an Integer Array. Generics provides type safety and remove casting during runtime.

Monday, June 20, 2011

10 example of using Vim or VI editor in UNIX and Linux


Vim or VI editor tutorial in UNIX

vi editor in unixVI Editor is like notepad in UNIX but it’s extremely powerful and have sophisticated feature to work as complete IDE. No matter which version of UNIX you are working or which flavor you are using you always find either VI editor or VIM there. VI is a very large topic and I am not covering every aspect of it what I am sharing here is some examples of using VI editor in UNIX or Linux. most of the time we use only 10% of VI editor and never know 90% of it , to be frank I also don't know many of VI feature by heart but I always search for it , see people working in VI and learn from there experience as well. after working on VI editor what I found that every day we learn something new in VI editor but we  forget something equally important and there I thought lets document whatever VI commands I have learned so far and using regularly. Idea is to keep this VI Editor tutorial updated with every single useful VI commands I learn and I also ask you guys to contribute with something useful. If you see 10 peoples working in VI editor you realize that they use it differently then use some new VI commands which you are not familiar of and which could improve your productivity as well. so if you would like to know more and more about VI editor I would suggest observe people around you when they work in VIM or VI editor and learn from there experience. Don’t confuse with both VIM and VI, VIM stands for VI improved and has some more feature than VI editor. Many a times you will find that VI command is aliased to VIM to make it default editor in UNIX.

Sunday, June 19, 2011

3 ways to solve java.lang.NoClassDefFoundError in Java J2EE

What is Exception in thread "main" java.lang.NoClassDefFoundError?
I know how frustrating is to see Exception in thread "main" java.lang.NoClassDefFoundError  Which is a manifestation of NoClassDefFoundError in Java , I have seen it couple of times and spent quite a lot time initially to figure out what is wrong , which class is missing etc. First mistake I did was mingling java.lang.ClassNotfoundException and NoClassDefFoundError, in reality they are totally different and second mistake  was using trial and error method to solve this java.lang.NoClassDefFoundError instead of understanding why NoClassDefFoundError is coming, what is real reason behind NoClassDefFoundError and how to resolve this. In this Java tutorial I have tried to rectify that mistakes and uncover some secrets of NoClassDefFoundError in Java and will share my experience around it. NoClassDefFoundError is not something which cannot be resolved or hard to resolve it’s just its manifestation which puzzles most of Java developer. This is the most common error in Java development along with java.lang.OutOfMemoroyError: Java heap space and java.lang.OutOfMemoryError: PermGen space  Anyway let’s see Why NoClassDefFoundError comes in Java and what to do to resolve NoClassDefFoundError in Java.

Friday, June 17, 2011

How to use Comparator and Comparable in Java? With example

Comparator and Comparable in Java Examples
Difference between Comparator and Comparable in Java is very popular Java interview question mostly asked in telephonic round and writing code to sort object using Comparable or Comparator is popular on  written test round of interview.The question was this “How you will sort Employee object based on his EmployeeID and his name” and this involves the use of both Comparable as well as Comparator interface in Java. This post is my revision on Java fundamentals similar to I did about equals method in Java and  some tips to override hashCode in Java. All of these methods are fundamentals in Java programming language and correct understanding is must for any Java developer. Comparators and comparable in Java are two interfaces which is used to implement sorting in Java. It’s often required to sort objects stored in any collection classes like ArrayList, HashSet or in Array and that time we need to use either  compare() or  compareTo() method defined in java.util.Comparator and java.lang.Comparable. In this Java tutorial we will see example of  Comparator and Comparable to sort object in Java and discuss some best practices around when to use Comparator interface etc. Any way before moving ahead Let’s see some important differences between Comparable and Comparator in Java.

Sunday, June 12, 2011

10 examples of grep command in UNIX and Linux

grep command examples in Unix and Linux
grep command is one of the most frequently used UNIX command stands for "Global Regular Expression Print"  like  find, chmod or tar command in Unix. grep command in Unix operating system e.g. Linux, Solaris, BSD, Ubuntu or IBM AIX is used to search files with matching patterns, by using grep command in Unix you can search a file which contains a particular word or particular pattern. UNIX grep command also provides several useful command line option which can be used to enhance functionality of grep command e.g. by using grep -v you can list down all files which doesn't contains a word i.e. excluding files which matches a pattern, grep -c will print count of matching pattern in a file etc. One of the popular example of  grep command is to find empty files and directories in Unix. This grep command tutorial is not about theory of UNIX grep but practical use of grep command in UNIX and here I am sharing my experience on use of grep command in Linux with an aim that this would serve as quick guide or tutorial for using grep in UNIX for new beginners and help them to understand the grep command better and its thoughtful usage in UNIX or Linux. Many people use grep just for finding words in a file and missed the real potential of grep by not using all its powerful command line options and its regular expression capability which could not only save a lot of time but also works as a great and powerful tool while analyzing large set of data or log files.  Also find command in UNIX can be used in place of grep at many places. If you want to leverage full potential of grep, then using Grep pocket reference is not a bad idea, an ideal grep reference for system admin, developers and security professionals

Friday, June 10, 2011

Top 30 Programming questions asked in Interview - Java C C++ Answers

Top 30 Programming interview questions

Programming questions are integral part of any Java or C++ programmer or software analyst interview. No matter on which language you have expertise it’s expected that you are familiar with fundamental of programming and can solve problems without taking help of API. Programming questions like How to reverse String using recursion or How to find if Array contains duplicates  are some popular examples of programming question in Java.  Programming questions present lot of challenges Especially to Java developers as compared to C++ programmer and I think, One reason for this is powerful Java API; Which has method for almost every need and you rarely need to write by your own or there are lots of third party library from Apache, Spring, Google and other open source. These programming interview questions are from my personal collections and I have only chosen those which are not very difficult, can be solved easily but at same time can become too complex or confusing, present lots of follow-up questions and test fundamentals of programming, OOPS and design. I have not given answers of these programming questions but those can be found by google and I will try to post links of answers here sometime later but at same time I will try to provide quick tips or hints on some questions. If you like to read programming books, you can check out Programming Interviews Exposed and 10 coding questions asked in Google with solution, that helps a lot while preparing for any programming Job interview.

Wednesday, June 8, 2011

Tibco tutorial : Reliability Parameter Explained

Reliability parameter is one of the important stat up parameter we provide to tibco rvd and incorrect setting up of this parameter can screw up things in big way. When I wrote Tibco Tutorials for beginners I thought to explain some individual concept on separate tutorials and this article is part of it. Tibco messaging is one of the most used messaging solution on Investment banks over the years and will continue for coming years.

Friday, June 3, 2011

How Volatile in Java works ? Example of volatile keyword in Java

How to use Volatile keyword in Java
What  is Volatile variable in Java  and when to use Volatile variable in Java is famous multi-threading interview question in Java interviews. Though many programmer knows what is a volatile variable but they fail on second part i.e. where to use volatile variable in Java as its not common to have clear understanding and hands-on on volatile in Java. In this tutorial we will address this gap by providing simple example of volatile variable in Java and discussing some when to use Volatile variable in Java. Any way  Volatile keyword in Java is used as an indicator to Java compiler and  Thread that do not cache value of this variable and always read it from main memory. So if you want to share any variable in which read and write operation is atomic by implementation e.g. read and write in int or boolean variable you can declare them as volatile variable. From Java 5 along with major changes like Autoboxing, Enum, Generics and Variable arguments ,  Java introduces some change in Java Memory Model (JMM),  Which  guarantees visibility of changes made by one thread to another also as "happens-before" which solves the problem of memory writes that happen in one thread can "leak through" and be seen by another thread. Java volatile keyword cannot be used with method or class and it can only be used with variable. Java volatile keyword also guarantees visibility and ordering , after Java 5 write to any volatile variable happens before any read into volatile variable. By the way use of volatile keyword also prevents compiler or JVM from reordering of code or moving away them from synchronization barrier.