tag:blogger.com,1999:blog-8712770457197348465.post6495879435670253443..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: What is Marker interface in Java and why required? Answerjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-8712770457197348465.post-4576011438359141302021-07-25T22:16:25.504-07:002021-07-25T22:16:25.504-07:00To me, Marker interface looks like completely usel...To me, Marker interface looks like completely useless, this can be easily done by using an Annotation? what do you guys think? I am really curious to know the true purpose and significance of Marker interface? If anyone knows what is the role of Marker interface in Java then do comment? I know from this article that Marker interface is kind of hint or suggestion but why not use Annotation insteadAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88958192282558914212019-01-14T04:12:24.934-08:002019-01-14T04:12:24.934-08:00Hello Nikhil, thanks for adding value but I would ...Hello Nikhil, thanks for adding value but I would also highlight one aspect of marker interface that if he means to something inside JVM then it's not possible. For example, JVM or Compiler does special things for Serializable, it's not possible for custom marker interface to achieve same because you can't modify JVM code. But, logically your answer is correct. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75768833497553114002019-01-13T08:57:41.029-08:002019-01-13T08:57:41.029-08:00Another good question on this, which was asked to ...Another good question on this, which was asked to me in one of the interview was that can you create your own marker classes, and answer is yes we can, as the marker classes are just to mark the classes so that compiler knows what it means, if we create a interface of our own say example CustomCheckMarker, we can check at run time classes that implement this interface and can do some custom Nikhil Guptanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-50184713005718794522018-12-05T00:47:56.727-08:002018-12-05T00:47:56.727-08:00It is marker interface, not "market interface...It is marker interface, not "market interface" .<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-37808452843373753052018-10-23T07:45:27.329-07:002018-10-23T07:45:27.329-07:00It is marker interface, not "market interface...It is marker interface, not "market interface" .<br />Heera_r_nambiarhttps://www.blogger.com/profile/15646545883879767797noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-17343297694383251692018-03-26T23:39:08.109-07:002018-03-26T23:39:08.109-07:00It’s a kind of interface which has no method is kn...It’s a kind of interface which has no method is known as marker interface. Serializable, Clonnable is the example of marker interface to <a href="http://beyondcorner.com/create-own-marker-interface-in-java" rel="nofollow">Marker Interface in Java </a> <br />Use of Marker Interface:<br />Marker Interfaces are used to indicate something to compiler/JVM. If JVM see that a class is a object of MarkerAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10907687794402401072017-08-30T07:33:03.039-07:002017-08-30T07:33:03.039-07:00market interface market interface akshobhyahttps://www.blogger.com/profile/00857741871945663435noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56430938667370272362017-08-09T06:41:10.375-07:002017-08-09T06:41:10.375-07:00Hello @Unknown, The default Serialization is imple...Hello @Unknown, The default Serialization is implemented ad compiler and JVM level which uses marker interface, isn't it? The purpose of marker interface is same as annotation, to indicate something, now the tool which could use this information can be anything e.g. another Java program like ant or compiler or JVM etc. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-27190317189652851592017-08-06T10:39:06.294-07:002017-08-06T10:39:06.294-07:00This post is correct in the parts that (1) a marke...This post is correct in the parts that (1) a marker interface must be empty, and (2) implementing it is meant to imply some special treatment of the implementing class. The part that is incorrect is that it implies that JVM or the compiler would treat the objects of that class differently. In fact, it's the code of Java class library that treats these objects as cloneable, serializable, etc. Unknownhttps://www.blogger.com/profile/07702199695782196905noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-23192900097876452632017-02-21T16:09:17.529-08:002017-02-21T16:09:17.529-08:00Hi.. can marker interface have some methods????
Be...Hi.. can marker interface have some methods????<br />Because I have read somewhere saying marker interface can have .Santoshnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8376283986336598322016-11-12T09:11:09.164-08:002016-11-12T09:11:09.164-08:00if any interface doesn't contain any method an...if any interface doesn't contain any method and by implemeting this interface if our object will get some ability then such type of interface is called marker interface.<br />Anonymoushttps://www.blogger.com/profile/03294453261304832899noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61655912692497589322016-10-18T16:48:51.661-07:002016-10-18T16:48:51.661-07:00Good artical ,and the comments are also awesome .Good artical ,and the comments are also awesome .zengzhenhttps://www.blogger.com/profile/13704092413122372005noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-90107491167145933392016-09-01T06:07:38.206-07:002016-09-01T06:07:38.206-07:00A marker interface does not indicate anything to c...A marker interface does not indicate anything to compiler or JVM. It indicates java classes to implement it in a different way from other interfaces. Please go through this link for a better understanding.<br /><br />http://stackoverflow.com/questions/20869993/why-does-arraylist-implement-randomaccess-interfaceAnonymoushttps://www.blogger.com/profile/11392114597624037153noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-33267122903832554772016-08-25T11:02:05.387-07:002016-08-25T11:02:05.387-07:00Superb Article . Very Nicely Explained :)Superb Article . Very Nicely Explained :)Anonymoushttps://www.blogger.com/profile/06707987263552782219noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-71499032668727165712015-11-29T23:44:20.950-08:002015-11-29T23:44:20.950-08:00Hi Every One! Marker Interface means it has no m...Hi Every One! Marker Interface means it has no methods in that. right ? so this is not correct definition for marker interface. Marker Interface is an Interface which is gives ability, functionality to derived classes. Like Runnable Interface it has run() method and Serializable no method, Cloneable no method too.Anonymoushttps://www.blogger.com/profile/01637472162590855065noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-85076666285492505372015-11-29T05:57:28.849-08:002015-11-29T05:57:28.849-08:00Why to use marker interface.? If its use is restri...Why to use marker interface.? If its use is restricted just to be used as an indication to JVM then we can have a flag in Object class. This way all classes will have this flag.Anonymoushttps://www.blogger.com/profile/04058041636426309226noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76525894869174554602015-11-06T05:17:00.055-08:002015-11-06T05:17:00.055-08:00Everyone saying Marker interface is designed in su...Everyone saying Marker interface is designed in such a way that JVM get notified when one class implement that Marker interface.Now i am really curious to know how JVM is designed that it came to know that this is special type of interface.love the worldhttps://www.blogger.com/profile/08256399362521571819noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-67040375050725550112015-08-05T09:51:30.207-07:002015-08-05T09:51:30.207-07:00The main purpose of marker interfaces is to create...The main purpose of marker interfaces is to create special types where types themselves have no behavior of their own.<br /><br />public interface MarkerEntity {<br /><br />}<br /><br />public boolean save(Object object) throws InvalidEntityFoundException {<br /> if(!(object instanceof MarkerEntity)) {<br /> throw new InvalidEntityFoundException("Invalid Entity Found, can't be infojhttp://netjs.blogspot.in/2015/05/difference-between-abstract-class-and-interface-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86084905914180607212015-07-18T11:12:23.951-07:002015-07-18T11:12:23.951-07:00Read some of the reasons why James Gosling created...Read some of the reasons why James Gosling created interfaces. you need to understand Java, not just know it.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9886977886534131632014-09-15T05:00:27.294-07:002014-09-15T05:00:27.294-07:00This is the BEST site for interviewThis is the BEST site for interviewAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75689114903602974342014-04-06T07:40:43.524-07:002014-04-06T07:40:43.524-07:00The designers maybe would have used Annotations in...The designers maybe would have used Annotations instead of the marker interfaces Serializable or Cloneable, but these marker interfaces belong to Java 1.0 and there was no annotation concept back then. Annotations were introduced in Java 1.5.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-15034986948953059542014-03-02T02:29:28.848-08:002014-03-02T02:29:28.848-08:00interface Marker{
}
class MyException extends... interface Marker{ <br /> }<br /> <br /> class MyException extends Exception { <br /> public MyException(String s){<br /> super(s);<br /> }<br /> }<br /> <br /> class A {<br /> void m1() throws MyException{ <br /> if((this instanceof Marker)){<br /> System.out.println("successfull");<br /> }<br /> else {<br /> throw new MyException("Must implement interfaceAnonymoushttps://www.blogger.com/profile/00215757443831118374noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-67157030532158335732014-02-26T21:35:11.890-08:002014-02-26T21:35:11.890-08:00package com.java.testString;
interface Marker{
}...package com.java.testString;<br /><br />interface Marker{ <br />}<br /><br />class MyException extends Exception { <br /> public MyException(String s){<br /> super(s);<br /> }<br />}<br /><br />class A {<br /> void m1() throws MyException{ <br /> if((this instanceof Marker)){<br /> System.out.println("successfull");<br /> }<br /> else {<br /> throw new MyException("Anonymoushttps://www.blogger.com/profile/00215757443831118374noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75357247789623825282014-02-13T18:55:20.772-08:002014-02-13T18:55:20.772-08:00One of the lesser known marker interface in Java i...One of the lesser known marker interface in Java is RandomAccess, defined in java.util package. This interface is used to signal that a particular List implementation supports random access to its elements e.g. their get(index) method provides constant time O(1) performance. Main reason, why this marker interface exists is that best algorithms for random access can perform poorly if applied to Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-17200747961374885212013-08-08T10:54:40.945-07:002013-08-08T10:54:40.945-07:00nice explanation :) thanksnice explanation :) thanksAnonymoushttps://www.blogger.com/profile/17946131082526175489noreply@blogger.com