Posts

Showing posts with the label multiple

Java doesn't have "Diamond" problem : Really ..?

Java doesn’t have “Diamond” problem : Really ..? We have been confidently telling that Java doesn’t have diamond problem even if it support multiple inheritance. In object-oriented programming languages with multiple inheritance and knowledge organization, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. But do you that the diamond problem is now there in newly introduced Java 8. It is because of the introduction of default methods in Interface. In Java8 Interfaces not only have method declaration but their default implementation. Any class implementing can either use default implementation from interface or provide its own implementation. Since Java class can implement multiple interfaces it is possible that two interfaces has same default methods, that brings diamond problem. How do we overcome diamond problem ? Consider following code snippet public interface InterfaceA { ...

Eclipse command framework core expression : Multiple handlers

Image
Eclipse platform command framework supports core expression to control commands behavior runtime. In this series of posts I have explained different ways of using core expressions . This post explains having multiple handler for same command but activate only one of it at runtime based on some of the condition. Eclipse command framework is based on MVC framework. Command declaration, handler declaration  and contributing command to workbench helps to keep declaration separate from presentation. You can have multiple handlers for same command, but only one will be active at one moment. Core expression provides “activeWhen” declarative clause to activate specific handler for given command based on specific condition. Here is how we use it . I have created a new eclipse plug-in project. I have extended “org.eclipse.ui.editors” extension point to define two simple text editors. Here I am going to define two different handlers for same commands but only one will be active based on e...

Improved Exception handling in Java 7

Java 7 has improved the exception handling by ease of development, reduced code duplication  and intelligent throws clause. 1. More than one  exception types in single catch block: Java 7 onwards single catch block can handle multiple exception types. Now Catch block can specify ‘|’ separated exception types instead of only one exception. It prevent code duplication in case when same operation has to perform for all of set of types of exceptions and improve code readability. Old style : try { //your code here } catch (IOException ex) { log(ex); throw ex; catch (SQLException ex) { log(ex); throw ex; } New style : try { //your code here } catch (IOException|SQLException ex) { logger.log(ex); throw ex; } 2. Intelligent throws clause : Method declaration has to include the list of exception its is going to throws using throws clause. These exception types has to be matched with catch block throw statement. Java 7 onwards compiler ...