View RSS Feed

All Blog Entries

  1. Implementing service method or doGet/doPost

    by , 11-08-2011 at 06:37 PM (My Java Tips)
    "Whether to implement 'service' method or 'doGet/doPost' in Http Servlet ?" ,Is question often heard at least in the beginners columns.

    Actually the answer depends on the requirement.

    First we should know that the purpose of servlet is to accept an HTTP request from a Web browser, and return an HTTP response. This is done by "service", "doGet\ doPost" methods. Each of these include request object (HttpServletRequest) to receive data from ...
  2. Using == or equals() for string comparison

    by , 11-08-2011 at 06:34 PM (My Java Tips)
    Mostly new Java programmers get confused when comparing strings. You can check the equality of strings either by using "==" or "equals()". But one should know when to use each of these in order to get the required results.

    First, lets talk about "equals() " method. Method "equals()" is included in the class java.lang.Object which every Java class inherit. "equals()" method actually compares the characters that make up String object. ...
    Java SE
  3. Creating UDP Server And Client

    by , 11-08-2011 at 06:29 PM (My Java Tips)
    UDP stands for User Datagram Protocol.

    UDP does not ensure reliable delivery of all the packets, the order in which the packets would be received and it is connectionless too.

    Despite all these UDP provides quick transfer of packets through low-overhead because of an minimal error-checking and correction.

    Java supports UDP through two classes.
    contains a wrapper for an array of ...
    Network Programming
  4. Implementing Clone Method For HashMap in Java

    by , 11-08-2011 at 05:25 PM (My Java Tips)
    Method "clone"creates and returns a copy of the object. It makes another object of the class in memory. Suppose, We are creating a clone of the object x then x.clone() != x will return true but it is not necessary that x.clone().equals(x) will return true. It depends upon the implementation of class.
    Class should implement "Cloneable" interface in order to make clone of its objects. Otherwise "CloneNotSupportedException" will be thrown. Array,HashMap are considered ...
    Java SE
  5. Using Instanceof operator in java

    by , 11-08-2011 at 05:16 PM (My Java Tips)
    Good Java programmers use "instanceof" operator since it is a must to escape from "Class Cast Exceptions".

    Following are the key points to be remembered while using instanceof operator

    Instanceof operator is used to restore full functionality of an object.
    While programming many times heterogeneous collection are used and then to invoke full functionality of an object casting is required then to check the type of instance, "instanceof" ...
    Java SE
  6. Correct way to override equals method in Java

    by , 11-08-2011 at 05:01 PM (My Java Tips)
    Though it is very simple to override "equals" method for a class. But people usually make mistakes in overriding this method. It is very important for a Java developer to know about this method.

    Some Important points to remember

    Always remember to override "hashCode" method if you are overriding "equals" method otherwise you may face problem while using your class with HashTable, HashMap like classes as they uses "hashCode" ...
    Java SE
  7. Hibernate Queries

    by , 11-07-2011 at 08:02 PM (My Java Tips)
    Hibernate is a popular OR (Object Relational) mapping framework. To access database, we have to use Hibernate Query language. I will present the basics in this post that will help you starting query database tables using HQL.

    Hibernate queries can be roughly divided into 3 categories:

    The queries we general use can be divided up into three main categories :

    - Queries using one class
    - Queries which several classes so join operation is required ...
  8. Defining annotations

    by , 11-07-2011 at 07:54 PM (My Java Tips)
    It is right to say that a typical application programmer won't need to define annotations in normal routine. But still, one should know how to define annotations.

    Annotation type declarations are very much like normal interface declarations. An at-sign (@) comes before the interface keyword and each method declaration defines an element of the annotation type. Method declarations should not have any parameters or a throws clause. Also note that the return type should be amoung the ...
    Java SE
  9. Asynchronous method calls

    by , 11-07-2011 at 07:52 PM (My Java Tips)
    Methods called on the asynchronous proxy will be executed asynchronously, and the results can be obtained later on.

    To execute methods asynchronously in EJB 3.0, one can use asynchronous proxy. This allows calling methods at an instance, and collecting the results later. Good thing is that there exist a JBoss extension to EJB 3.0, which allows obtaining asynchronous proxy from the remote or local interface of a stateful session bean, stateless session bean or service bean.
  10. Sync4J

    by , 11-07-2011 at 07:49 PM (My Java Tips)
    To create an implementation of SyncML protocol, you may use sync4j. I will introduce you to sync4j in this post.

    You may download it from:

    Sync4j possesses layered architecture and the layers are:

    Core layer - The actual SyncML handling is done by the core layer. Its responsibilities include XML parsing and conversion of the SyncML markup to an internal object representation. Sync4j can also convert internal ...
    Java ME , XML
  11. Path vs ClassPath

    by , 11-07-2011 at 07:47 PM (My Java Tips)
    I have found may people asking the difference between ClassPath and path. They tend to mix these and find this confusing. I will address this issue in this post.

    Path is simply a system wide variable that tells where to find your commands. Like you can run directory command (dir) from an path. This is so because Windows path is set in the path variable. To see the contents of path variable, use following command on command prompt:

    echo %PATH%

    Java SE
  12. Behavioral Pattern - Iterator Pattern (Example)

    by , 11-07-2011 at 07:45 PM (My Java Tips)
    The aim is to iterate through a collection of data using a common interface and more importantly, underlying implementation should not be known. We have a behavioral design pattern called ‘Iterator Pattern’ for this. I will introduce you to it in this post.

    Iterator should be implemented as an interface. This allows the user to implement it anyway its easier for him/her to return data.
    I will take an example of daily life and will show how to use iterator pattern in that. You ...
    Design Patterns
  13. Creating MessageDigest

    by , 11-07-2011 at 07:42 PM (My Java Tips)
    Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value. Thing to remember is that it I s not any encryption technique. It’s simply hashing. Same message will always generate the same hash code and a slight change in the message will generate completely different hash code. In the next few posts, I will talk about how we can generate message digests in our Java programs.

    The popular message digest algorithms are MD5 and ...
    Java SE
  14. Transformations API for XML

    by , 11-07-2011 at 07:36 PM (My Java Tips)
    In the next few posts, I will write about how to perform an XSLT transformation using StAX APIs: Cursor API and Event Iterator API.

    TrAX (Transformations API for XML) is a Java API for performing XSLT transformations. In J2SE 1.5, there are three different ways to represent the source and the result of an XSLT transformation and they are: by XML stream source/result, by SAX events source/result, and by DOM tree source/result. In J2SE 1.6 an XSLT transformation is performed using a ...
    Java SE , XML
  15. ANT's best practices

    by , 11-07-2011 at 07:28 PM (My Java Tips)
    ANT makes building complex Java applications easier. But many people argue that managing ANT scripts is itself a cumbersome task and involves a lot of effort. In the next few posts, I will talk about how one can adopt best practices for creating and managing ANT scripts that will make the life of developers and configuration managers easier.

    First thing is, one should follow a consistent style while writing XML for ANT files. If you format your ANT script, it will be visually appealing ...
    Ant , XML
  16. in.use file

    by , 11-07-2011 at 07:17 PM (My Java Tips)
    A lot of J2ME developers face problems when running multiple instance of Nokia Wireless Toolkit emulators. Some of the problems are linked with in.use file. This post is all about that.

    When your run the emulator, a file named in.use is created in the emulator’s root directory with will be something like:


    This file is removed when the emulator shuts down.

    This emulator’s default directory will also ...
    Java ME
  17. RecordStore with examples

    by , 11-07-2011 at 07:15 PM (My Java Tips)
    I will use several examples to show how to use RecordStrore in J2ME applications.

    Creating record store is simple. We use a static method to create or open an existing record store.

    Java Code:
    public static RecordStore openRecordStore(String recordStoreName,
                                              boolean createIfNecessary)
                                       throws RecordStoreException,
    Java ME
  18. Open Resource Window

    by , 11-07-2011 at 07:08 PM (My Java Tips)
    Eclipse provides a window called ‘Open Resource’ window to locate the required files in no time.

    You can find it under the Navigate. Its shortcut is Ctrl+Shift+R. ‘Open Resource’ window allows you to type a search for any file that exists in your workspace. You are free to use wildcards like ? to replace a single character or * to replace an entire string. It is amazingly fast and useful.
    Name:  openresource.PNG
Views: 257
Size:  16.4 KB

    Let me present a use case. ...
  19. Using property files

    by , 11-07-2011 at 07:05 PM (My Java Tips)
    To make your Java applications flexible, you might want to give properties that keep on changing in properties file. A property file is simply a text file that has key-value pairs relation.

    If you are thinking of writing your parser to read the property files, then think again. Java provides java.util.Properties class, that will help you deal with propery files. Property files comprise of key-value pairs in a file, where the key and value are separated by an equal ...
    Java SE
  20. Pom

    by , 11-07-2011 at 07:01 PM (My Java Tips)
    Maven uses an XML project descriptor to generate the object model for project. This file is POM.XML and should be located at the top level directory of the project.

    The XML file contains all the needed information for the project. Apart from core information, it also contains groupid, version, name and all the libraries needed for the project.

    <artifactid>junit</artifactid> ...
    Maven , XML
  21. 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 ...
  22. 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. ...
    Ant , XML
  23. 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
  24. 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
  25. 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
  26. 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. ...
  27. 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

  28. 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
  29. 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
  30. 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
Page 10 of 17 FirstFirst ... 89101112 ... LastLast