View RSS Feed

All Blog Entries

  1. Apache Struts

    by , 11-15-2011 at 07:03 PM (My Java Tips)
    Apache Struts is a free open-source framework for creating Java web applications. In this post, I will write about Apache Struts.

    In a standard Java EE web application, the client will typically submit information to the server via a web form. The information is then either handed over to a Java Servlet which processes it, interacts with a database and produces an HTML-formatted response, or it is given to a JavaServer Pages (JSP) document which intermingles HTML and Java code to ...
  2. Introduction to Model View Controller Architecture

    by , 11-14-2011 at 06:51 PM (My Java Tips)
    Designing large sized enterprise applications is a difficult task because the code maintenance becomes difficult as the size of application goes. Model View Controller Architecture presents a solution to this. In this post, I will introduce you to MVC.

    Web applications based on JavaServer Pages sometimes mix database code, page design code, and control flow code. In practice, we find that unless these concerns are separated, larger applications become difficult to maintain. One way ...

    Updated 11-14-2011 at 06:57 PM by Java Tip

  3. Capture screenshots

    by , 11-14-2011 at 06:41 PM (My Java Tips)
    Taking screenshots in windows is simple and very useful in our day to day business. It is done by pressing the Print Screen key on your keyboard [PrtScn], pasting it in image editor such as MS paint and then editing and saving it. In this post, I will write about how to do this from Java program.

    Java provides classes to help us which capturing screens.

    java.awt.Robot is used to generate native system input events which can be used to for test automation, and other ...
  4. Changing Java for projects

    by , 11-14-2011 at 06:37 PM (My Java Tips)
    Sometimes you want to keep legacy code and for that you have to use older version of Java. These days, people are working in Java 5 and Java 6. But still developers are using legacy code which means using Java 1.3 and Java 1.4. In this post, I will brief you how to change the Java version for projects in Eclipse.

    Eclipse provides support for changing the Java version through few clicks. Eclipse 3.3.0 has Java 5.0 configured. So if you do not specify Java version, your project will ...
  5. Changing Console properties

    by , 11-14-2011 at 06:31 PM (My Java Tips)
    Eclipse provides a console window in which you see the output of your Java program. Normally default properties are sufficient and developers are satisfied with it. In some cases, you might want to change the look and feel of the console window. I'll write about this in this post.

    The default console looks like this:

    Now lets try to change the look and feel. Click
    Tags: console, eclipse Add / Edit Tags
  6. Generating Interface from a Class

    by , 11-14-2011 at 06:27 PM (My Java Tips)
    Some times you have a class with concrete methods and you want to declare an interface with all the methods in the class. You may call it backtracking. In this post, I will write about how to do this in Eclipse.

    Suppose we have a class called Students that has methods defined in it. We want to generate the interface for it in Eclipse. Simply right click the class name, or simply right click anywhere in the code and select Refactor > Extract interface. A new window will open. Name ...
  7. Viewing Outline of a Class

    by , 11-14-2011 at 06:20 PM (My Java Tips)
    Eclipse includes a useful feature called outline. It helps the developer to get a birds eyes view of the class. In this post, I will explore it.

    You can display outline panel of your class by Navigate > Show in > Outline.

    Eclipse Outline

    Outline will show all the methods and fields in the class. It used special symbols for private, public, static fields ...
    Tags: eclipse, outline Add / Edit Tags
  8. Build a Rich Client Platform application

    by , 11-14-2011 at 05:54 PM (My Java Tips)
    While the Eclipse platform is designed to serve as an open tools platform, it is architect so that its components could be used to build just about any client application. The minimal set of plug-ins needed to build a rich client application is collectively known as the Rich Client Platform.

    Applications that don't require a common resource model can be built using a subset of the platform. These rich applications are still based on a dynamic plug-in model, and the UI is built using ...
  9. RCP Custom Look and Feel

    by , 11-14-2011 at 05:40 PM (My Java Tips)
    The presentation of your Rich Client Platform application can be changed using the org.eclipse.ui.presentationFactories extension point.

    This example will show how to use the R2.1 presentation, provided by the org.eclipse.ui.presentations.r21 plugin, in the RCP Browser Example application. Here is a screen shot of the browser example using the R2.1 presentation.

  10. Eclipse RCP Browser Example

    by , 11-14-2011 at 05:33 PM (My Java Tips)

    This is an example of a simple Eclipse Rich Client Platform (RCP) application. It is a bare bones web browser, using the SWT Browser control.

    To load the browser example source into your workspace, load project org.eclipse.ui.examples.rcp.browser from the Eclipse CVS repository.

    The code is in package org.eclipse.ui.examples.browser, and consists of an application class (BrowserApp), a workbench advisor for configuring the workbench (BrowserAdvisor), ...
  11. Defining a rich client application

    by , 11-13-2011 at 06:50 PM (My Java Tips)
    The definition of a rich client application plug-in starts out similarly to the other plug-ins we've been studying. The only difference in the first part of the markup is that the list of required plug-ins is much smaller than we've been used to.

    XML Code:
    <!--?xml version="1.0" encoding="UTF-8"?-->
    <!--?eclipse version="3.0"?-->
  12. Rich Client Platform (introduction)

    by , 11-13-2011 at 06:37 PM (My Java Tips)
    The Eclipse Rich Client Platform (RCP) allows developers to use the Eclipse architecture to design flexible and extensible applications re-using a lot of already existing functionality and coding patterns inherent in Eclipse. Programmers can build their own applications on existing platforms. Instead of having to write a complete application from scratch, they can benefit from proven and tested features of the framework provided by the platform. Building on a platform facilitates faster application ...
  13. Vector Capacity

    by , 11-13-2011 at 12:48 PM (My Java Tips)
    In this post, I will talk about the performance issues related to vector capacity. I have noticed, that normally developers donít care about the performance issues and declare the vector as:

    Java Code:
    Vector vector = new Vector();

    Newly created vector has no element in it so its size is 0 but its capacity is 10 by default. So if you donít specify the capacity of the vector (and call the default constructor), its capacity will be 10. Capacity of the vector is the ...
    Tags: capacity, vector Add / Edit Tags
  14. Bounding ArrayList

    by , 11-13-2011 at 12:45 PM (My Java Tips)
    Collections can be of a particular type i.e they are only allowed to hold objects of a defined type. This is called ďbounded byĒ. For example:

    Java Code:
    ArrayList  arrayList  = new  ArrayList();
    Vector  vector  = new  Vector();

    We declared an ArrayList and a Vector both bounded by String. We cannot store objects other than String in these. Lets try to store an integer in Vector and see what happens.

    Java Code:
    Vector  vector  = new  Vector();
  15. Interface extending Interface

    by , 11-13-2011 at 12:42 PM (My Java Tips)
    An interface can extend other interface but cannot implement any interface. This makes sense because interface cannot have any implementation. An interface can only contain abstract methods that are implemented by the class implementing that interface.

    Lets do this with an example.

    Create a package named myinterfaces. Using conventions, package name should be in small case. Now create an interface named InterfaceA with 2 methods.

    Java Code:
    package myinterfaces;
  16. Using LinkedList (Collection)

    by , 11-13-2011 at 12:40 PM (My Java Tips)
    LinkedList is a special type of List which is very useful in certain scenarios. Some important facts about LinkedList are:
    - It is not synchronized
    - It does not use array internally for storage
    - It uses pointers internally to point to next node
    - It implements Cloneable, List and Serializable interfaces

    LinkedList is preferred when you know that you have to add and delete data from the start or from middle of the list. It perform addition and deletion ...
    Java SE
  17. Implementing more than one Interfaces

    by , 11-13-2011 at 12:37 PM (My Java Tips)
    Interfaces contain abstract methods that implementing class has to implement. It is must for the implementing class to implement all the methods found in the interface. Sometimes you face a situation where you have to implement more than one interface. How to do that?

    One way is to simply try to write one interface with all the abstract methods. This is not at all flexible as all of these interfaces might be used in different scenarios. So its better to keep each as a separate interface. ...
  18. Constructor calling ordering

    by , 11-13-2011 at 12:34 PM (My Java Tips)
    Constructors are used for initialization normally. Name of constructor should be same as that of the class. If no constructor is declared, a default constructor is created without parameters. Constructor does not return any thing.

    Consider the example below. ClassB inherits from ClassA. In the MainClass, we made an object of ClassB. Default constructor will be called. But the output suggests that first Constructor of ClassA is called and then the constructor of classB is called. ...
  19. JSF (introduction)

    by , 11-13-2011 at 12:31 PM (My Java Tips)
    It has been a problem with open source or community based developments that they provide more options than standards. When we look for java, standard/enterprise java and its development have always remain with standard, but while looking for some web framework in java, we get several names. From MVC based frameworks like Struts, JSF to specialized frameworks like Tapestry, Spring etc. Frameworks with similar and overlapping features making it difficult for a person to choose the best fit. When there ...
  20. Using Treeset

    by , 11-13-2011 at 12:29 PM (My Java Tips)
    TreeSet belongs to Java Collection Framework and is very rare situations. In this post, I will briefly discuss when to use TreeSet and how to use it.

    To use it, you have to import java.util.TreeSet in your class. TreeSet is not synchronized so if a TreeSet is concurrently accessed by threads then thread modifying the contents must be synchronized externally. TreeSet provides following constructors:
    TreeSet(Collection c)
    TreeSet(Comparator c)
    TreeSet(SortedSet ...
  21. Persisting state of objects

    by , 11-13-2011 at 12:24 PM (My Java Tips)
    Serializable interface has no methods and fields so a class that implementing this interface does not have to override any method. The state of objects of serializable class, can be saved and restored later. The state is saved on a container that may be transient (RAM-based) or persistent (disk-based).

    For network communication, the objects that you want to transfer through streams, should be Serializable. For instance, Vector, ArrayList etc implement Serializable interface so their ...
  22. Randomly Accessing Files

    by , 11-13-2011 at 12:12 PM (My Java Tips)
    I have seen a lot of Java guys struggling with accessing a file and playing the data in it. File input output operations are obviously slow as compared to "in memory" operations but then you have persistent data which is of good use. Someone can argue that databases should be used for input and output but then itís a separate debate. Just to keep it short, I would say that sometimes it is better to use text files for input and out.

    In this post, I will write about randomly ...
  23. Multithreading (basics)

    by , 11-13-2011 at 11:59 AM (My Java Tips)
    Multithreading is a concept where a program is broken into two or more parts called threads and all these threads run in parallel. Multithreading can make programs more responsive and effective and it increases its performance too. For example, today web pages need to display animations with sound effects and text at the same time. If this is done by using the traditional single-threaded event loop, the application will take a lot of time to get loaded, and time is a very crucial factor for web ...
    Java SE
  24. Why use multithreading?

    by , 11-13-2011 at 11:55 AM (My Java Tips)
    In this post, I will talk about the importance of multithreading and would like to answer the question: Why use multithreading ??

    Multithreading exploits the fact that most of the time the tasks (parts) of the same program are either waiting for the other resources to become free, or waiting for some timeout to occur. In the above example (spreadsheet), scroll operation is waiting for the calculation to be completed. If these parts or tasks can be described as independent threads, ...
    Java SE
  25. Java Threads

    by , 11-13-2011 at 11:51 AM (My Java Tips)
    A thread is a thread of execution in a program. Java environment has been built around the multithreading model. In fact all Java class libraries have been designed keeping multithreading in mind. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. If a thread goes off to sleep for some time, the rest of the program does not get affected by this. Similarly, an animation loop can be fired that will not stop the working of rest of the system. ...
  26. Thread priorities, synchronization and messaging

    by , 11-13-2011 at 11:47 AM (My Java Tips)
    I assume that you have the basic knowledge of threads. In this post, I will write about thread priorities, synchronization and messaging.

    In multithreading environment, one thread might require the attention of the CPU more quickly than other. In such a case that thread is said to be of high priority. Priority of a thread determines the switching from one thread to another. In other words, priority determines how a thread should behave with respect to the other threads.
  27. main() thread in Java

    by , 11-13-2011 at 11:44 AM (My Java Tips)
    The 'main()' method in Java is referred to the thread that is running, whenever a Java program runs. It calls the main thread because it is the first thread that starts running when a program begins. Other threads can be spawned from this main thread. The main thread must be the last thread in the program to end. When the main thread stops, the program stops running.

    Main thread is created automatically, but it can be controlled by the program by using a Thread object. The Thread ...
    Java SE
  28. Creating a Thread (extending Java Thread Class)

    by , 11-13-2011 at 11:41 AM (My Java Tips)
    There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.

    In case, ...
  29. Creating a Thread (implementing Java Runnable Interface)

    by , 11-12-2011 at 06:58 PM (My Java Tips)
    A better way to create a thread in Java is to implement Runnable interface. A thread can be created by extending Java Thread class also. Now the question arises why implementing Runnable interface is a better approach? Answer is, if the thread class you are creating is to be subclass of some other class, it canít extend from the Thread class. This is because Java does not allow a class to inherit from more than one class. In such a case one can use Runnable interface to implement threads.
  30. Implementing ActionListener interface

    by , 11-12-2011 at 06:54 PM (My Java Tips)
    ActionListener interface is used to perform actions on a performed event. In this post, I will write about its importance and usage.

    ActionListener interface is part of java.awt.event package. It has only one abstract method that has to be implemented in the class implementing this interface.

    Method signature:
    void actionPerformed(ActionEvent e)

    Consider the following scenario: you developed an GUI form for an application comprising of text fields, ...
Page 6 of 17 FirstFirst ... 4567816 ... LastLast