Friday, December 30, 2011

Step By Step guide to Read XML file in Java Using SAX Parser Example

Reading XML file in java using SAX Parser is little different than reading xml file in Java with DOM parser which we had discussed in last article of this series. This tutorial is can be useful for those who are new to the java world and got the requirement for read an xml file in java in their project or assignment, key feature of java is it provides built in class and object to handle everything which makes our task very easy. Basically this process of handling XML file is known as parsing means break down the whole string into small pieces using the special tokens.
Parsing can be done using two ways:

java.lang.UnsupportedClassVersionError: Bad version number in .class files Cause and Solution

How to fix Bad version number in .class file
"java.lang.UnsupportedClassVersionError: Bad version number in .class file" is a common error in Java programming language which comes when you try to run a Java class file. In our last article, we discussed that how to resolve Java.lang.UnSupportedClassVersionError and found that it comes when a major and minor version of the class is not supported by Java virtual machine or JRE running the program. Though "java.lang.UnsupportedClassVersionError: Bad version number in .class file" is little different than that of its manifestation and Cause. UnsupportedClassVersionError is not as difficult as Java.lang.OutOfMemoryError  and neither its solution is too complex but what is hard is thinking in the right direction because the cause of different types of UnsupportedClassVersionError is different.

Difference between DOM and SAX Parsers in Java

A difference between SAX and DOM Parser is very popular Java interview and often asked when interviewed on Java and XML. Both DOM and SAX parser are extensively used to read and parse XML file in java and have their own set of advantage and disadvantage which we will cover in this article. Though there is another way of reading XML file using XPath in Java which is the more selective approach like SQL statements people tend to stick with XML parsers. DOM Parser vs SAX parsers is also often viewed in terms of speed, memory consumption and their ability to process large XML files.

How to read and write Images in java using ImageIO Utility

Writing an Image file in Java is very common scenario and in this article we will see a new way to write images into file in Java. javax.imageio.ImageIO is a utility class which provides lots of utility method related to images processing in Java. Most common of them is reading form image file and writing images to file in java. You can write any of .jpg, .png, .bmp or .gif images to file in Java. Just like writing, reading is also seamless with ImageIO and you can read BufferedImage directly from URL. Reading Images are little different than reading text or binary file in Java as they they are associated with different format. Though you can still use getClass().getResourceAsStream() approach for loading images.

How to Convert a Map to a List in Java Example

Map and List are two common data structures available in Java and in this article we will see how can we convert Map values or Map keys into List in Java. The primary difference between Map (HashMap, ConcurrentHashMap or TreeMap) and List is that Map holds two objects key and value while List just holds one object which itself is a value. Key in hashmap is just an addon to find values, so you can just pick the values from Map and create a List out of it. The map in Java allows duplicate value which is fine with List which also allows duplicates but Map doesn't allow duplicate key.

Thursday, December 29, 2011

4 example to Iterate over HashMap, Hashtable or any Map in Java

There are multiple ways to iterate, traverse or loop through Map, HashMap or TreeMap in Java and we all familiar of either all of those or some of those. But to my surprise, one of my friends was asked in his interview (he has more than 6 years of experience in Java programming) to write code for getting values from hashmap or TreeMap in Java with at least 4 ways. Just like me he also surprised on this question but written it. I don't know why exactly someone asks this kind of java interview question to a relatively senior java programmer. Though my closest guess is to verify that whether he is still hands on with coding in java. Anyway, that gives me an idea to write this Java tutorial and here are multiple ways to traverse, iterate or loop on a Map in Java, so remember this because you may also ask this question J.

What is final in Java? Final variable , Method and Class Example

Final in Java is very important keyword and can be applied to class, method, and variables in Java. In this java final tutorial we will see what is a final keyword in Java, what does it mean by making final variable, final method and final class in java and what are primary benefits of using final keywords in Java and finally some examples of final in Java. Final is often used along with static keyword in Java to make static final constant and you will see how final in Java can increase the performance of Java application.

Difference between JRE JVM and JDK in Java Programming language

JRE, JVM, and JDK are three terms you often heard in conjunction with Java programming language and most people either confuse them or think they all are same. In this java article, we will what is Java Run-time (JRE), what is Java virtual Machine (JVM) and what is Java development Kit (JDK) along with Just in Time compiler or JIT. Once you know what JRE, JVM or JDK means you can differentiate them easily by yourself.  This article is in continuation of Difference between Comparable and Comparator in Java and Difference between ConcurrentHashMap and Synchronized-map.

