aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Interface" Watch "Interface" New topic
Author

Interface

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
Hello Ranchers,

What is use of interface in java in detail?



Thanks<br />Dinesh
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Please show some effort.

What have you read? What do you know? What doesn't make sense?


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35258
    
    7
The Sun Java Tutorial -as is so often the case with fundamental language questions- has answers: http://java.sun.com/docs/books/tutorial/java/IandI/index.html


Android appsImageJ pluginsJava web charts
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 341
Effective Java (2nd Ed.) Chapter 4 may help you in this regard


http://muhammadkhojaye.blogspot.com/
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
I am asking when to use interface and when to abstract in java.
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2701
    
    3

Dinesh Tahiliani wrote:I am asking when to use interface and when to abstract in java.


Well you CAN use abstract classes instead of interfaces. But if you decided to leave *all* of the methods in that top-level class without defining it's body, you should use interfaces.


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
didn't get you
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2701
    
    3

Dinesh Tahiliani wrote:didn't get you


I meant you should use abstract classes if you need to put some common business logic there. Using interfaces you can mandate it implementers to implement *all* of the methods defined in the interface. Please have a look at this JavaRanch wiki.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 341
Dinesh Tahiliani wrote:I am asking when to use interface and when to abstract in java.




Use Interface when you want to add optional behaviour in class. Consider Comparable interface that allows a class to make sure that its instances are ordered with respect to other mutually comparable objects. Such interface is called a Mixin. You cannot define Abstract Classes as mixin.

The constant interface pattern is a poor use of interfaces

If you have default behavior, then you must use an abstract class Otherwise, use an interface

An abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.


 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Interface
 
Similar Threads
How To Call Two Different Classes From the Main Program Using the Same API?
Regarding Interfaces
Writing an Interface
Time Capsule
Home interface or Home Interface stub