Pages

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.

"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.

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.

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.

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.

There are multiple ways to iterate, traverse or loop through Map, HashMap or TreeMapin 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.

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.

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.

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 orwrite 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.

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.

Observer design patternin 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.

Tomcat default port is 8080 but many times other Java application also uses 8080 like any other web-server Resin or Jetty and starting tomcatmay result in java.net.BindException:Address already in use: JVM_Bind 8080. In order to avoid this exception you can changedefault 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.

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.

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.

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.

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.

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.

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.

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

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 thisEnum tutorialwhen 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.

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

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.

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 Javaand 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.

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.

This String replace example in Java will show you how to replace String in Javaboth 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 Javaprovides 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 firstoccurrence of any pattern in Java. We will also see important points on String replace method andhow to make best use of regular expression while replace string in Java.

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