Wednesday, December 28, 2011

How to Parse or Read XML File in Java >> XML Tutorial Example

How to parse xml file in Java or how to read xml file in java is one of common need of a Java Developer working with enterprise Java application which uses XML for data representation, messaging and data transfer. Java has good support to handle XML files and XML Documents and you can read XML File in Java, create or write to XML file in Java by using various XML parsers available. Reading XML file is little bit different than reading text or binary file in Java but it uses same concept of File class.

Monday, December 26, 2011

Checked vs Unchecked Exception in Java Example

Checked and Unchecked Exception is two types of Exception exist in Java. Though there is no difference in functionality and you can very achieve same thing with either checked Exception or Unchecked Exception, there is some difference on exception handling part. In this Java tutorial we will see what is checked and Unchecked Exception in Java, Examples of Checked and Unchecked Exception and most importantly we will learn when to use Checked Exception and when to use Unchecked Exception in Java and lastly we will see difference between checked and unchecked exception to understand things better. By the way this article is second in my post on Exception along with difference between throw and throws in Java and improved Exception handling in Java 7 with Automatic resource management ARM and multi-catch block in JDK 7.

Sunday, December 25, 2011

Observer design Pattern in Java with Real world code Example

Observer design pattern in Java is a fundamental core Java pattern where Observe watch for any change in state or property of Subject. For Example Company updates all its shareholders for any decision they make here Company is Subject and Shareholders are Observers, any change in policy of company and Company notifies all its Shareholders or Observer. This was simple real world explanation of Observer pattern. In this article we will in detail what is Observer Design pattern, what is benefit of Observer design Pattern, Example or Observer pattern in Java and few other points. Just like Decorator design Pattern and Factory Pattern in Java, Observer pattern is also used in JDK.

How to change Tomcat default port 8080

Tomcat default port is 8080 but many times other Java application also uses 8080 like any other web-server Resin or Jetty and starting tomcat may result in java.net.BindException:Address already in use: JVM_Bind 8080. In order to avoid this exception you can change default port of tomcat from 8080 to some other port e.g. 8081 or 8082. Though don't change to tomcat port which is likely to be used by tomcat itself e.g. 8443 is used by tomcat https port. Use port which is most likely to be free. In this tomcat tutorial we will see how to change default port 8080 for http protocol in tomcat and port 8443 port for https protocol in tomcat.

Friday, December 23, 2011

Difference between Method Overloading and Overriding in Java?

Method Overloading vs Method Overriding
Though the name of the method remains same in the case of both method overloading and overriding, main difference comes from the fact that method overloading is resolved during compile time, while method overriding is resolved at runtime. Also rules of overriding or overloading a method are different in Java. For example, a private, static and final method cannot be overriding in Java but you can still overload them. For overriding both name and signature of the method must remain same, but in for overloading method, the signature must be different. Last but not the least difference between them is that call to overloaded methods are resolved using static binding while the call to overridden method is resolved using dynamic binding in Java.

Tuesday, December 20, 2011

Java.net.BindException: Address already in use: JVM_Bind:8080 Solution

java.net.BindException: Address already in use: JVM_Bind is a common exception in Java with application trying to connect on a particular port and some other processes either Java or non Java is already connected on that port. You can get "Address already in use: JVM_Bind" error while doing remote debugging in Java in Eclipse, when Eclipse trying to connect to remote Java application, when you are starting tomcat and another instance of tomcat is listening on port 8080 you will get java.net.BindException: Address already in use: JVM_Bind:8080.

Address already use: JVM Bind ExceptionIn this post we will analyze java.net.BindException and trying to figure out cause of "Address already in use: JVM_Bind" before fixing it. This article is in continuation of my earlier tutorial, How to Solve OutOfMemoryError in Java and How to fix ClassNotFoundException in Java.

Monday, December 19, 2011

Why main method is public static in Java

Main method in Java is the first programming method a Java programmer knows when he starts learning Java programming language.have you ever thought about why main method in Java is public, static and void, of-course Yes, since most of us first learn C and C++ than we move to Java in our programming path we familiar with main method but in Java main method is slightly different it doesn't return any value like in C it returns int, main method is public static and void Why? In this post we will try to find answer to these questions and have an idea of one of the most popular questions in Java why main method is declared Static.

