View RSS Feed

All Blog Entries

  1. 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 ...
  2. 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 ...
  3. 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 ...
    JBoss , Java EE
  4. 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 ...
  5. 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 ...
  6. 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 ...
  7. 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
  8. 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
  9. 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 ...
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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 ...
  15. 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: 298
Size:  31.0 KB

    Right click on the left most line (border) of the class. A window will open in which ...
  16. 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
  17. @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
  18. 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
  19. 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. ...
    Eclipse , Java ME
  20. 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, ...
    Java EE , EJB
  21. 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
  22. 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 ...
  23. 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
  24. 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
  25. 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
  26. Implementing LIFO principle

    by , 11-03-2011 at 01:04 PM (My Java Tips)
    Stack is a special type of Vector as it extends Vector class. Stack works on last-in-first-out (LIFO) principle. Stack class provides 5 operations to treat the vector in a special way.

    Java Code:
    boolean empty()
    Object peek()
    Object pop()
    Object push(Object item)
    int search(Object o)
    Lets try push and pop operation on a Stack

    Java Code:
    Stack newStack = new Stack();
    Java SE
  27. DateFormat Class

    by , 11-03-2011 at 01:00 PM (My Java Tips)
    DateFormat class is a very useful class included in java.text package that can be used to display date in different formats. Following example will show you how to use it with Date object in meaningful way.

    Java Code:
    Date now = new Date();
    DateFormat df =  DateFormat.getDateInstance();
    DateFormat df1 = DateFormat.getDateInstance(DateFormat.SHORT);
    DateFormat df2 = DateFormat.getDateInstance(DateFormat.MEDIUM);
    DateFormat df3 = DateFormat.getDateInstance(DateFormat.LONG);
    Java SE
  28. XPath VS DOM

    by , 11-03-2011 at 12:55 PM (My Java Tips)
    We use Structured Query Language (SQL) for querying certain kinds of relational databases. Other less familiar query languages include Object Query Language (OQL) and XQuery. XPath, a query language used for querying XML documents.

    Following XPath query finds the titles of all the books in a document whose author is Neal Stephenson:

    //book[author="Neal Stephenson"]/title

    Following example uses DOM to find all the title elements of books by Neal ...
  29. JAXP/XPath example

    by , 11-03-2011 at 12:50 PM (My Java Tips)
    I will present an example that will search a XML file and then prints out the titles of all the books it finds.

    I will use following books.xml in the example.

    <book year="2000">

    <author>Neal Stephenson</author>
  30. View for warnings and problems

    by , 11-03-2011 at 12:40 PM (My Java Tips)
    Eclipse has a view that shows all the warnings and errors of the projects in your workspace. I will write about that in this post.

    While working on Java projects involving lot of packages and classes, you want a view to show you all the warnings and errors in your work. This will present all wrong stuff in a single view and you don’t need to search for the errors manually. Eclipse provides a view called ‘Problems’ that serves the purpose.

    Name:  viewprob.PNG
Views: 316
Size:  17.9 KB ...

    Updated 11-03-2011 at 12:42 PM by Java Tip

Page 12 of 17 FirstFirst ... 21011121314 ... LastLast