tag:blogger.com,1999:blog-8712770457197348465.post6815560099008585017..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: What is interface in Java with Example - Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-8712770457197348465.post-84845701618499333032020-02-16T00:00:33.888-08:002020-02-16T00:00:33.888-08:00Hello dd, if you have used JDBC then you know abou...Hello dd, if you have used JDBC then you know about some of the popular interface like Driver, Connection, ResultSet etc. You can write your code by using this interface without worrying about their implementation, which is done by vendors like MySQL has their own JDBC Driver JAR, Oracle will have their own. The Point is interface allowed you to create your code without actual implementation. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2847755586547033912020-02-15T08:29:52.133-08:002020-02-15T08:29:52.133-08:00I'm still not confident, though this article i...I'm still not confident, though this article is very informative. I have used interfaces in past but don't exactly know what was the purpose.<br /><br />Can you please explain all the points with an example? That how generally understand things: a code snippet showing the implementation, and an example that reader can relate to or implement on their own.ddhttps://www.blogger.com/profile/16561155309110737926noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-30646672812180660062017-06-12T05:07:07.056-07:002017-06-12T05:07:07.056-07:00hello @sikdar007, good suggestion, I'll update...hello @sikdar007, good suggestion, I'll update the article. Btw, I have blogged about <a href="http://javarevisited.blogspot.sg/2014/07/default-defender-or-extension-method-of-Java8-example-tutorial.html" rel="nofollow">default methods on interface on Java 8</a> already, you may want to check that article. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-29457385750075859812017-06-11T21:24:34.580-07:002017-06-11T21:24:34.580-07:00JAVA 8 have got some modification on Interface lik...JAVA 8 have got some modification on Interface like deafult and static methods can be defined in an interface.Can we have a post based on that linked in this tutoarial?sikdar007noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-68849903638462188692015-09-24T07:33:33.947-07:002015-09-24T07:33:33.947-07:00Hi ,Can some one please provide a real time exampl...Hi ,Can some one please provide a real time example on Abstract and Interface class with respect to any web application or webpage .Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-14524653856822419672015-08-15T08:48:05.994-07:002015-08-15T08:48:05.994-07:00@Nuwan and @infoj, that's true, Java 8 has all...@Nuwan and @infoj, that's true, Java 8 has allowed interface to contain some actual code to do the job as well, it has bring interface little closer to abstract class in my opinion.javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-68329260297902667142015-08-10T10:44:21.599-07:002015-08-10T10:44:21.599-07:00Note that from Java 8 interface can have default a...Note that from Java 8 interface can have default and static methods. Which means a default implementation for a method can be given. Also static methods can be written which can be accessed using Interface_name.method_name.infojhttp://netjs.blogspot.in/2015/04/this-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76968670150400550922014-11-13T16:34:05.963-08:002014-11-13T16:34:05.963-08:00In JDK 8 interfaces are allowed to have a default...In JDK 8 interfaces are allowed to have a default implementation where as earlier versions of JDK does not allow. This is a major update to JDK after a long time. I think it's better to update this article now to keen in sync with latest changes.Nuwan's Post~ishhttps://www.blogger.com/profile/09527576607455724309noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69639391275667423552014-08-12T02:59:39.333-07:002014-08-12T02:59:39.333-07:00hai this is very nice.......i have one question......hai this is very nice.......i have one question.....<br />in Below code how to try and catch........<br /><br /><br /><br />import java.io.*;<br />import java.lang.*;<br />interface ebcalc<br />{<br />final static int re=100;<br />public void get();<br />public void put();<br />public void ebdisp();<br />}<br />class detail<br />{<br />String cname,caddr;<br />int lmr,cmr,a,u,b,c;<br />float amt,Anamikanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22242726094629926332014-05-18T03:36:10.872-07:002014-05-18T03:36:10.872-07:00hi this is very nice article. I've one questio...hi this is very nice article. I've one question.<br /><br />In below code which from which interface "method()" method will be called.<br /><br /> interface Rollable {<br /><br /> void method(); <br /> }<br />interface bounceback<br />{<br /> int BAR=9;<br /> void rollaback_of_Rollable();<br /> void method();<br />}<br />interface bounceback1 extends bounceback,Rollable<br />{<brAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82240026714545608582014-04-07T09:07:00.822-07:002014-04-07T09:07:00.822-07:00One more use of interface which i think you should...One more use of interface which i think you should include here. Although an interface cannot be instantiated but since it is a type, Java allows to write a method with a parameter of an interface type. That method parameter will accept any class that implements this interface. <br /><br />For example, public interface Creator{}<br /><br />This is a valid method - void createObject(Creator hjhttps://www.blogger.com/profile/07628170479835253417noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42536771163240730702014-02-20T22:26:51.392-08:002014-02-20T22:26:51.392-08:00Though I agree that using interface is great in te...Though I agree that using interface is great in terms of flexibility, but it also has few disadvantages. For example by coding Interface, you are restricted to methods declared on interface. One example, which I face, where I had to change the type from Map to ConcurrentHashMap, was putIfAbsent(), this method is only defined in ConcurrentHashMap, and not in java.util.Map. If a method accepts Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36321741311855699422013-08-23T02:59:07.505-07:002013-08-23T02:59:07.505-07:00here it will print toString because here we don,...here it will print toString because here we don,t show method and child is in show method <br /><br /> so out put will be toStringShivanshu Bhargavahttps://www.blogger.com/profile/12914755694387023480noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-80149596740181045712013-08-21T20:47:02.557-07:002013-08-21T20:47:02.557-07:00Hi Javin, I have couple of questions related to in...Hi Javin, I have couple of questions related to interface in Java :<br /><br />Can one interface extend other interface in Java? If Yes, when should we extend other interface, a real world programming example would be great.<br /><br />Can one interface extend a class? if not, Why<br /><br />Can we define method inside interface in Java? if not, why?<br /><br />Why all variables are public final Pristinenoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-28897269443647154632013-07-21T18:35:27.221-07:002013-07-21T18:35:27.221-07:00many there and the example one is Comparator inter...many there and the example one is Comparator interface.Srikanth goudhttps://www.blogger.com/profile/17536578283293046379noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-57713862040166041262013-04-29T19:24:02.101-07:002013-04-29T19:24:02.101-07:00@Anonymous, I suggest you to read Effective Java, ...@Anonymous, I suggest you to read Effective Java, Joshua Bloach has suggested some good use of interface in Java, one of them is use interface for declaring type, advantage? One object can represent multiple type because it can implement multiple interface. Another advantage is that using interface will lead you to program for interface than implementation, which is key to create flexible object Sonalnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10577504252924248202013-04-29T19:21:19.010-07:002013-04-29T19:21:19.010-07:00Inheritance is good for code reuse, but it can cos...Inheritance is good for code reuse, but it can cost flexibility, if not used correctly. It's very important for an Object Oriented designer to understand inheritance in Java quite well. Following are some of the strong and week points of Inheritance, I have learned in hard way, might help your readers :<br /><br />1)Inheritance is great if all sub classes have same behavior, but it's Gauravnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31439261860337095862013-04-27T20:34:39.964-07:002013-04-27T20:34:39.964-07:00I will add another frequently asked question relat...I will add another frequently asked question related to interface in java<br />Why you use interface in java if you can not define any method there?<br />Well in reality interface is key for flexible and reusable java program. Suppose an Employee objects needs to calculate its salary and<br /> There are different kinds of employees e.g. Hourly, Daily, Monthly. Now how do you write code for that<Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-77611915151774104022013-03-22T02:12:40.419-07:002013-03-22T02:12:40.419-07:00OOPS concepts in brief
Object-An object is a softw...OOPS concepts in brief<br />Object-An object is a software bundle of related state(Color,Height etc) and behavior(Selection).An object stores its state in fields (variables) and exposes its behavior through methods (functions).Ex-Vehicle.<br /><br />Class-Class is ma collection of objects.<br /><br />Inheritance-Different kinds of objects often have a certain amount in common with each other. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-57000191993887983952013-02-07T17:18:13.236-08:002013-02-07T17:18:13.236-08:00@Anonymous and @Prasanna, I think output should be...@Anonymous and @Prasanna, I think output should be "toString", as show() method is not called any where. As Prasanna pointed out this Child object so toString() from Child class will get called.<br /><br />Now your second question "Does interface in Java extends Object class", which is indeed a good question.<br />Simple answer is No. interface in Java doesn't extend Javin @ ClassLoader in Javahttp://javarevisited.blogspot.com/2012/12/how-classloader-works-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-12362418537633176582013-02-07T11:15:43.201-08:002013-02-07T11:15:43.201-08:00I think the output will be: Child because the inte...I think the output will be: Child because the interface Parent is printing out Child in its implementation. <br />Anonymoushttps://www.blogger.com/profile/01107065128617161307noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-13313247763152427162013-02-01T09:21:00.029-08:002013-02-01T09:21:00.029-08:00interface Parent
{
void show();
}
class Child ...interface Parent<br />{<br /> void show();<br />}<br /><br />class Child implements Parent<br />{<br /> public void show() <br /> {<br /> System.out.println("Child");<br /> }<br /> <br /> public String toString()<br /> {<br /> System.out.println("toString");<br /> }<br />}<br /><br /><br />///main() method<br />{<br /> Parent p=new Child();<br /> p.toString();<br />}<Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-87488533778105634202012-05-23T01:07:11.092-07:002012-05-23T01:07:11.092-07:00interface is really beautiful concept introduced b...interface is really beautiful concept introduced by Object oriented programming language and Java seems use it perfectly. there are several benefits of using Interface while coding like:<br /><br />1) Interface offers protection with change in requirement or future enhancement.<br />2) By using interface you can leverage more powerful implementation as highlighted in this article.<br />3) Code Anagathttp://en.wikipedia.org/wiki/Interface_(computing)noreply@blogger.com