View RSS Feed

All Blog Entries

  1. Using Constructor Injection with Spring

    by , 11-15-2011 at 02:09 PM
    As we had mentioned in a previous tip, Inversion of Control (IoC) can be divided into two subtypes. There is Dependency Lookup which has two types, Contextualized Dependency Lookup and Dependency Pull); and Dependency Injection which also has two types, Constructor Injection and Setter Injection. In this tip we will look at Constructor Dependency Injection. Constructor Dependency Injection is Dependency Injection where a component's dependencies are provided to it in its constructor(s). The component ...

    Updated 11-30-2011 at 11:43 AM by Spring Framework

    Categories
    Dependency Injection
  2. Using Setter Injection in Spring

    by , 11-15-2011 at 02:02 PM
    An object is created in the Spring IOC container by invoking the zero-argument constructor. In this Setter Dependency Injection, the IoC container injects a component's dependencies into the component via JavaBean-style setter methods. A component's setters expose the set of the dependencies the IoC container can manage The dependent object is then passed as a parameter to the setter method. The CarService object needs data access objects (DAO) to execute data- base operations. The data access ...

    Updated 11-15-2011 at 02:10 PM by Spring Framework (Error in constructor for class)

    Categories
    Dependency Injection , Bean , Configuration
  3. The Core Features of the Spring Framework

    by , 11-15-2011 at 01:42 PM
    Dependency Injection
    In early tips, we discussed the issues around creating and initializing objects and itís variables. Fortunately there is a way of addressing this situation in Spring that is a wonderful design pattern that they have applied to address this aspect. It is a combination of Inversion of Control and Dependency Injection. Many developers mistakenly believe that IOC and DI are the same thing. It is incorrect. IOC deals with inverting the control flow in an application, DI describes ...
  4. Introduction to Model View Controller Architecture

    by , 11-14-2011 at 05: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 05:57 PM by Java Tip

    Categories
    MVC
  5. Capture screenshots

    by , 11-14-2011 at 05: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 ...
  6. Changing Java for projects

    by , 11-14-2011 at 05: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 ...
    Categories
    Eclipse
  7. Changing Console properties

    by , 11-14-2011 at 05: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
    Categories
    Eclipse
  8. Generating Interface from a Class

    by , 11-14-2011 at 05: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 ...
  9. Viewing Outline of a Class

    by , 11-14-2011 at 05: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
    Categories
    Eclipse
  10. Build a Rich Client Platform application

    by , 11-14-2011 at 04: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 ...
    Categories
    RCP
  11. RCP Custom Look and Feel

    by , 11-14-2011 at 04: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.




    ...
  12. Eclipse RCP Browser Example

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

    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), ...
    Categories
    RCP
  13. Defining a rich client application

    by , 11-13-2011 at 05: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"?-->
    <plugin
       id="org.eclipse.ui.examples.rcp.browser"
       name="%pluginName"
    ...
  14. Rich Client Platform (introduction)

    by , 11-13-2011 at 05: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 ...
    Categories
    RCP
  15. Vector Capacity

    by , 11-13-2011 at 11:48 AM (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
    Categories
    Performance
  16. Bounding ArrayList

    by , 11-13-2011 at 11:45 AM (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();
    ...
  17. Interface extending Interface

    by , 11-13-2011 at 11:42 AM (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;
    ...
  18. Using LinkedList (Collection)

    by , 11-13-2011 at 11:40 AM (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 ...
    Categories
    Java SE
  19. Implementing more than one Interfaces

    by , 11-13-2011 at 11:37 AM (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. ...
  20. Constructor calling ordering

    by , 11-13-2011 at 11:34 AM (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. ...
  21. JSF (introduction)

    by , 11-13-2011 at 11:31 AM (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 ...
    Categories
    JSF
  22. Using Treeset

    by , 11-13-2011 at 11:29 AM (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()
    TreeSet(Collection c)
    TreeSet(Comparator c)
    TreeSet(SortedSet ...
  23. Persisting state of objects

    by , 11-13-2011 at 11:24 AM (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 ...
  24. Randomly Accessing Files

    by , 11-13-2011 at 11:12 AM (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 ...
  25. Multithreading (basics)

    by , 11-13-2011 at 10: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 ...
    Categories
    Java SE
  26. Why use multithreading?

    by , 11-13-2011 at 10: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, ...
    Categories
    Java SE
  27. Java Threads

    by , 11-13-2011 at 10: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. ...
  28. Thread priorities, synchronization and messaging

    by , 11-13-2011 at 10: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.
    ...
  29. main() thread in Java

    by , 11-13-2011 at 10: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 ...
    Categories
    Java SE
  30. Creating a Thread (extending Java Thread Class)

    by , 11-13-2011 at 10: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, ...
Page 37 of 48 FirstFirst ... 27353637383947 ... LastLast