HTML

JDOM Example : Reading and Parsing XML with SAX parser in Java

XML parsing with JDOM parser
JDOM is an open source library which allow XML parsing and reading in Java program. JDOM is designed by using Java programming technique and customized for Java programmers, so that Java programmer with  very little knowledge of XML documents can use JDOM to read XML files. Unlike DOM Parser of Java API , which uses Factory design pattern to create instance of parser e.g DocumentBuilderFactory and DocumentBuilder, as seen in our last example of parsing XML documents in Java, JDOM uses new() operator to create its parser instances. In fact JDOM is very easy to understand and most of the time its self explanatory. While trying this Java program to parse XML file, you can explore JDOM API. JDOM API also allows to use XPATH expression to query XML documents with package org.jdom2.xpath. In next section we will see complete code example of How to read an XML file using JDOM parser in Java program.

How to Search Element in Java Array with Example

find an index of the object in Array
While programming in Java, many times we need to check if a String array contains a particular String or an int array contains a number or not. Though array is an object in Java but it does not provide any convenient method to perform these kinds of operation. Sometimes you even need an index of an item stored in Array, unfortunately, Java API does not provide any direct method. Thanks to open Source Apache Commons provides a utility class called ArrayUtils which allows you to check for an Item in Array, find its index in the array, find its lastIndex in Array and perform several other common operations. In fact, ArrayUtils has overloaded methods for different kind of Array e.g. String, int, float, double, Object etc, which makes this kind of programming task trivial. In this article, we will see an Apache commons example of How to use ArrayUtils class to search an item in Array and find its index.

Difference between Serializable vs Externalizable in Java - Interview Question

Serializable vs Externalizable
What is difference between Serializable and Externalizable in Java is famous core Java interview questions and for some of them its one of those difficult Java question, which no one want to see in Java interview. I was on that category until I explored How Serialization works in Java and find out more about Serialization process. What makes Serialization questions tricky is , Serialization as persistence mechanism is not very popular. Many programmer prefer database, memory mapped file or simple text file over Serialization. But Serialization has a distinguished advantage over these mechanism. Java provides default mechanism to preserver object state and your job many time would be as simple as adding implements Serializable on any class.In this article we will compare Serializable to Externalizable and see some common difference between Serializable vs Externalizable to tackle this Java question.

Top 10 Servlet JSP Interview Questions for Java J2EE programmer - FAQ

Servlets and JSP Interview Questions are core of any J2EE Interview. Its expected from candidate to have good knowledge of Servlet, JSP, EJB , Struts or Spring in any J2EE interview. Consequently Servlets and JSP Interview Questions are very common in any J2EE Interviews along with some questions from core Java, Some interview Questions from Spring and Some EJB interview questions. Since J2EE is main platform for building enterprise and web application using Java programming language, its important to prepare well for J2EE interview, especially If you are in application development space. Servlet and JSP forms web layer of J2EE framework where Java Server pages is main view technology and Servlets are main Controller component of standard MVC architecture. In this article we will see couple of most common or frequently asked JSP and Servlet Interview questions and answers, which can help you on your J2EE interview preparation and understanding some key concept of Java web applications.

Difference between throw vs throws in Java

throw vs throws in Java
throw vs throws in Java programming Exceptionthrow and throws are two Java keyword related to Exception feature of Java programming language. If you are writing Java program and familiar with What is Exception in Java, its good chance that you are aware of What is throw and throws in Java. In this Java tutorial, we will compare throw vs throws and see some worth noting difference between throw and throws in Java. Exception handling is an important part of Java programming language which enables you to write robust programs. There are five keywords related to Exception handling in Java e.g. try, catch, finally, throw and throws. Apart from the difference between final, finally and finalize,  throw vs throws is one of the frequently asked Java interview questions. Difference listed here will not only help you to answer this interview question but also understand concept behind throw and throws better.

Java Interview Questions for 2 to 3 years experience - Answered

Java Interview Questions 2 to 4 years experienced
If you are a Java programmer with 2 to 3 years experience of working in Java and looking for job change then its better to know what is expected from a 2 to 3 years experienced Java programmer in a typical core Java or J2EE interview. Since 2 to 3 years is not a huge experience and you still fall under beginner to intermediate category , its not expected from you to have done profiling, Garbage collection tuning or designing complex Java applications or even creating concurrent Java design pattern. What is expected from a 2 to 4 years experience guy in Java programming is sound knowledge of Java fundamental including OOPS concepts like Abstraction, Encapsulation, Polymorphism, Composition and Inheritance, good knowledge of Java collection API and familiarity with different kinds of collection e.g. List, Set and Map with some familiarity with popular Collection classes e.g. ArrayList, HashMap, Vector and HashSet etc. Fundamental knowledge of Java threading API, wait-notify mechanism and Exception handling in Java is also something Interviewer look in a intermediate Java programmer and of-course some basic programming and coding exercise e.g. finding length of linked List in one pass or reversing String in Java etc. If you manage to prepare these topics well, you are most likely to do well in Java interviews on service based companies e.g. Tech Mahindra, CapeGemini, CTS, Wipro, TCS etc.

How to iterate over HashSet in Java - loop or traverse Example

Iterating over HashSet in Java
Java program to Iterate over HashSet in Java with ExampleIn our last Java collection tutorial, we have seen How to iterate over ArrayList in Java and in this tutorial we will see How to iterate over HashSet in Java. There are two ways to iterate, loop or traverse over HashSet in Java, first using advanced for-each loop added on Java 5 and second using Iterator which is a more conventional way of iterating over HashSet in Java. Now questions are When should you use for loop and when Iterator is an appropriate option. Well I usually use for loop If I only read from HashSet and doesn't remove any element, while Iterator is preferred approach. You should not remove elements from HashSet while iterating over it in for loop, Use Iterator to do that.

