View RSS Feed

My Java Tips

  1. Loading properties from XML file

    by , 11-07-2011 at 06:58 PM (My Java Tips)
    In this post, I will present how to read properties from XML files.

    We have following XML file with the required properties:

    <!--?xml version="1.0" encoding="UTF-8"?-->
    <entry key="mode">alpha</entry>
    <entry key="entertaionment">movie</entry>
    DTD for the XML file ...
  2. ANT (Example)

    by , 11-07-2011 at 06:55 PM (My Java Tips)
    This post is all about an ANT example. I will present an ANT build script that will compile a project, and will generate a JAR file.

    I will name the project as Project X and will provide some useful description.

    <!--?xml version="1.0"?-->
    <project default="dist" name="Project X">
    <description>Test project</description>

    Now is the time to define the properties. ...
    XML , Ant
  3. POM (groupId:artifactId:versi on)

    by , 11-07-2011 at 06:22 PM (My Java Tips)
    A project object model (POM.xml) contains all necessary information about a project like configurations of plugins involved. You might be thinking about Ant build file. You may embed ant tasks inside the POM. A build.xml tells Ant precisely what to do when it is run, a POM states its configuration.

    A POM in simplest form is given below:

    xsi:schemaLocation=" ...
    Maven , XML
  4. Ant exec task

    by , 11-07-2011 at 06:19 PM (My Java Tips)
    To execute a system command from Ant, exec is used. Since different operating systems have different commands, therefore OS commands (if used), will restrict the build script to a particular operating system.

    One cannot interact with the forked program and if any attempt to read input in the forked program is made, an EOF (-1) will be thrown.

    The task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. Generally, batch files (.bat) cannot by executed ...
    Ant , XML
  5. Short Message Peer to Peer protocol

    by , 11-07-2011 at 06:14 PM (My Java Tips)
    SMPP is a communication protocol designed for transfer of short messages between short message centre and SMS application.

    Some useful points about SMPP are listed below:

    - Binary encoded protocol data units are exchanged in request and response.
    - Transceiver support is added in version 2.4, which allows a single connection to send and receive messages.
    - Data exchange can be synchronous or a synchronous.

    External Short Message Entities ...
    Java ME
  6. Subclipse - changing user credentials

    by , 11-07-2011 at 06:11 PM (My Java Tips)
    Subclipse is a very popular Eclipse plugin which provides SVN repository supports within Eclipse. It serves the purpose but there is no real way to change the SVN user for a repository if credentials are saved. I will try to address this problem in this post.

    First of all, why you would need to change the svn user credentials? Person A is working on your machine and he checks out a project from a SVN repository using his credentials. He saves his SVN credentials in your Eclipse environment. ...
  7. Linking files with Editor

    by , 11-07-2011 at 05:50 PM (My Java Tips)
    There is a very useful Eclipse feature that is normally not used by the developers. Its called ‘Link with Editor’. I'll write about it.

    In complex projects, lot of files are involved. To search a rile, you may use Open Resource window – which is really very useful. Then you may click the file and can see/modify the contents. You might want to see where the file lies in the project. Obviously lots of folders are involved and its not easy to manually search for the file. You can simple ...

    Updated 11-07-2011 at 06:09 PM by Java Tip

  8. Fetching contact field (PIM)

    by , 11-06-2011 at 07:07 PM (My Java Tips)
    Each contact entry in a PIM Contact database is represented by Contact. This post is all about retrieving contact fields from PIM.

    The supported field list for a Contact depends on vCard specification from the Internet Mail Consortium. These set of fields included in this Contact class provides relevant information about a contact. ContactList restricts what fields a Contact can retain. This reflects that some native Contact databases do not support all o the fields available in a ...
    Java ME
  9. PIM - ToDo

    by , 11-06-2011 at 07:04 PM (My Java Tips)
    javax.microedition.pim.ToDo is an interface that extends from PIMItem. It represents a single ToDo item in a PIMToDo database. I will present an example of how to retrieve ToDo list from PIM.

    Consider the following example. We create todos with fields of our interest. But before adding the field,w e should check if its supported on the platform or not.

    Java Code:
    ToDoList todos = null;
     try {
        todos = (ToDoList) PIM.getInstance().openPIMList(PIM.TODO_LIST,
    Java ME
  10. Error codes lookup

    by , 11-06-2011 at 07:02 PM (My Java Tips)
    There are sometimes situations, when you need some look up mechanism. I will present few example in the next few posts.

    Let me present an scenario. We have an application which reads and writes to files on a file system. We have defined a error generating and tracking mechanism as well. Each error is assigned an error code and that code is thrown in case an error is encountered. To Interpret the code, we need to have some lookup mechanism.

    I defined a final class with ...
    Java SE
  11. Benefits of using Final class

    by , 11-06-2011 at 06:58 PM (My Java Tips)
    Final classes have a lot of benefits if used where required. I will present benefits of final classes in this post.

    Sometimes, you wish that no one can inherit from your class since its functionality is completed and should not be inherited. In that case, you may define your class as final, and then no class can inherit from it. The method of final class are also final. Final methods cannot be overridden in any sub class. There is also performance issues related to final class. A ...
    Java SE
  12. Final variables

    by , 11-06-2011 at 06:57 PM (My Java Tips)
    A final variables in Java are can only be assigned once. Once they are assigned some value, they cannot be assigned some other value.

    If you have final class variable, they must be assigned to in the constructor of the class. An interesting thing is that the value of a final variable is not necessarily known at compile time. Consider the following example:

    Java Code:
    public class Sphere {
        public static final double PI = 3.141592653589793;
    Java SE
  13. Using a custom task in Ant

    by , 11-06-2011 at 06:53 PM (My Java Tips)
    It is assumed that you have already defined a custom Ant task and wish to use it. In this post, I will show you how to do so.

    You first need to define the task by giving it a name and telling Ant the classfile that implements it and any classpath setting required to locate that classfile. This is done using the taskdef task, like so:

    <taskdef name="fileparser">classname="FileParser"
    classpath="."/&gt; ...
    Ant , XML
  14. Defining custom tasks in ANT

    by , 11-06-2011 at 06:49 PM (My Java Tips)
    Ant provides various core and optional tasks which you use to automate the build process. Very seldom, you need to define your own customized tasks.

    To implement a simple custom task, you need to extend the class and override the execute() method. Follow the sample below:

    Java Code:
    public class FileSorter extends Task {
    // The method executing the
  15. JBossWS

    by , 11-06-2011 at 06:47 PM (My Java Tips)
    JBoss used to have JBoss.NET package for web services. Now, there exists JBossWS module which is responsible for providing web services in JBoss 4.0.

    It is based on Apache Axis like JBoss.NET but the difference is that JBossWS provides the complete set of J2EE 1.4 web services technologies like SOAP, SAAJ, JAX-RPC and JAXR. The J2EE web services support exposing EJBs as web services, but only stateless session beans can be used.

    JBossWS is a JAX-WS compliant web service ...
  16. JBoss directory structure

    by , 11-06-2011 at 06:45 PM (My Java Tips)
    You should be knowing the directory structure of JBoss server, in order to work efficiently with JBoss. I will target the directory structure in this post.

    The jboss-4.0.2 directory contains following sub-directories:

    Contains startup and shutdown scripts.

    Client folder contains configuration and JAR files that are required by Java client application or an external web container.

    The XML DTDs used in ...
  17. SVN (Trunk/Branch/Tag)

    by , 11-06-2011 at 06:41 PM (My Java Tips)
    SVN (SubVersion) is being used in software development houses to maintain the source code. Its very effective if used properly. In this post, I will present some basic concepts about SVN.

    Usually, SVN has following directory structure:


    You may add more directories like archive and some other of you want. I will explain the use of above directories so you know when to use what.

    The trunk directory contains ...
  18. Writing System Properties

    by , 11-06-2011 at 06:35 PM (My Java Tips)
    System's setProperties() method can be used to modify existing system's property. It takes a Properties object that has been initialized to contain the key/value pairs for the properties that you want to set.

    This method actually replaces the entire set of system properties with the new set Properties object. Lets review an example that creates a Properties object,initializes it from a file and then uses System.setProperties() to install the new Properties objects ...
    Java SE
  19. Environment Variables

    by , 11-06-2011 at 06:31 PM (My Java Tips)
    Environment variables are used by operating systems to pass useful information (configurations) to the applications. Environment variables are key/value pairs very much like properties. The key and the value, both are strings. To set environment variables, please read system documentation as it varies from one operating system to another.

    In our Java applications, we use System.getEnv to retrieve environment variable values. If no argument is passed, getEnv will return ...
    Java SE
  20. Java built-in data types (performance issues)

    by , 11-06-2011 at 06:29 PM (My Java Tips)
    Java built in data types provide programmers ease of storing their required data in appropriate data type. But in come cases, it may become a bottleneck. When doing low level related work, the speed is very important. In such case don't use the Java built-in data types.

    Lets take an example. If you are using an Integer class, just think of all the overhead you are creating by using the wrapper class. One rule of thumb is to use the primitives instead of wrapper. This ...
  21. JBoss – Web Container

    by , 11-06-2011 at 06:27 PM (My Java Tips)
    I assume you are familiar with Tomcat. Normally developers start learning J2EE with Servlet and JSP and deploy them on Tomcat. JBoss now comes with Tomcat 5.5 and is used as default web container.

    The embedded Tomcat service is the expanded SAR jbossweb-tomcat55.sar in the deploy directory. All the required JARs also exist there. The file web.xml provides default configuration set for web applications. server.xml, which contains standard Tomcat format configuration information. This ...
  22. 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 ...
    Eclipse , EJB , Java EE , JBoss , JSF
  23. 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
  24. Creating a Hibernate archive

    by , 11-06-2011 at 06:20 PM (My Java Tips)
    Consider a simple POJO with no direct coupling to Hibernate. The details of the Hibernate mapping will be specified in the Player.hbm.xml file.

    Player.hbm.xml is shown below.

    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    <class name="org.jboss.roster.Player" table="PlayerBean">
    <id ...
    XML , Hibernate
  25. Using the hibernate objects

    by , 11-06-2011 at 06:18 PM (My Java Tips)
    I assume that you know how to create hibernate archive and you have created a fully configured SessionFactory for use in other parts of your application. I will present an simple JSP which creates a Session from the SessionFactory and issues a query directly.

    It’s a good practice to put the Hibernate access code in a servlet or in a
    session bean, but for example purposes I will use JSP.

    The example shows how to access Hibernate session in the ...
  26. 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
  27. JBoss - Logging Service

    by , 11-06-2011 at 06:13 PM (My Java Tips)
    Jboss uses Apache logging application called log4j for logging. You can find log4j.jar under lib director. The logging service is enabled from jboss.service.xml.

    The file will read like this:

    <!-- ================================================== ================== -->
    <!-- Log4j Initialization -->
    <!-- ================================================== ================== --> ...
    JBoss , XML
  28. Using Maven - Unit Tests

    by , 11-05-2011 at 08:00 PM (My Java Tips)
    You want Maven to compile your unit tests. Simply place you unit tests in a directory and mention the director under


    Once that is done, specify the unit tests which you want to run in unitTest XML element. You may use includes and excludes tags to include or exclude the classes.

    Java Code:
  29. Documenting projects

    by , 11-05-2011 at 07:58 PM (My Java Tips)
    Everyone know how important it is to document the project. I wont be shedding light on this. But the aim of this post is
    to introduce how Maven can help you generate project documentation.

    Maven can actually generate a website for your project. Use following command to generate documentation:
    Run the site:generate goal for your project with this command:

    maven site:generate

    Maven will generate html documentation in the docs ...
  30. JMS - Publish-Subscribe Messaging

    by , 11-05-2011 at 07:55 PM (My Java Tips)
    Programs can create, send and read messages in distributed enterprise environment using MOM (Message-Oriented-Middleware). The Java Message Service (JMS) provides a standard Java-based interface to the message services of a MOM of some other provider.

    There are few messaging models available which determine which client receives the message.
    Publish-Subscribe Messaging
    Point-To-Point Messaging
    Request-Reply Messaging

    Lets first talk ...
Page 9 of 15 FirstFirst ... 7891011 ... LastLast