Friday, December 16, 2011

What is load-on-startup servlet element in web.xml with Example?

load-on-startup is an element which appears inside <servlet> tag in web.xml.4 years back load-on-startup was a very popular servlet interview question because not many Java J2EE developer was familiar with this element and how load-on-startup works inside servlet container like tomcat or webshere. In this J2EE Tutorial we will see what is load on start up, how to use load-on-startup element and what are different values we can configure for loadOnStartup inside web.xml.

Is Apple IPhone4S Siri going to replace the Google Search Engine

I am sure this is one of those most optimistic title you can think of but that is what my first thought after seeing apple introductory video of Siri, there new voice recognition and task completion service integrated on Apple Iphone4s. I was amazed with smoothness and accuracy of Siri as shown on that video. You just say siri what's whether, find me new restaurant, traffic status and you get a response you are looking for, this looks to me a new way of searching web and technology.  Asking questions is more natural than typing on Google and believe if Siri kicks of like that you will suddenly have more search volume via siri than google, though only limiting factor is not everybody has Apple Iphone4s with them :). People are also thinking Siri as Google Killer let's see.

Wednesday, December 14, 2011

5 Example of kill command in UNIX and Linux

Kill command in UNIX and Linux is normally used to kill a suspended or hanged process or process group. Though kill is mainly associated with kill operation its mere a signal transporter and can send specified signal to specified process in UNIX or UNIX like systems e.g. Linux, Solaris or FreeBSD. Like in windows when we see a particular process hung the system we go to task manager find the process and kill it, similarly in UNIX and Linux we first find the process ID (PID) of offending process and then kill it. Though we have killAll command also which doesn't require PID instead it can kill the process with just process name. Kill commands is often a wrapper around kill () system call but some Linux systems also has built-in kill in place. In this article we will see some examples of kill command in UNIX and how we can use kill command to kill the locked process.

Monday, December 12, 2011

Java TreeMap Tutorial: 10 Example of TreeMap in Java

TreeMap in Java is a SortedMap and it maintains Sorting order when you insert object on it.
You can specify Sorting order while Creating TreeMap by providing an explicit Comparator to
TreeMap. Basically you can create TreeMap in Java by different ways, a TreeMap with natural sorting order, and TreeMap with custom Sorting Order by providing Comparator, Copying Sorting order from other SortedMap etc. TreeMap has specific constructor for these conditions. We will see these in section of creating instance of TreeMap in Java.  We will also see how to put element, get element, iterate over TreeMap, clearing and reusing TreeMap in this Java TreeMap tutorial. This article is in continuation of my collection series e.g. HashMap vs HashSet , SynchronziedHashMap vs ConcurrentHashMap and Iterator vs Enumeration in Java

Friday, December 9, 2011

How to parse String to Enum in Java | Convert Enum to String with Example

Converting Enum into String and parsing String to Enum in Java is becoming a common task with growing use of Enum. Enum is very versatile in Java and preferred the choice to represent bounded data and since is almost used everywhere to carry literal value it's important to know how to convert Enum to String in Java. In this article, we will see both first converting Strings to Enum in Java and then Change an Enum to String in Java with Example. I thought about this Enum tutorial when I wrote 10 Examples of Enum in Java. I missed String to Enum conversion and one of reader pointed out that. So here we have now.

Wednesday, December 7, 2011

Top 5 FIX Protocol Data Dictionaries and Online FIX References

While you work on FIX Protocol you need a handy FIX Data dictionaries or what we called fixionary in order to refer for exact details related to particular message type, particular fix tag and what does a particular value of tag means. Without FIX data dictionary or fix wiki it’s very hard to work especially when you are dealing with different fix protocol versions like FIX 4.0, FIX 4.1, FIX 4.2 and FIX 4.4. In this FIX Protocol article we will explore some of free available fixionaries or fix protocol reference guides. FIX data dictionary is a must have development tool for FIX protocol developers.

Tuesday, December 6, 2011

How to read and write in text file in Java

