View RSS Feed

My Java Tips

  1. 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 ...
  2. 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 ...
  3. 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
  4. 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
  5. 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
  6. 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: 449
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 ...
  7. 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 ...
  8. 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
  9. Debugging - All references of a class/object

    by , 11-04-2011 at 07:48 PM (My Java Tips)
    Consider the following scenario. You have a class and you with to see all the references of it. It’s definitely worth seeing that. Eclipse 3.3 provides this functionality.

    Mark a class (whose references you want to see) in the Java editor and choose All Instanced from the context menu.

    If you want to display references of the specific object, follow the following procedure:

    In the Variable window, right click on the object and choose All References. A ...
  10. Eclipse - Classpath variables

    by , 11-04-2011 at 07:46 PM (My Java Tips)
    A classpath variable can be added to a project’s class path. It can be used to define location of a JAR file that is not the part of workspace. Non modifiable class path variables are set internally like JRE_LIB, JRE_SRC, JRE_JRCROOT.

    To define a class path variable in Eclipse, open preferences by clicking Window > Preferences from the menu bar. You will find class variables under Java > Build Path. There you can define new class variables.

    Name:  eclipse-classpath.PNG
Views: 559
Size:  16.2 KB ...
  11. Eclipse Debugging

    by , 11-04-2011 at 07:44 PM (My Java Tips)
    Following are Eclipse debugging features: Breakpoints, Step into, Step over, Step return, Step Filters, Watches, Run to line, Suspend/Resume/Terminate. You should know each of these for debugging your Java programs. I will try to introduce these in the next few posts.

    We use breakpoints in our Java source to cause the thread of execution to suspend and return to the debugger. To set breakpoints in Eclipse, simply double-click the left margin.

    Use ‘Step Into’, to execute ...
  12. Java Applets - lifecycle

    by , 11-04-2011 at 07:38 PM (My Java Tips)
    I plan to talk about applet lifecycle in the next two posts.

    Applets have following 4 methods.

    Java Code:
    public void init();
    public void start();
    public void stop();
    public void destroy();
    init method is used to initialize the applet each time it's loaded (or reloaded).
    start method to start the applet's execution, such as when the applet is loaded or when the user revisits a page that contains the applet.
    stop to stop ...

    Updated 11-04-2011 at 07:40 PM by Java Tip

    Java Applets
  13. Viewing all breakpoints

    by , 11-04-2011 at 07:36 PM (My Java Tips)
    In this post, I will talk about how to view all the breakpoints in a project/workspace.

    You set breakpoints for debugging. If you have too many of them, then it becomes difficult to manage those. At some point, you would like to see all the breakpoints in a view so you can remove the unwanted ones. Eclipse has a breakpoints view. You can find it under:

    Windows > Show View > Other > Debug > Breakpoints

    Name:  breakpoints.PNG
