View RSS Feed

Recent Blogs Posts

  1. Abstract class vs Interface

    by , 01-08-2012 at 11:15 AM
    Base classes are used to present interface to its child classes in design. It supports that base class cannot be instantiated. It can be only up casted and its interface is used only. To achieve this, mark the base class as abstract. Compiler gives an error, if you try to create an object of abstract class.

    The interface helps and improves the concept of abstract class. In interfaces, you can only declare methods and cannot provide implementation. The child class which is implementing ...
    Categories
    Interface
  2. Interface and bean-class

    by
    EJB
    , 01-02-2012 at 06:02 PM
    Home interfaces and remote interfaces present the bean however beans are insulated by the container and client applicationís direct access. Whenever a bean is deleted, created or requested the whole process is managed by the container.

    Componentís life cycle methods are presented by the home interfaces however beanís business method is presented by the remote interfaces. Home & remote interfaces extends the javax.ejb.EJBHome interface and javax.ejb.EJBObject interface. Such types ...
    Categories
    Session Bean
  3. Use an Interface to Compare Objects in Generics

    by , 11-29-2011 at 11:25 PM
    A key aspect of using generics is being able to compare different objects. Consider an example where you are comparing different species of felines.
    Java Code:
    public class ComparableFeline implements Comparable<ComparableFeline> {
    
    	@Override
    	public int compareTo(ComparableFeline arg0) {
    		return 0;
    	}
    }
    So if you wanted to narrow ComparableFeline for use only among different types of domesticated cats instead of other felines such as ...

    Updated 11-30-2011 at 08:37 AM by Advanced Java

    Categories
    Generics
  4. 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;
    ...
  5. Implementing ActionListener interface

    by , 11-12-2011 at 05: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, ...
  6. Using Interfaces

    by , 11-10-2011 at 04:32 PM (My Java Tips)
    Interfaces are used to define a contract for the classes. It has its own importance when it comes to defining standards.


    Consider the following example:

    Cars have some standard and their basic operations are the same. Each car should have operations like startCar, moveCar, stopCar etc. Toyota, Mazda and Honda are cars and each has its own way of starting, moving and stoping. So each has to have its own startCar, moveCar and stopCar method.

    How to enforce ...
  7. Working With Interfaces

    by , 11-08-2011 at 06:33 PM (My Java Tips)
    Interface is very much similar to the Abstract class in Java but the difference is that in interfaces, members (methods) cannot be implemented, member(fields) defined will be treated as constants.
    A class becomes more formal about its behavior after implementing an interface. Interfaces are actually a contract between the class and the outside world. While implementing an interface in a concrete class, you have to implement all the methods defined by that interface. If you miss any method, ...
    Categories
    Java SE
  8. Factory Methods

    by , 06-02-2011 at 07:11 PM (My Java Tips)
    This post lists some facts about factory methods.

    Factory methods are static methods that return an instance of the native class. Some examples from JDK include :

    • LogManager.getLogManager
    • Pattern.compile
    • Collections.unmodifiableCollection
    • Collections.synchronizeCollection
    • Calendar.getInstance


    Factory methods do not have names like constructors and do not need to create a new object upon each invocation. Objects can be cached and reused, if ...
  9. Using interfaces in APIs

    by , 05-25-2011 at 09:59 AM (My Java Tips)
    When you are designing your API, you might want to use interface since this seems a common practice. There exist a style in Java programming where everything is expressed in terms of Java interfaces instead of classes.

    Using interfaces provides benefits but its not a good idea for an entire API to be expressed in terms of them.

    Use interface as a type if you have a good reason for it to be. Following are some important facts to be considered:

    Interfaces ...
    Tags: api, interface Add / Edit Tags
    Categories
    Java SE