Java has excellent support for reading from file and writing to file in Java. In last post we have seen how to create file and directory in Java and now we will see how to read content from file in java and how we will write text into file in Java. File provides persistent solution to Java developer; in almost every Java application you need to store some of the data in persistent may be its user configuration, system configuration or related to state of application but without persistence no enterprise Java application can buildup. Normally Database is preferred choice for storing data persistently but in high frequency trading one doesn’t have liberty to afford network latency to travel database and latency introduced by database itself, though database still offer best choice for historical data , transactional details related to orders and trades are commonly stored in In Memory files provided by Java.nio API.

Monday, December 5, 2011

How to deal with Java.rmi.MarshalException: CORBA MARSHAL in Java

Java has some mysterious RMI exception one of them is java.rmi.MarshalException: CORBA MARSHAL, which was bothering me from last couple of days while working. I thought to put this solution post similar to my earlier post How to solve OutofMEmroyError in Java and Fixing ClassNotFoundException in Java. RMI is still used in many places and many times it create too much problem and chew-up your lot of time to find exact cause and solution.

Sunday, December 4, 2011

Matt Cutt Revealing Google's Latest Algorithmic Changes

Inside Search: Search quality highlights: new monthly series on a...: Today we’re publishing another list of search improvements, beginning a monthly series where we’ll be sharing even more details about the al...

Saturday, December 3, 2011

How to Create File and Directory in Java Example - Java IO Tutorial

How to create File and directory in Java is probably the first things come to mind when we exposed to the file system from Java. Java provides rich IO API to access contents of File and Directory in Java and also provides lots of utility method to create a file, delete a file, read from a file, and write to file or directory. Anybody who wants to develop an application in Java should have a solid understanding of IO and Networking package. In this Java File Tutorial, we will basics of File and Directory in Java, How to Create File and Directory in Java, Utility methods provided by File API and Common Exception or Error you will face during File and Directory Creation or access time. Creating File is different than creating Thread in java as you don’t have to implement any interface for making a Class as File in Java.


File in Java is also getting its place on various core java interviews questions especially after the introduction of java.nio package and concepts like In Memory Files, we will discuss those in probably another blog post but what it confirms is the importance of knowledge of File IO for java programmer.

Friday, December 2, 2011

Java String Replace Example Tutorial

This String replace example in Java will show you how to replace String in Java both at character level and by using regular expression. Since String is final in Java every time you replace String you will get a new String object only if your actually replace anything on original String otherwise replace methods of String return same String object. String Class in Java provides 4 methods to replace String in Java. Those methods allow you to replace character from String, replace CharacterSequence from String, replace all occurrence of pattern in String or just first occurrence of any pattern in Java. We will also see important points on String replace method and how to make best use of regular expression while replace string in Java.

This article is on series of my other String article like 2 ways to Split String in Java and how to convert String to Date in Java. String is one of the most important classes in Java and having a good knowledge of String class is mandatory for any Java developer.

What is Factory method Design Pattern in Java with Example - Tutorial

Factory design pattern in Java one of the core design pattern which is used heavily not only in JDK but also in various Open Source framework such as Spring, Struts and Apache along with decorator design pattern in Java. Factory Design pattern is based on Encapsulation object oriented concept. Factory method is used to create different object from factory often refereed as Item and it encapsulate the creation code. So instead of having object creation code on client side we encapsulate inside Factory method in Java. One of the best examples of factory pattern in Java is BorderFactory Class of Swing API. In this Design pattern tutorial we will see What is Factory method design pattern in Java, What are main advantages of factory pattern in Java , Code example of Factory design pattern and What problem Factory pattern solves in Java or when to use Factory design pattern.  This article is in continuation of my design pattern article as 10 OOPS and SOLID design principles java programmer should know and How to use Observer pattern in Java

Friday, November 25, 2011

Database Transaction Tutorial in SQL with Example for Beginners

A database transaction is an important concept to understand while working in database and SQL. Transaction in the database is required to protect data and keep it consistent when multiple users access the database at the same time.  In this database transaction tutorial we will learn what is a transaction in a database, why do you need transaction in the database, ACID properties of database transaction and an example of database transaction along with commit and rollback.   Almost all vendors like Oracle, MySQL, SQL Server or Sybase provide transaction facility but MySQL only provide it for certain storage engines like InnoDB and BDB and not for MyISAM.

Thursday, November 24, 2011

Great Example of Open Closed Design Principle in Java

