View RSS Feed

All Blog Entries

  1. Introduction To Collections In Java

    by , 11-08-2011 at 05:56 PM (My Java Tips)
    Framework is a set of classes that acts as a base for building some advanced functionality. It contains super classes having useful functionality and mechanisms which can either be used directly or can be extended in form of subclasses so as to extend the functionality without having to reinvent the basic mechanisms. For example, AWT is a framework for user interfaces.

    The Java collections library is a framework for collection classes. It includes a number of interfaces and ...
  2. More on Collection FrameWork

    by , 11-08-2011 at 05:54 PM (My Java Tips)
    Here we assume that programmer is well aware about the basic concepts of Collections Framework. For more information about basics on Collection Framework click here.
    Now have a look on the classes that implement the " Collection " and " Map " interface.

    As the collection interfaces have a few methods that can be easily implemented from fundamental methods where as abstract classes in the collection framework supply some of these routine implementations. ...
  3. Singleton Pattern

    by , 11-08-2011 at 05:51 PM (My Java Tips)
    A design pattern describes a proven solution to a recurring problem or in other words it is a template for solving problems. Singleton pattern is a creation pattern.

    As the name denotes there will be only an instance of an object, which is created by this pattern. For example: central configuration object should have only one instance that should be accessible from other parts of application. If we have more than one instances of a central configuration object, then different parts ...
    Design Patterns , Java SE
  4. Object Pointer In Java

    by , 11-08-2011 at 05:43 PM (My Java Tips)
    Pointer in C/C++ denotes to the variables saving the reference, In Java there is only call by reference. But here the pointer refers to an object which itself has another reference within it.

    Java classes can have instance variables. If an instance variable is of class type, then it can hold instance of the class in it. This is called pointer to the object.

    In some cases, we need an object that contains an instance variable that can refer to another object of the same ...
    Java SE
  5. How to remove an element from a collection

    by , 11-08-2011 at 05:40 PM (My Java Tips)
    Collections in Java include so many interesting features. As the number of features increase there arise the possibility of incorrect usage. Here we discuss such an issue while removing an object from a Collection. Exception throw is "Concurrentmodificationexception" .


    Java Code:
    package test;import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    public class ListExample
    Java SE
  6. Implementing service method or doGet/doPost

    by , 11-08-2011 at 05: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 ...
  7. Using == or equals() for string comparison

    by , 11-08-2011 at 05: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
  8. Creating UDP Server And Client

    by , 11-08-2011 at 05: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
  9. Implementing Clone Method For HashMap in Java

    by , 11-08-2011 at 04: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
  10. Using Instanceof operator in java

    by , 11-08-2011 at 04: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
  11. Correct way to override equals method in Java

    by , 11-08-2011 at 04: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
  12. Hibernate Queries

    by , 11-07-2011 at 07: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 ...
  13. Defining annotations

    by , 11-07-2011 at 06: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
  14. Asynchronous method calls

    by , 11-07-2011 at 06: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.
  15. Sync4J

    by , 11-07-2011 at 06: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
  16. Path vs ClassPath

    by , 11-07-2011 at 06: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
  17. Behavioral Pattern - Iterator Pattern (Example)

    by , 11-07-2011 at 06: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
  18. Creating MessageDigest

    by , 11-07-2011 at 06: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
  19. Transformations API for XML

    by , 11-07-2011 at 06: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
  20. ANT's best practices

    by , 11-07-2011 at 06: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
  21. in.use file

    by , 11-07-2011 at 06: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
  22. RecordStore with examples

    by , 11-07-2011 at 06: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
  23. Open Resource Window

    by , 11-07-2011 at 06: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: 319
Size:  16.4 KB

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

    by , 11-07-2011 at 06: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
  25. Pom

    by , 11-07-2011 at 06: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
  26. Loading properties from XML file

    by , 11-07-2011 at 05: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 ...
  27. ANT (Example)

    by , 11-07-2011 at 05: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
  28. POM (groupId:artifactId:versi on)

    by , 11-07-2011 at 05: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
  29. Ant exec task

    by , 11-07-2011 at 05: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
  30. Short Message Peer to Peer protocol

    by , 11-07-2011 at 05: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
Page 10 of 17 FirstFirst ... 89101112 ... LastLast