<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Blog &#187; Abstract and Interface</title>
	<atom:link href="http://javapapers.com/category/core-java/abstract-and-interface-core-java-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://javapapers.com</link>
	<description>Blog on core java, servlets, jsp and design patterns.</description>
	<lastBuildDate>Sun, 03 Jun 2012 11:34:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Java Marker Interface</title>
		<link>http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-a-java-marker-interface/</link>
		<comments>http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-a-java-marker-interface/#comments</comments>
		<pubDate>Thu, 29 May 2008 12:28:57 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Abstract and Interface]]></category>

		<guid isPermaLink="false">http://javapapers.com/?p=60</guid>
		<description><![CDATA[Marker interface is used as a tag to inform a message to the java compiler so that it can add special behaviour to the class implementing it. Java marker interface has no members in it. Lets take the java.io.Serializable marker interface. It doesnot has any members defined it it. When a java class is to be [...]]]></description>
			<content:encoded><![CDATA[<p>Marker interface is used as a tag to inform a message to the java compiler so that it can add special behaviour to the class implementing it. Java marker interface has no members in it.</p>
<p><img class="alignnone size-full wp-image-673" title="marker" src="http://javapapers.com/wp-content/uploads/2008/05/marker.jpg" alt="" width="225" height="180" /></p>
<p>Lets take the java.io.Serializable marker interface. It doesnot has any members defined it it. When a java class is to be serialized, you should intimate the java compiler in some way that there is a possibility of serializing this java class. In this scenario, marker interfaces are used. The java class which may be serialized has to implement the java.io.Serializable marker interface. In such way, we are intimating the java compiler.</p>
<p>From java 1.5, the need for marker interface is eliminated by the introduction of the java annotation feature. So, it is wise to use java annotations than the marker interface. It has more feature and advantages than the java marker interface.</p>
<h2>Is Runnable a marker interface?</h2>
<p>First point, there is no reference or definition about marker interface from Java specification/api. This is yet another inconclusive debate. &#8216;Marker Interface&#8217; is a term coined by (book / web) authors. Since we don&#8217;t have Java&#8217;s definition it is left to us to arrive at a decent definition. This is one popular question asked in java interview. My answer to the interviewer, there are better questions ask than this to ask.</p>
<p>&#8220;Runnable is not a marker interface&#8221;, you might say &#8216;run&#8217; is used to start a method and this is a special instruction to the JVM.  When you run a java class the java interpreter calls the &#8216;main&#8217; method, because of this would you say every java class as &#8220;marker class&#8221;?</p>
<h2>&#8216;My&#8217; definition for marker interface</h2>
<blockquote><p>&#8220;An interface is called a marker interface when it is provided as a handle by java interpreter to mark a class so that it can provide special behaviour to it at runtime and they do not have any method declarations&#8221;.</p></blockquote>
<p>In the above definition &#8220;and they do not have any method declarations&#8221; is added because, till now all the marker interfaces provided by java do not have method declarations. I dont think, in future there will be any new marker interfaces added :-)</p>
<p>We cannot create marker interfaces, as you cannot instruct JVM to add special behavior to all classes implementing (directly) that special interface.</p>
<h3>Java Marker Interface Examples</h3>
<ul>
<li>java.lang.Cloneable</li>
<li>java.io.Serializable</li>
<li>java.util.EventListener</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-a-java-marker-interface/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>Difference Between Interface and Abstract Class</title>
		<link>http://javapapers.com/core-java/abstract-and-interface-core-java-2/difference-between-a-java-interface-and-a-java-abstract-class/</link>
		<comments>http://javapapers.com/core-java/abstract-and-interface-core-java-2/difference-between-a-java-interface-and-a-java-abstract-class/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 05:57:36 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Abstract and Interface]]></category>

		<guid isPermaLink="false">http://javapapers.com/?p=17</guid>
		<description><![CDATA[Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior. Variables declared in a Java interface is by default final. An  abstract class may contain non-final variables. Members of a Java interface are public by default. A Java abstract class can [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.</li>
<li>Variables declared in a Java interface is by default final. An  abstract class may contain non-final variables.</li>
<li>Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..</li>
<li>Java interface should be implemented using keyword &#8220;implements&#8221;; A Java abstract class should be extended using keyword &#8220;extends&#8221;.</li>
<li>An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.</li>
<li>A Java class can implement multiple interfaces but it can extend only one abstract class.</li>
<li>Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.</li>
<li>In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://javapapers.com/core-java/abstract-and-interface-core-java-2/difference-between-a-java-interface-and-a-java-abstract-class/feed/</wfw:commentRss>
		<slash:comments>241</slash:comments>
		</item>
		<item>
		<title>When can an object reference be cast to a Java interface reference?</title>
		<link>http://javapapers.com/core-java/abstract-and-interface-core-java-2/when-can-an-object-reference-be-cast-to-a-java-interface-reference/</link>
		<comments>http://javapapers.com/core-java/abstract-and-interface-core-java-2/when-can-an-object-reference-be-cast-to-a-java-interface-reference/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 05:50:45 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Abstract and Interface]]></category>

		<guid isPermaLink="false">http://javapapers.com/?p=16</guid>
		<description><![CDATA[When a Java object implements the referenced interface it can be cast to the Java interface reference.]]></description>
			<content:encoded><![CDATA[<p>When a Java object implements the referenced interface it can be cast to the Java interface reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://javapapers.com/core-java/abstract-and-interface-core-java-2/when-can-an-object-reference-be-cast-to-a-java-interface-reference/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Java interface</title>
		<link>http://javapapers.com/core-java/abstract-and-interface-core-java-2/java-interface/</link>
		<comments>http://javapapers.com/core-java/abstract-and-interface-core-java-2/java-interface/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 05:48:06 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Abstract and Interface]]></category>

		<guid isPermaLink="false">http://javapapers.com/?p=15</guid>
		<description><![CDATA[A java class containing all the methods as abstract is called an interface. A method that has no implementation and which is expected to be implemented by a subclass is called an abstract method. Java interface can contain constants. When an interface needs to be instantiated it should be implemented by a class and all [...]]]></description>
			<content:encoded><![CDATA[<p>A java class containing all the methods as abstract is called an interface. A method that has no implementation and which is expected to be implemented by a subclass is called an abstract method. Java interface can contain constants. When an interface needs to be instantiated it should be implemented by a class and all its abstract methods should be defined. If all the methods are not implemented in the class then it becomes a java abstract class and so cannot be instantiated. Variables declared in a java interface by default is final.</p>
]]></content:encoded>
			<wfw:commentRss>http://javapapers.com/core-java/abstract-and-interface-core-java-2/java-interface/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How can you invoke a defined method of an abstract class?</title>
		<link>http://javapapers.com/core-java/abstract-and-interface-core-java-2/haw-can-you-invoke-a-defined-method-of-an-abstract-class/</link>
		<comments>http://javapapers.com/core-java/abstract-and-interface-core-java-2/haw-can-you-invoke-a-defined-method-of-an-abstract-class/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 14:09:54 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Abstract and Interface]]></category>

		<guid isPermaLink="false">http://javapapers.com/core-java-interview-questions/abstract-and-interface-core-java-interview-questions/haw-can-you-invoke-a-defined-method-of-an-abstract-class/</guid>
		<description><![CDATA[An abstract class cannot be instantiated directly. An abstract class has to be sub-classed first and then instantiated. Only then the method defined in the abstract class can be invoked.]]></description>
			<content:encoded><![CDATA[<p>An abstract class cannot be instantiated directly. An abstract class has to be sub-classed first and then instantiated. Only then the method defined in the abstract class can be invoked.</p>
]]></content:encoded>
			<wfw:commentRss>http://javapapers.com/core-java/abstract-and-interface-core-java-2/haw-can-you-invoke-a-defined-method-of-an-abstract-class/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What is an abstract class?</title>
		<link>http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-an-abstract-class/</link>
		<comments>http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-an-abstract-class/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 14:07:11 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Abstract and Interface]]></category>

		<guid isPermaLink="false">http://javapapers.com/core-java-interview-questions/abstract-and-interface-core-java-interview-questions/what-is-an-abstract-class/</guid>
		<description><![CDATA[A class containing atleast one abstract method is called an abstract class. A method that has no implementation and which is expected to be implemented by a subclass is called an abstract method. An Abstract class cannot be instantiated. It is expected to be extended by a subclass. An abstract class may contain static variables [...]]]></description>
			<content:encoded><![CDATA[<p>A class containing atleast one abstract method is called an abstract class. A method that has no implementation and which is expected to be implemented by a subclass is called an abstract method. An Abstract class cannot be instantiated. It is expected to be extended by a subclass. An abstract class may contain static variables declared. Any class with an abstract method must be declared explicitly as abstract. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.</p>
]]></content:encoded>
			<wfw:commentRss>http://javapapers.com/core-java/abstract-and-interface-core-java-2/what-is-an-abstract-class/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