Great Example of Open Closed Design Principle
I am big fan of design pattern article and love to read articles on design patterns and recently wrote about decorator design pattern in JavaObserver patternstatic factory pattern and about Singleton pattern. Today I come across this good article on open closed design pattern, what I like most is there example and clear way of explanation, first example is true value and it will help you understand open closed principle very quickly and second example is also not bad. I have also shared many questions on design patterns and Object oriented design principles like 10 Java singleton interview questions , which discusses some of the most common questions on Singleton pattern like how to write Thread-Safe Singleton class , should we use Enum as Singleton or not etc and 20 design pattern interview questions, if you are preparing for senior level Java interview, where questions from design is expected, its worth looking for quick review.

open closed design principle exampleOne word about Open Closed principle is a design principle which says that a class should be open for extension but closed for modification. Open Closed Principles is one of the principle from SOLID design principle where it represent "O". Read more about OOPS and SOLID design pattern in my post 10 OOPS and SOLID design principles Java programmer should know.  


In Simple language Open closed design principles says that new functionality should be added by introducing new classes, methods or fields instead of modifying already tried and tested code. One of the way to achieve this is Inheritance where class is extended to introduce new functionality on top of inherited basic features.

Benefit or Open Closed Design Principle:
1) Application will be more robust because we are not changing already tested class.
2) Flexible because we can easily accommodate new requirements.
3) Easy to test and less error prone.

Wednesday, November 23, 2011

Top 10 Struts Interview Question And Answer - J2EE

This time its Struts interview questions, After writing Spring interview questions few weeks back I was thinking what to pick for my interview series and then I thought about any web framework, and on that struts is my favorite. Struts are open source framework used for web application. These Struts interview questions are based on my experience as well as collected by friends and colleague and they are not only good for interview practice but also shows a new direction of learning for anyone who is not very familiar with struts. The best way to use these interview questions does revise before going for any Struts interview or any Java or J2EE interview. I have also provided answers to these struts interview questions but you can also research more on Google but these answers of struts are sufficient on interview perspective.

Sunday, November 20, 2011

XPath Tutorials Examples for Beginners and Java Developers

XPath Tutorials for Beginners and Java Developers
This XPath Tutorial is collection of my Xpath Notes which I prepared recently when I was working on XML and XPATH. Though I was familiar with XML but not with Xpath and thought to note down bullet points about Xpath to get myself up and running. It’s not quite detailed but gives a nice overview on what is Xpath and how can you use Xpath in Java. I have not edited order of notes and presented it as it is in this XPath Tutorial. It also contains some example of xpath expression to give you an idea of how they look like but its analogous to SQL which is used to retrieve data from tables.

Saturday, November 19, 2011

Top 25 Java Collection Framework Interview Questions Answers for Freshers and Experienced Programmers

Interview questions from Collection package or framework are most common in any Core Java Interview yet a tricky one. Together Collection and multithreading make any Java interview tough to crack and having a good understanding of Collection and threads will help you to excel in Java interview. I thought about writing interview questions on Java collection framework and important classes like ArrayList, HashMap, Hashtable, and newly added concurrent collections e.g. ConcurrentHashMap when I first wrote 10 multi-threading Interview questions  but somehow this article got delayed. Though I have shared several questions individually in between.

Friday, November 18, 2011

Decorator design Pattern in Java with Example Java Tutorial

I was thinking to write on decorator design pattern in Java when I first wrote 10 interview questions on Singleton Pattern in Java. Since design pattern is quite important while building software and it’s equally important on any Core Java Interview, It’s always good to have clear understanding of various design patterns in Java. In this article we will explore and learn Decorator Design pattern in Java which is a prominent core Java design pattern and you can see lot of its example in JDK itself. JDK use decorator pattern in IO package where it has decorated Reader and Writer Classes for various scenario, for example BufferedReader and BufferedWriter are example of decorator design pattern in Java. From design perspective its also good idea to learn how existing things work inside JDK itself for example How HashMap works in Java or How SubString method work in Java, that will give you some idea of things you need to keep in mind while designing your Class or interface in Java. Now let’s Move on to Decorator pattern in Java.

Thursday, November 17, 2011

File permissions in UNIX Linux with Example >> Unix Tutorial

Whenever we execute ls command in UNIX you might have observed that it list file name with lot of details e.g.
stock_options:~/test ls -lrt
total 8.0K
-rw-r--r-- 1 stock_options Domain Users 1.1K Jul 15 11:05 sample

