View RSS Feed

Java EE

Java Enterprise Edition

  1. Using the DocumentBuilderFactory

    by , 11-28-2011 at 08:02 PM (My Java Tips)
    In this post, I will present an example to show how to use the DocumentBuilderFactory.

    First step is to import the required classes.

    Java Code:
    // JAXP
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.DocumentBuilderFactory;
    Java EE
  2. Working with the DOM parser

    by , 11-28-2011 at 07:59 PM (My Java Tips)
    You will be introduced to the working of DOM parser in this post.

    We can get a DocumentBuilder instance as soon as we have a DOM factory. The methods available for the DocumentBuilder instance are very similar to those available to its SAX counterpart. But there is a slight difference when we talk about the parse() method. The parse method in case of DOM do not take an instance of the SAX DefaultHandler class. It returns a DOM Document instance representing the XML document that was ...
    Java EE
  3. Reading RSS using Informa API

    by , 11-28-2011 at 07:56 PM (My Java Tips)
    RSS (Really Simple Syndication) is a family of Web feed formats used to publish frequently updated content such as blog entries, news headlines, and podcasts. It is actually a specification for XML files to provide syndicated data.

    To read RSS feeds in a Java application is easy. You have to use Informa API which is availabel at:

    The code snippet given below shows how to read RSS using Informa API.

    Java Code:
    try {
    Tags: informa, rss Add / Edit Tags
    Java EE
  4. Using the JAXP validation framework

    by , 11-28-2011 at 07:29 PM (My Java Tips)
    While working with XML documents, you need to validate the documents. You may use setValidating() method on a SAX or DOM factory. But Java 5.0 (JAXP 1.3) introduces JAXP validation framework which can also be used for validating XML documents.

    Using the JAXP validation framework is fairly simple and efficient. In JAXP 1.3, the validation is broken out into several classes within the new javax.xml.validation package. Lets go through the steps:

    1. Load the model in to ...
    Tags: dom, java 5.0, jaxp, sax Add / Edit Tags
    Java EE , XML
  5. JAXP SAXParser class

    by , 11-28-2011 at 07:19 PM (My Java Tips)
    You can doa lot if interesting stuff once you have the instance of SAXParser class. I will introduce a code snippet that will show you what you can do with an instance of SAXParser.

    JAXP provides methods to determine the parser's settings. For instance:

    use this method to see if the parser will perform validation or not

    use this method to determine if the parser can process namespaces in an XML document ...
    Java EE
  6. SAXParserFactory Example

    by , 11-28-2011 at 07:17 PM (My Java Tips)
    To change the parser implementations, JAXP provides a class called SAXParserFactory. I will present an example that will show how to use this class.

    First thing is to create an instance of SAXParserFactory. After creating the new instance, we have to get he SAX-capable parser. For thos, factory provides a method. Good thing is that the JAXP implementation takes care of the vendor-dependent code and thus keeps the code clean. This factory has some other nice features, as well. Do explore ...
    Java EE
  7. Introduction to JAXP

    by , 11-28-2011 at 07:14 PM (My Java Tips)
    If you want to process XML data using applications written in the Java programming language, then JAXP is the best choice. JAXP stands for Java API for XML Processing. I will introduce JAXP in this post.

    JAXP can be called an abstraction layer since it does not introduces any new way to parse XML documents nor it provides different way of handling XML documents. Actually it makes using DOM and SAX easier. Using JAXP, you may habdle vendor-specific tasks that may arise when dealing ...
    Tags: dom, jaxp, sax Add / Edit Tags
    Java EE
  8. EJB - Entity Beans

    by , 11-26-2011 at 07:39 PM (My Java Tips)
    This post contains an introduction to Entity Beans.

    An entity beans are used to represent a business object in a persistent storage mechanism for example: customers, orders, products, employees etc. We normally refer persistent storage mechanism as a relational database. Normally, each entity bean has an underlying table in a relational database. Please note that each instance of the bean corresponds to a row in that table.

    Some people mix Entity beans with session ...
    Java EE
  9. Accessing Beans (EJB)

    by , 11-26-2011 at 07:36 PM (My Java Tips)
    In the post, I will write about how to accessing a bean in EJB.

    Accessing deployed beans is simple. First write the the client code and set up JNDI environment settings for the client. It can be done via a JNDI properties file. Now you have to set the class path for the client and add the following file locations to it:

    jboss-client.jar, jnp-client.jar, EJB interfaces, and the directory where the JNDI properties file is stored

    Remember, two JNDI settings ...
    Tags: beans, ejb, jndi Add / Edit Tags
    Java EE
  10. JBoss Application Server

    by , 11-26-2011 at 07:35 PM (My Java Tips)
    Talking about J2EE application servers, JBOSS is a popular choice. The reason is that JBOSS is open-source EJB solution with lot of impressive features that are missing in Weblogic, WebSphere, and the other big players.

    Some of the interesting features provided by JBOSS are:

    - enterprise-class security
    - transaction support
    - resource management
    - load balancing
    - clustering
    - database connection pooling
    - JavaMail support ...
    Tags: ejb, jboss Add / Edit Tags
    Java EE
  11. Handling Cookies in JSP

    by , 11-20-2011 at 06:04 PM (My Java Tips)
    Cookies are text files that are downloaded onto a visitor's hard drive to store the visitor's actions in order to better
    customize their following visits. We may handle cookies in JSP and I will show you how to do that.

    JSP provides an implicit response object which is used to add cookies. To add a cookie to the response, addCookie method is used.
    We may store useful information in cookies for later use and this method is perfect for our needs.
    Java Code:
    Java EE , JSP
  12. Checking if Session is new

    by , 11-19-2011 at 07:26 PM (My Java Tips)
    Sessions are used to keep track of the user in applications. Specifically talking about web applications (JSP), we may store objects in the session as well for using them later. Sometimes we wish to know if the session is new or not. This post will show how to do that.

    If a session is new, then isNew method of session object will return true otherwise false. When a server creates a session and client has not yet acknowledged the session, the server marks it with new. When the client ...
    Tags: isnew, sessions Add / Edit Tags
    Java EE , JSP
  13. Sending files from Servlet

    by , 11-15-2011 at 07:35 PM (My Java Tips)
    In this post, I will present an example which will show how to move the selected file (drop down menu) form a servlet to another servlet which performs operations on the file.

    I have created 3 Javafiles namely:

    - HelloServlet(Servlet)
    - GetImg (Servlet)
    - ImgCompare (simpleJava class)

    HelloServlet contains a HTML form that has a dropdown menu. Menu contains 2 JPG files. You should have following images at the given path:

    C:\image1.jpg ...
    Java EE
  14. Preparing development environment for J2EE dev/JBoss

    by , 11-06-2011 at 06:25 PM (My Java Tips)
    I will show how to prepare development environment for J2EE development using JBoss. Download and install the JBoss. I will be using jboss-4.2.2.GA. Now download the latest Java EE Eclipse from I have version 3.3.2.

    You should have all the required plugins for J2EE development with JBoss in your Eclipse. Navigate to:

    Help > Software updates > Find and Install > Search for new features to install > New remote site

    You can name ...
    JSF , Eclipse , EJB , Java EE , JBoss
  15. Jboss-4.0.2 hibernate bug

    by , 11-06-2011 at 06:21 PM (My Java Tips)
    Hibernate is a popular persistence engine that runs in almost any application server and provides alternative of standard entity beans. With JBoss, you can choose to deploy your application as a Hibernate archive, called a HAR file. This makes using hibernate simpler. JBoss is responsible for managing hibernate session and other configuration details.

    Jboss-4.0.2 does not include Hibernate3 integration module. This requires Apache commons collections JAR. To fix this, use fix-hibernate ...
    Hibernate , Java EE , JBoss
  16. jboss-service.xml

    by , 11-06-2011 at 06:16 PM (My Java Tips)
    JBoss core services are listed in conf/jboss-service.xml file. These services are started first when the server starts up. You may open the file in any test editor or in some XML editor. You will see MBeans for various services including logging, security, JNDI. You may comment any service for example:

    Now if you restart JBoss, you wont see the JNDIView service in the management console listing. In normal practice, you very seldom needs to alter this file. Remember that the ...
    Java EE , JBoss
  17. Debugging Remote Java Application

    by , 11-05-2011 at 07:38 PM (My Java Tips)
    Debugging is very helpful is following the flow of an application and knowing what happens when. You get list of variables with their values and you can flow what exactly is happening. It really helps is identifying the problem areas. Debugging in Eclipse is really simple and easy. I assume that you have done debugging in Eclipse.

    Debugging a J2EE application is a bit tricky since the application is deployed in web/application container. JBoss provides support for ...
    JBoss , Eclipse , Java EE
  18. Deploying WAR on JBOSS

    by , 11-04-2011 at 07:52 PM (My Java Tips)
    I will present simple steps to create a web application (WAR) and will show how to deploy a WAR on JBOSS.

    Let me start from installing Java.

    Run the installer and install Java at: "C:\Program Files\Java\jdk1.6.0_06\". An important thing to note is that JBoss, requires the full JDK which contains the JRE along with some additional stuff like javac compiler.

    Next step is to install JBoss. Go to the ...
    Java EE , JBoss
  19. @Stateful (Stateful session bean)

    by , 11-03-2011 at 07:34 PM (My Java Tips)
    @Stateful annotation is used to represent stateful session bean. These beans are used to maintain conversational state across method invocations, then use stateful session beans. As the name implies, these beans maintain the internal state. For instance: Online shopping is an example of stateful session bean. We need to maintain the state of the bean when the customer adds/removes items from the cart.

    An example of stateful session bean is presented below:

    Java Code:
    EJB , Java EE
  20. Using @Stateless

    by , 11-03-2011 at 07:25 PM (My Java Tips)
    Stateless session beans are those, who do not keep track of the information that is passed from one method call to another. Thus, they donít have internal state and each invocation of a stateless business method is independent of its previous invocation. These beans are simple to manage for the container. For example: tax calculation is a business task and we can have a bean for that. It will simply calculate the tax for an employee. It can be a stateless session bean since each time we call it, ...
    EJB , Java EE
  21. Broken Pipe - Transaction

    by , 10-31-2011 at 05:51 PM (My Java Tips)
    I assume that you are having a J2EE environment with connection pool and you are using hibernate.

    When you use transactions, you have to explicitly commit or rollback every time. Some programmers believe that queries do not have to be committed. This is not right in my opinion. If you do not commit, the connection is left assigned. Which means we have dangling connections that later will be killed by the database server like: MySQL. Connection pool would later attempt to reattach ...
  22. Using pagging techniques

    by , 10-30-2011 at 06:59 PM (My Java Tips)
    When displaying long lists on the web, we use paging techniques. In this post, I will show how to do that.

    Normally we display 10 or 15 results at a time and the user can scroll through the list. If list is a long one, then it does not make an sense to loat it completely. Loading the complete list in session and then loop through the results is not a nice approach. An approach can be to use pagination tags which means fetching and displaying the results one page at a time. Pagination ...
    Java EE , JSF , JSP
  23. Writing deployment descriptor

    by , 05-25-2011 at 10:57 AM (My Java Tips)
    If you writing J2EE applications, you need to deploy your application to J2EE container like JBOSS. I will shed some light on how to write simple deployment descriptors for your web applications.

    I am deploying my JSP application on JBOSS. For JBOSS, we need to put our application in WAR format in deploy folder. So deployment descriptor will have following 2 tasks:

    1. Archieve the application into WAR
    2. Copy that WAR to deploy folder of JBOSS

    Assuming ...
    Tags: j2ee, war Add / Edit Tags
    Java EE , JBoss
  24. Remote Debugging

    by , 05-21-2011 at 11:31 PM (My Java Tips)
    Ever wanted to launch a Java program from a network computer and debug it from the workstation running the Java platform? Example scenario is that you have an a J2EE application deployed on a dedicated server and you need to do debugging on you machine. This can be done if Java VM that supports this feature.

    To do this, launch the program in debug mode on the remote machine. It means that the program on server will wait for a connection from your debugger. Now start the debugger ...
    Java EE , JBoss
  25. JNDI - Introduction

    by , 05-21-2011 at 11:20 PM (My Java Tips)
    JNDI is a standard Java API that comes with JDK 1.3 and higher. It provides a common interface to a variety of existing naming services for example DNS, LDAP, Active Directory, RMI registry, COS registry, NIS, and file systems.

    The JNDI API is divided logically into a client API and service provider interface. Client API is used to access naming services and a SPI allows the user to create JNDI implementations for naming services.
    The naming service providers must implement ...
    Tags: jndi Add / Edit Tags
    Java EE , JBoss
  26. The JNDI API

    by , 05-21-2011 at 11:18 PM (My Java Tips)
    JNDI API package is called javax.naming package. It is composed of 5 interfaces, 10 classes along with few exceptions. InitialContext is the key class.

    This is what Sun Java Docs say about InitialContext:
    Java 2 Platform SE v1.3.1: Package javax.naming

    In JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore JNDI defines an initial context, InitialContext, which provides a starting point for naming ...
    Tags: jndi Add / Edit Tags
    Java EE , JBoss
  27. Using reflection QueryRequestTag

    by , 05-21-2011 at 10:51 PM (My Java Tips)
    This post presents an example that show use of reflection in creating a tag. The created tag will call some methods of the request (HttpServletRequest) object using reflection.

    Source code for the QueryRequestTag handler is presented below:

    Java Code:
    public class QueryRequestTag extends ExTagSupport {
        static Object []params = new Object[0];
        static Hashtable methods = new Hashtable();
        static LocalStrings ls =
  28. Tags and JavaBeans

    by , 05-21-2011 at 10:42 PM (My Java Tips)
    We use tags and beans to fetch data from the bean and present it. If you have some knowledge about these, then you will love working with these.

    Bean interaction involves JSP getting the value of some property of a bean and displaying that value to the user. Another role of JavaBean is defining how events are specified. Tags can be concerned with two bean-related issues:

    • Introspecting the beans to find the properties and get the methods that these tags should call
    Tags: javabean, tag Add / Edit Tags
    Java EE