View RSS Feed

All Blog Entries

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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 ...
  8. 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 ...
  9. 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 ...
  10. 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
  11. 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
  12. 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 ...
  13. 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 ...
  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 ...
    Eclipse , EJB , Java EE , JBoss , JSF
  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 ...
    Java EE , JBoss , Hibernate
  16. 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 ...
    Hibernate , XML
  17. 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 ...
  18. 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
  19. 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
  20. 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:
  21. 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 ...
  22. 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 ...
  23. JMS - Request – Reply Model

    by , 11-05-2011 at 07:51 PM (My Java Tips)
    This model is used when real time response is required. JMS provides two API to implement Request – Reply model which are QueueRequester and TopicRequester.

    You may use this is you wish to use QUEUE. It creates a TemporaryQueue for the responses and provides a request() method that sends the request message and waits for its reply.

    This API uses TOPIC to get responses. It creates a TemporaryTopic for the responses ...
  24. Entity (Tips/Info)

    by , 11-05-2011 at 07:47 PM (My Java Tips)
    In this post, I will present some useful information about Entities. I hope these will prove useful.

    You may indicate the entity class by annotating it with the Entity annotation or you may denote that class as entity in the XML descriptor. The entity class must have no-arg constructor and it should either be public and protected. The entity class can have other constructors as well.

    Another important thing to note about entity class is that the entity ...
  25. Sample Entity Bean

    by , 11-05-2011 at 07:45 PM (My Java Tips)
    Creating entity bean is simple. You have to annotate the class to indicate that it’s an entity bean. Also your class should implement Serializable interface. An example entity bean is presented below. Do note that we have defined a no argument constructor which is a must.

    Java Code:
    public class Customer implements Serializable {
    private Long id;
    private String name;
    private Address address;
    private Collection
  26. Managing dependencies using Maven

    by , 11-05-2011 at 07:42 PM (My Java Tips)
    Maven can manage all jar file dependencies for the build machines. Let me explain how to do this.

    We use dependency element to refer to a jar file which reside in a remote repository. It is said that in near future, the dependencies will extend beyond jar files. Maven places the jar files (fetched from remote repository) on the local repository. The element has three child elements, , , and . Maven looks in the remote repository for a directory with the same name as ...
    Maven , XML
  27. 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 ...
    Eclipse , Java EE , JBoss
  28. Eclipse - Show View

    by , 11-05-2011 at 07:35 PM (My Java Tips)
    Java developers working in Eclispe should be aware of the windows that Eclipse provides for assistance. You may turn them on/off when ever required.

    Select Window > Show view from menu bar to see the available views.Name:  eclipse_views.PNG
Views: 377
Size:  34.5 KB

    Once you have a view, you can slide it to the appropriate place you want. I agree that it will take some space and this will reduce your working area. But can always minimize a view. Also, double clicking the view ...
  29. Jboss port numbers

    by , 11-05-2011 at 07:32 PM (My Java Tips)
    While working with JBoss, you must have experienced port-number collision. JBoss is does not tell ports are in use, which services are using those and how you can change them. I will try to provide some useful information in this post.

    In this post, I will talk particularly about JBoss version 4.03. All file references are relative to $JBOSS_HOME/server/default. Do assume that we are working with default configuration.

    File: $JBOSS_HOME/server/default/deploy/jbossweb-tomcat50.sar/server.xml ...
  30. 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
Page 42 of 48 FirstFirst ... 324041424344 ... LastLast