If you focus on first column you will see the file permissions as "-rw-r--r--" this is made of three parts user, group and others. User part is permission relate to user logged in, group is for all the members of group and others is for all others. also each part is made of three permissions read, write and execute so "rw-" means only "read and write" permission and "r--" means read only permission. So if you look permission of example file it has read and writes access for user, read only access for groups and others. Now by using chmod command in UNIX we can change the permissions or any file or directory in UNIX or Linux. Another important point to remember is that we need execute permission in a directory to go inside a directory; you can not go into directory which has just read and write permission.

Tuesday, November 15, 2011

LDAP Active Directory Authentication in Java Spring Security Example Tutorial

LDAP authentication is one of the most popular authentication mechanism around the world for enterprise application and Active directory (an LDAP implementation by Microsoft for Windows) is another widely used LDAP server. In many projects we need to authenticate against active directory using LDAP by credentials provided in login screen. Some time this simple task gets tricky because of various issues faced during implementation and integration and no standard way of doing LDAP authentication. Java provides LDAP support but in this article I will mostly talk about spring security because its my preferred Java framework for authentication, authorization and security related stuff. you can do same thing in Java by writing your own program for doing LDAP search and than LDAP bind but as I said its much easier and cleaner when you use spring security for LDAP authentication.

Thursday, November 10, 2011

Helloworld Example Java : How to run Java Program from command prompt

This article contains HelloWorld Example in Java and step by step guide to run Java program from command prompt. Beginners who just started to learn Java or using Java often struggled and doesn't know how to run a Java program from command prompt. Running a Java program is simple but setting up Java environment is rather cumbersome especially if you are new in Programming world and not
very familiar with words like PATH, CLASSPATH or even command prompt. I don't blame you because we all start at some point of time and even When I started to wrote my first Java program, What I was doing was simply typing HelloWorld from a textbook in a notepad editor, to my surprise my Java program ran without any issue because I was running that on school PC where PATH and CLASSPATH were already setups but when I tried the same thing on my home Windows PC I had tough time to run my Java program including HelloWorld Example in Java.

Tuesday, November 8, 2011

Result of Recent Google PageRank Update in November 2011

Just come to know about recent Google PR update which is due today 8th November 2011 and thought about this post to share result of recent Google Page Rank update based on my experience.
Everybody in web is talking about this Google PR update which is coming after recent Google Panda or Caffeine update, which has affected many sites ranking. I think Google PR update has been done or under work because I can see PR updates from zero to two on some of my articles. I can also see that this time Google is more restrict on awarding page rank and the one which got PR 3 on last Google PR update on Augst 2011 is getting PR 2 this time. Google has also adjusted PR of existing articles along with new articles.

10 Examples of HotSpot JVM Options in Java

There are hundreds of JVM parameters or JVM Options exists inside sun JDK and its virtually impossible to keep track of every single JVM option and based on my experience we don't even use most of JVM flags except couple of important JVM option related to java heap size, java options for printing garbage collection details and most likely JVM switches for setting up remote debugging in Java. but there are many other useful category of JVM parameters which you at least like to be familiar even if not intending to use it more frequently. In this article we will see examples of 10 different categories of JVM parameter which I found useful and use more frequently than other. I would recommend to get a full knowledge of what does a particular JVM options does by referring official list of JVM options.

Monday, November 7, 2011

What is Static Variable Class method and keyword in Java - Example Tutorial

What is Static in Java
Static in Java is an important keyword and used to create static method, static class and static variable in Java. Correct understanding of static keyword is required to understand and write sophisticated Java programs. Java 5 also introduced static imports along with Autoboxing, Generics, Enum and varargs method, which allows to import static members of one class or package into another using import keyword and then using them like they are member of that class. In this Java tutorial we will learn about What is is static in Java, What does it mean to be a static field, static class or method in Java and various points and issues involved around How to use static members in Java. This Java tutorial is also about how to use static keyword in Java and where not to use static keyword. Common rule is anything which you want to share between all object can be made static e.g. singleton instance of a  Singleton Class in Java.

Saturday, November 5, 2011

10 Examples of tar command in UNIX and Linux

tar command in UNIX or Linux is one of the important command which provides archiving functionality in unix. we can use UNIX tar command to create compressed or uncompressed archive files by using either gzip or bzip2. In this unix tar command tutorial we will see examples of unix tar command related to basic archiving task e.g. How to create tar archive in Unix and Linux, How to extract files from tar archive in unix, How to view contents of tar file in Unix and Linux or how to update and existing tar file in Unix. Examples of tar command in unix are kept simple and easy to understand and master each of basic task using unix tar command.

