Legacy Java Interfaces

Dated: 19-3-2014

Interface is a Contract between two parts of program/system/component.They are important design construct for any component/system/systems of systems. Some of the languages do not have any construct to support interfaces, they have to be realized conceptually. But almost all of the upcoming coming languages targets productivity, lesser typing drudgery, hence they do support them with language constructs. JAVA being a language highly hailed for Productivity and claimed as productive language supports interface concept by providing language construct "interface".

Here are few of the important aspects of the language which any serious JAVA language speaker supposed to understand to gain fluency.

These features or semantics are good for the "Legacy" Java Interfaces as few of them have changed in JAVA 8 version.

1. All interfaces are public and abstract by default/Implicitly and always.

2. Interface member type can only be public.

3. All methods in the interfaces are public and abstract by default/Implicitly and always. (Try adding a Private/Protected Methods – Final is not allowed)

4. All attributes in the interfaces are public static final by default/Implicitly and always. (Try adding a Private/Protected and non static final Constants)

5. Static Nested classes / Nested Classes can be declared inside an interface. (Try declaring a Class inside Interface)

6. An Interface can extend any no. of Interface unlike classes where only one can be extended.

7. Segregation of Interfaces (dividing Interfaces into two) is one of the Design Principle to form better Design.

8. Circular Reference in Interface is not allowed. (A->B->C->A not allowed will give compilation error, where -> means extends)

9. “Marker Interfaces” are interfaces which do not have any members inside it. They are used by the JVM/Compiler to add specific functionality. Egs – Remote, Cloanable, Serializable etc,

10. A Nested interface is any interface whose declaration occurs within the body of another class or interface. A top-level interface is an interface that is not a nested interface. (Try declaring an Interface inside an Interface/Class)

11. Final & Static Modifier are not allowed on Top level Interfaces.

12. Protected, Private & Static are allowed on Member Interfaces /Nested interfaces inside a class declaration.

13. Interfaces can serve as a better “Constant Storage” as one can access all the constants without creating Objects. (Any Manipulation with Constant happens at Compile time)

14. Overloading & Overriding of Members occurs when interfaces are extended/inherited.

15. Ambiguous Inherited Fields will leave out Compilation Errors when interfaces are extended/inherited.

16. Diamond Problem does not occurs in Interface during “Multiple Inheritance” as duplicate declaration of methods is ignored. 

Comments

Popular posts from this blog

JavaScript Debut as a Full Fledged Language for Production in the Age of Cloud, Big Data and IoT

Make Raspberry Pi Independent of Peripheral Devices & Connector Cables

Following Java, Exploring Projects JIGSAW and KULLA - Intro