How to convert Hexadecimal to Decimal, Binary and Octal in Java program - Example

Hexadecimal to decimal and binary conversion in Java
This Java program will convert Hexadecimal number to decimal, binary and Octal in Java programming language using JDK standard API methods. For beginners hexadecimal is base 16 number, while decimal is base 10, Octal is base 8 and binary is base 2 numbers in Number systems. Binary only contains 0 and 1 bits, octal contains 0 to 7, decimal contains 0 to 9 and Hexadecimal contains 0-9,A,B,C,D,E,F where F represent 16. Thankfully Java library provides convenient method to convert any integer from one number system to another. In our last article we have seen How to convert decimal number to binary in Java and in this article we will convert Hexadecimal numbers to binary, octal and decimal numbers.If you are going for programming interviews, then its better to prepare How to do this exercise without using Java API as well, as interviewer commonly expect programmer to create there own method during interviews e.g. reversing String without using StringBuffer reverse() method.

How to convert ArrayList to String in Java - Spring Example

Some time we need to convert ArrayList to String in Java programming language in order to pass that String to stored procedure, any method or any other program. Unfortunately Java collection framework doesn't provide any direct utility method to convert ArrayList to String in Java. But Spring framework which is famous for dependency Injection and its IOC container also provides API with common utilities like method to convert Collection to String in Java. You can convert ArrayList to String using Spring Framework's StringUtils class. StringUtils class provide three methods to convert any collection e.g. ArrayList to String in Java, as shown below:

How to find swap space and usage in Solaris - UNIX command

Swap space in Solaris or any UNIX host is an important disk space which is used for swapping process from physical memory (RAM)  to disk. Virtual memory allowed a process to run even if physical memory gets full by using swap space (which is located on your hard disk) to swap out memory pages which are not currently in use. In this UNIX command tutorial, we will see some Solaris commands to find configured and current usage of swap space. Remember if your machine runs out of swap space then you can not start a new process and also an old process which will try to expand themselves will likely to fail. 

UNIX command to find symbolic link or soft link in Linux

There are two ways you can find a symbolic link or soft link in UNIX based operating system e.g. Linux, Solaris, BSD or IBM AIX. The first way is by using ls command in UNIX which displays files, directories, and links in any directory and other way is by using UNIX find command which has the ability to search any kind of files e.g. file, directory or link. In this UNIX command tutorial, we will see examples both of these UNIX commands for finding a soft link in any directory. If you are new to UNIX operating system and not familiar with the concept of the soft link and hard link, I would recommend getting a good hand on it, as it is one of the most powerful features of UNIX based system.

Difference between static and non static nested class in Java - Inner class

Static vs non Static class in Java
In Java you can make a class either static or non static. Now what is difference between making a class static vs non static? well there is lot of difference between them. First of all there are two kinds of class in Java, one is called top level class and other is called nested class. As name suggested top level class is a class which is declared in .java file and not enclosed under any other class. On other hand nested class is declared inside another class. The class which enclosed nested class is known as Outer class. Now let's come back to static vs non static class. In Java programming language you can not make a top level class static. You can only make nested class either static or non static. If you make a nested class non static then it also referred as Inner class. Now let's come to the point regarding Difference between static and non static nested class in Java

20 EJB 3.0 Interview Questions and Answers - Java J2EE

EJB interview questions are core part of any Java J2EE interview. As EJB forms business layer for modern J2EE enterprise application, Good knowledge of EJB is expected from J2EE programmer. Purpose of these EJB interview questions is to give an Idea about what kind of questions you can expect on J2EE and EJB interviews. EJB was always tough for Java programmer because of heavy weight architecture comprised with many interfaces e.g. home interface, remote interface, local interface, bean class etc. It take too much time and knowledge to implement and use EJB in your Java web and enterprise application forget about challenges posed by application servers like WebLogic or IBM WebSphere. All these problem persist till EJB 2.0 which makes EJB infamous along with J2EE and created path for Spring framework which is based on POJO. But with EJB 3.0, Enterprise Java Beans are back again and they are back with bang. In this article I will share some EJB Interview questions from my collection. These EJB questions are from EJB 2.0 and EJB 3.0 and also related to fundamental concept of using Enterprise Java beans. By the way I don't have answer of these Enterprise Java beans questions but I will update the post once I have answers of all these interview questions asked on EJB interviews. This article is divided in two category, in first category we will see some common EJB interview questions and in second category we will see EJB 3.0 interview question, which is more popular now days. I have seen EJB question on companies like Capegemini, TCS, CTS, Infosys and Wipro and mostly on finance domain projects

Java program to read File in Java - Windows UNIX

Java provides java.io  package in JDK API for reading File in Java from File system e.g. C:\ or D:\ drive in Windows or any other directory in UNIX. First, you can use FileInputStream to open a file for reading. FileInputStream takes a String parameter which is a path for the file you want to read. Be careful while specifying File path as path separator is different on Window and UNIX. Windows uses back slash while UNIX uses forward slash as a path separator. By the way, Java supports forward slash in Windows, It means if use forward slash your program will work on both Windows and UNIX. Alternatively, you can also get PATH separator from System property path.separator. In this Java tutorial, we will code example of How to read File in Java.