View RSS Feed

All Blog Entries

  1. Eclipse Debugging

    by , 11-04-2011 at 06: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 ...
    Categories
    Eclipse
  2. Java Applets - lifecycle

    by , 11-04-2011 at 06: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 06:40 PM by Java Tip

    Categories
    Java Applets
  3. Viewing all breakpoints

    by , 11-04-2011 at 06: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: 122
Size:  16.5 KB
    ...
    Categories
    Eclipse
  4. Checkout - out of disk space

    by , 11-04-2011 at 06: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 ...
    Categories
    Subversion
  5. Iterating using for loop

    by , 11-04-2011 at 06: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: ...
    Categories
    Java SE
  6. Spanning arrays

    by , 11-04-2011 at 06: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 :
    ...
    Categories
    Java SE
  7. Enumeration/Enum Spanning

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




    Java Code:
    enum Breed { DALMATIAN, LABRADOR, DACHSHUND }
    ...
    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();
       System.out.println(
    ...
    Categories
    Java SE
  8. Removing elements from a List

    by , 11-04-2011 at 06: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 = iter.next();
       if ( item.isUnwanted() )
           {
           // remove from underlying Collection
    ...
    Categories
    Java SE
  9. Colapse all

    by , 11-04-2011 at 06: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 ...
    Categories
    Eclipse
  10. Folding

    by , 11-04-2011 at 06: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: 142
Size:  31.0 KB

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

    by , 11-03-2011 at 06: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 ...
    Categories
    Eclipse , Maven
  12. @Stateful (Stateful session bean)

    by , 11-03-2011 at 06: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:
    @Stateful(entityContext=INSTANCE)
    ...
    Categories
    Java EE , EJB
  13. Converting an existing project to an EclipseME project

    by , 11-03-2011 at 06: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 ...
    Categories
    Eclipse , Java ME
  14. Creating J2ME MIDlet Project

    by , 11-03-2011 at 06: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: 410
Size:  9.8 KB

    You will then see a wizard pane which is actually the standard for almost all Eclipse projects. ...
    Categories
    Eclipse , Java ME
  15. Using @Stateless

    by , 11-03-2011 at 06: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, ...
    Categories
    EJB , Java EE
  16. Subtyping

    by , 11-03-2011 at 12: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 ...
    Categories
    Java SE
  17. java.net.InetAddress example

    by , 11-03-2011 at 12: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 ...
  18. Testing supported protocols

    by , 11-03-2011 at 12: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(
    ...
    Categories
    Network Programming
  19. AbstractList

    by , 11-03-2011 at 12: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 {
    
    	@Override
    ...
    Categories
    Java SE
  20. LinkedList (Generics)

    by , 11-03-2011 at 12: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();
    ll.add("Str1");
    ll.add("Str2");
    ll.addFirst("Str3");
    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. ...
    Categories
    Java SE
  21. Implementing LIFO principle

    by , 11-03-2011 at 12: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();
    newStack.push("10");
    newStack.push("20");
    ...
    Categories
    Java SE
  22. DateFormat Class

    by , 11-03-2011 at 12: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);
    ...
    Categories
    Java SE
  23. XPath VS DOM

    by , 11-03-2011 at 11:55 AM (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 ...
    Categories
    XML
  24. JAXP/XPath example

    by , 11-03-2011 at 11:50 AM (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.


    <inventory>
    <book year="2000">

    <author>Neal Stephenson</author>
    <publisher>Spectra</publisher>
    <isbn>0553380958</isbn>
    <price>14.95</price>
    </book>
    ...
    Categories
    XML
  25. View for warnings and problems

    by , 11-03-2011 at 11:40 AM (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: 169
Size:  17.9 KB ...

    Updated 11-03-2011 at 11:42 AM by Java Tip

    Categories
    Eclipse
  26. log4j.properties file

    by , 11-03-2011 at 11:34 AM (My Java Tips)
    log4j.properties file is a configuration file (not in XML format). If you have a stand alone application, then log4j.properties should be in the directory where you issued the java command. In case of web application (JSP/Servlet), place log4j.properties at /WEB-INF/classes/.



    A sample properties file is given below:

    log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder
    log4j.appender.stdout.Target=System.out
    log4j.appender.stdout.layout=org.apache.log4j.Patt ...
    Categories
    Java SE , XML
  27. JSF - Validators and Converters

    by , 11-02-2011 at 06:21 PM (My Java Tips)
    I will introduce JSF calidators and converters in this post.



    Converters are plug-in for conversions.

    <h:input_text valueref="testingBean.today" convertor="DateTime/">
    </h:input_text>

    Validators are used to perform correctness checks on UIInput values.

    <h:input_text valueref="testingBean.today&lt;br"> </h:input_text>
    Categories
    Frameworks
  28. Sample JSF page

    by , 11-02-2011 at 06:17 PM (My Java Tips)
    Creating JSF page is simple and easy. There are few things to remember which I will list down.


    The page must include JSF tag library and HTML and core tags.

    All the JSF tags must enclosed between a set of view tag.
    Use JSF form and form component tags.
    Use h:input_text and not input type=text
    Use h:command_button and not input type=submit

    A page may include validators and event listeners on any form components

    For example: ...

    Updated 11-02-2011 at 06:19 PM by Java Tip

    Categories
    Frameworks
  29. Tunning Eclipse

    by , 11-02-2011 at 06:15 PM (My Java Tips)
    Sometimes you might feel that your Eclipse is sluggish and performance tuning is required. I will address this issue in this post.


    Implement the following for better performance:

    - Increase your min/max memory settings from 40/256 to 256/512 or higher. You might have to experiment with the min/max setting but increasing the initial memory heap to 128 when Eclipse starts should help.

    - Disabling the code folding feature also helps. To disable this, go ...
    Categories
    Eclipse
  30. Resolving OutOfMemoryExceptions

    by , 11-02-2011 at 06:13 PM (My Java Tips)
    You might have encountered OutOfMemoryException using Eclipse. This post is about solving this issue.


    OutOfMemoryException is caused by too little heap space for virtual machine. Adjusting the maximum heap space with something like -vmargs -Xmx256m works. This gives your Java apps more space to run and this always helps performance. There are situations where even with an enormous heap size you can still end up with OutOfMemoryException. This means that your VM is not running out ...
    Categories
    Eclipse
Page 43 of 48 FirstFirst ... 334142434445 ... LastLast