Thursday, November 3, 2011

How to override compareTo method in Java - Example Tutorial

compareTo in Java is in the same league of equals() and hashcode() and used to implement natural order of object, compareTo is slightly different to compare() method of Comparator interface which is used to implement custom sorting order. I have seen during java interviews that many Java programmers not able to correctly write or implement equals(), hashCode() and compareTo() method for common business objects like Order or Employee. Simple reason behind this is that they either not understand the concept well enough or doesn't write this stuff at all. I will try to fill that gap in this Java tutorial and will see What is compareTo() method in java, how to write compareTo in Java and things to remember while implementing compareTo in Java.

Monday, October 31, 2011

How to Convert Double to String to Double in Java Program with Example

Many scenarios come in day to day Java programming when we need to convert a Double value to String or vice versa. In my earlier article we have seen how to convert String to Integer and in this article, we will first see how to convert double to String and the later opposite of  that from String to double. One important thing to note is Autoboxing which automatically converts primitive type to Object type and only available from Java 5 onwards. This conversion example assumes the code is running above Java 5 version and actually tested in JDK 1.6, which makes it unable to pass Double object when the method is expecting double primitive value e.g. String.valueOf(double d) which expect a double value.

Sunday, October 30, 2011

How to Stop Thread in Java Code Example

The thread is one of important Class in Java and multithreading is most widely used a feature,but there is no clear way to stop Thread in Java. Earlier there was a stop method exists in Thread Class but Java deprecated that method citing some safety reason. By default, a Thread stops when execution of run() method finish either normally or due to any Exception.In this article, we will How to Stop Thread in Java by using a boolean State variable or flag. Using a flag to stop Thread is a very popular way  of stopping the thread and it's also safe because it doesn't do anything special rather than helping run() method to finish itself.

Thursday, October 20, 2011

What is Iterator and ListIterator in Java Program with Example - Tutorial Code Sample

Iterator in Java is nothing but a traversing object, made specifically for Collection objects like List and Set. we have already aware about different kind of traversing methods like for-loop ,while loop,do-while,for each lop etc,they all are  index based traversing but as we know Java is purely object oriented language there is always possible ways of doing things using objects so Iterator is a way to traverse as well as access the data from the collection. Even with traversing with object we have Enumeration, Iterator and ListIterator in Java which we will in this Java Iterator tutorial.

Wednesday, October 19, 2011

Difference between Truncate and Delete command in SQL - Interview Questions with Example

Truncate and delete in SQL are two commands which are used to remove or delete data from a table. Though quite basic in nature both SQL commands can create a lot of trouble until you are familiar with details before using it. The difference between Truncate and delete are not just important to understand perspective but also a very popular SQL interview topic which in my opinion a definite worthy topic. What makes them tricky is the amount of data. Since most of Electronic trading system stores large amount of transactional data and some even maintain historical data, a good understanding of delete and the truncate command is required to effectively work in that environment.I have still seen people firing delete command just to empty a table with millions of records which eventually lock the whole table for doing anything and take ages to complete or Simply blew log segment or hang the machine.

Saturday, October 15, 2011

How to convert decimal to binary, octal and hex String in Java Program

This article is a simple Java program which converts the decimal number to binary, octal and hexadecimal format. When it first came into my mind I though I would probably need to write whole code to convert decimal to various other radix or base numbers but when I looked Integer class and saw these two way of converting decimal to binary etc I was simply amazed. It’s indeed extremely easy to do this in java and you can also write this program or use it is.

How to write Helloworld in Google Dart with Example - Dart Tutorial

Google Dart  Program Example Tutorial

Google dart is now released and its time to try google dart and see how much it offers to a programmer and whether it is suitable language to replace JavaScript or not. As a language my first impression of Google dart is great it looks so much familiar with Java my favorite programming language and this motivate me to write this hello-world example in Google Dart and execute it , run it and see how it works. Google dart has Class and Object, it has final keyword, String Class , Object class , extends keyword and many more I going to learn but it really look structure because it has google dart compiler which shows warning and error like any other structure programming language.

