File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 41800
    
  62
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


Ping & DNS - my free Android networking tools app
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3090
    
  40

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 ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Dinesh Tahiliani
Ranch Hand

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

Joined: Jul 29, 2008
Posts: 3090
    
  40

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: 449

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://aspose.com/file-tools
 
subject: Interface