Views: 247
Size:  16.5 KB
  14. Checkout - out of disk space

    by , 11-04-2011 at 07:34 PM (My Java Tips)
    I would like to highlight a problem which many developer face while check outing a project from SVN.

    Consider that you are check outing a project from SVN comprising of many folders. During checkout process, you run out of disk space or you computer breaks down of any reason. What you think of checked out project? There will be few files/folders left to be checked out. Also it is possible that fvew files are corrupted. The solution is to fist make sure you have enough free space on ...
  15. Iterating using for loop

    by , 11-04-2011 at 07:32 PM (My Java Tips)
    Guys, who are new to Java will find this post interesting. I will present for loop with examples.

    Use for loop when you know the maximum number of times you have to iterate in advance or backwards.

    Java Code:
    for ( int i=0; i   {
       System.out.println( i );
    for ( int i=n-1; i>=0; i-- )
       System.out.println( i );
    You may increment 2 variables in the for loop as shown below: ...
    Java SE
  16. Spanning arrays

    by , 11-04-2011 at 07:29 PM (My Java Tips)
    There are different ways to span an array. I will present few of them here.

    This simplest way is to use a for loop as shown:

    Java Code:
    String[] stuff = new String[ 10 );
    for ( int i=0; i   {
       String s = stuff[i];
       System.out.println( s );
    Java 1.5 introduces a new for of for loop and can also be used to span an array.

    Java Code:
    String[] stuff = new String[ 10 );
    for ( String s :
    Java SE
  17. Enumeration/Enum Spanning

    by , 11-04-2011 at 07:25 PM (My Java Tips)
    Spanning enum in Java 1.5 is easy using for loop.

    Java Code:
    for ( Breed dog : Breed.values() )
       System.out.println( dog );
    Let me show hot to span an enumeration.

    Java Code:
    for ( Enumeration e = props.propertyNames(); e.hasMoreElements(); )
       String key = (String) e.nextElement();
    Java SE
  18. Removing elements from a List

    by , 11-04-2011 at 07:20 PM (My Java Tips)
    You may use Iterator to remove elements from a List (ArrayList, LinkedList etc.) efficiently. You must be aware that you cannot remove elements from a List using for:each.

    Other approach is to get and them remove the elements which is not that efficient.

    Java Code:
    for ( Iterator iter = items.iterator(); iter.hasNext(); )
       Item item =;
       if ( item.isUnwanted() )
           // remove from underlying Collection
    Java SE
  19. Colapse all

    by , 11-04-2011 at 07:17 PM (My Java Tips)
    You are working in a Eclispe workspace that involves many projects. If you want to refresh all the projects or just simply if want to see all project names without their sub folders and files, you have to collapse all projects.

    In the package explorer, you will be viewing all the projects. To collapse each project, you can click the minus symbol for each project. But this is painful as too many clicks are required in case of too many projects.

    Eclipse provides ‘collapse ...
  20. Folding

    by , 11-04-2011 at 07:14 PM (My Java Tips)
    I will introduce folding option provided by Eclipse which is very helpful if you wish to fold (collapse) elements of a class.

    You might have experienced a situation where you have a class with lot of methods and comments. You may wish to collapse all the comments, or the methods or both to have a bird’s eye view of what the class is offering.

    Name:  foldin_option.PNG
Views: 297
Size:  31.0 KB

    Right click on the left most line (border) of the class. A window will open in which ...
  21. M2Eclipse (Tycho)

    by , 11-03-2011 at 07:35 PM (My Java Tips)
    Maven can be integrated in to Eclipse my using M2Eclipse (Tycho). Is is true to say that it is the most mature of the Eclipse integration projects.

    Worth mentioning features of M2Eclipse include:

    - Launching Maven builds from within Eclipse
    - Dependency management for Eclipse build path based on Maven's pom.xml
    - Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
    - Automatic downloading of the required ...
    Eclipse , Maven
  22. @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
  23. Converting an existing project to an EclipseME project

    by , 11-03-2011 at 07:32 PM (My Java Tips)
    Eclipse provides ‘Convert to J2ME Midlet Suite’ from the project pop-up menu to convert an existing Java project to EclipseME project. Let me show how to do that.

    When you select ‘Convert to J2ME Midlet Suite’’, you will be prompted for the appropriate device definition by the EclipseME plug-in. This plugin will then make the required changes to your project.

    When you convert a J2SE project to an EclipseME project, the J2SE libraries have to to be removed from the build ...
    Eclipse , Java ME
  24. Creating J2ME MIDlet Project

    by , 11-03-2011 at 07:31 PM (My Java Tips)
    Many guys who are new to mobile application development often question: “Does Eclipse support MIDlet development?”. Yes it does. In the next few posts, I will explain how you can create a J2ME project in Eclipse.

    To cleate a EclipseME project, we should use the New Project Wizard and select J2ME Midlet Suite from within the J2ME item.

    Name:  j2me_midlet_suite.PNG
Views: 627
Size:  9.8 KB

    You will then see a wizard pane which is actually the standard for almost all Eclipse projects. ...
    Java ME , Eclipse
  25. 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
  26. Subtyping

    by , 11-03-2011 at 01:17 PM (My Java Tips)
    Subtyping is very important in Java. One type is said to be subtype of other if they are related by an extend or implements clause.

    For instance:

    Integer is a subtype of Number
    Double is a subtype of Number
    ArrayList is a subtype of List
    List is a subtype of Collection
    Collection is a subtype of Iterable

    Subtyping principle says that a variable of type A can be assigned a value of any subtype of A and methods ...
    Java SE
  27. example

    by , 11-03-2011 at 01:15 PM (My Java Tips)
    Each computer on internet is called a node or a host. Each host has unique address called Internet Protocol (IP) address. IP addresses are not easy for the humans to remember therefore, Domain Name System (DNS) was introduced. DNS assigns a human understandable name to IP addresses.

    InetAddress class represents IP addresses which can be useful in networking environment. Let see what we can o with this one:

    Following code finds and prints the IP address ...
  28. Testing supported protocols

    by , 11-03-2011 at 01:13 PM (My Java Tips)
    Consider the following scenario: You are asked to test your browser with a list of protocols. So, you can do this by making URL objects for a host with each protocol. If object is created, it means protocol is supported, in other case, it simply means that the browser does not support the particular protocol.

    Review the applet code below:

    Java Code:
    public class ProtocolTesterApplet extends Applet {
      TextArea results = new TextArea(
    Network Programming
  29. AbstractList

    by , 11-03-2011 at 01:10 PM (My Java Tips)
    AbstractList implements Collection and List interfaces. ArrayList, Vector and AbstractSequentialList extends from AbstractList. Actually AbstractList contains implementation of List interface for random access.

    If you want to create a list that should not be modified, then you should extend this class. But then you have to provide implementations for the get(int index) and size() methods.

    Java Code:
    public class MyList extends AbstractList {
    Java SE
  30. LinkedList (Generics)

    by , 11-03-2011 at 01:07 PM (My Java Tips)
    Like Vectors and ArrayLists, LinkedList can also be made to deal with only one type of objects. Lets see how to do that.

    Java Code:
    LinkedList ll = new LinkedList();
    The LinkedList named ll can only store String objects. This is very useful and provides more control over collection. You are always sure that you will get objects of a specific type from the list. ...
    Java SE
Page 10 of 15 FirstFirst ... 89101112 ... LastLast