In this Google Dart tutorial we will see How to write Helloworld in Google Dart and How to run Google dart program using Google Dartboard Application which is a browser based application, allow you to write and run Google Dart Programs. This is the easiest and quickest way to get a feel of Google Dart language itself before trying it with HTML code. Google Dart also has compiler and html converter which allow you to convert Dart code into JavaScript and use it. We will see about how to convert Google Dart Code into JavaScript in next article. For now let's start with this step by step guide of writing Google Dart HelloWorld Example and running it.


Step by Step Guide to Write and Run Google Dart Example



I. Open http://www.dartlang.org/ in your browser.

Make sure you use Mozilla Firefox, Google Chrome or Apple Safari. Google Dartboard application won’t work on Microsoft Internet Explorer, though support is coming in may be few days or week.also if you are using Mozilla please use latest version, Google Dartboard was not working on my Mozilla Firefox 3.6 versions. Once you open this link Google Dartboard Application will be open on your browser and first example which it has is "Hello Dart" as shown in below screen.

google dart example tutorial


II. Important points about Google Dart structured programming language

Now you have two options either edit the existing program or write a new program.
Before writing new program let’s see few points about google dart language.

1. Like Java google dart program will start with main () method.

2. You can declare Variable using "var" a JavaScript style or using correct type like String or int using Java Style , for example below two code  are same.

String text = "NYSE is biggest Stock Market in world";
var text = "NYSE is biggest Stock Market in world";

It depends upon your choice whether you want to adopt javascript style or Java Style. Since I am a Java programmer I found Java Style more intuitive and easy to use.

3. You can assign incorrect type to variable e.g. in this example assigning "text" as int, your programe will run but Dart compiler will show warning related to incorrect type.

int text ="google dart compler will show warning but programme will run".

4. Instead of var or a formal type, you can use final keyword and your program will run successfully.

5. Each statement ends with semicolon ";" otherwise compiler will throw error "Unexpected token "IDENTIFIER expected" or "; expected"

6. For displaying value of variable we need to use interpolation or jsp expression language style "${var}" or else it will complain as "cannot resolve text".

7. We can display string as literal, exactly same as in Java. print() method is similar to Perl, java or any other language. For example

print("This is String literal");

III. Our first google dart program

main() {
  String tradingSecrets = "High Frequency Trading requires extremely fast computers";
  int latency = 10;
  String message = "Google Dart language";
 
  print('Hello world in ${message }');
  print("This is String literal just like Java");
  print( '${tradingSecrets}');
}


Output:

Hello world in Google Dart language
This is String literal just like Java
High Frequency Trading requires extremely fast computers



IV. Running your Google Dart program

Just press the Run button as shown in the above image, it will contact darn server and run your program, sometime you may get error as "The darn server failed to respond." but mostly you see out of your google dart program.

This is the first Google Dart tutorial there are more to come but this is good to start and get feeling of Google dart language. Google Dartboard application is easy to use and execute google dart program which reduce learning curve but converting google dart program to JavaScript and than running into HTML file like JavaScript requires little effort which we will see in next article.




Friday, October 14, 2011

10 Example Queries of SQL Select Command

The Select command in SQL is one of the most powerful and heavily used commands. This is I guess the first command anyone learn in SQL even before CREATE which is used to create a table in SQL. SELECT is used in SQL to fetch records from database tables and you can do a lot many things using Select. For example, you can select all records, you can select few records based on the condition specified in WHERE clause, select all columns using the wild card (*) or only selecting a few columns by explicitly declaring them in a query.

Thursday, October 13, 2011

Dennis Ritchie, Creator of C language and Unix has passed away

I just come to know about this sad news that Dennis Ritchie passed away, It is second blow to technology world after Steve jobs who has recently passed away. Dennis Ritchie is the first programming figure I come to know when I started my programming classes in C and C++ and that's why when I heard this news I feel sad about it and suddenly I remember my programming days and I thought about this post to pay my tribute and remember him.


Dennis Ritchie creator of C and Unix passed away
There is lot of Great information available on Dennis Ritchie in web and Wikipedia but two of its main contribution is:

1) C Programming language, which is still number one after Java.
2) His Contribution in UNIX Operating System which is best Server Operating system available.
3) Author of book


Let’s remember this programming genius and pay 2 minute tribute to him, without his C language and immense contribution to programming language, community will never forget him.

May god rest his soul in piece.