Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31661 > unrolled thread

how does a marker interface give specific instruction to jvm(java internals)

Started byAjay Paul <ajaykpaul@gmail.com>
First post2015-05-10 03:08 -0700
Last post2015-05-13 22:49 -0400
Articles 12 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  how does a marker interface give specific instruction to jvm(java internals) Ajay Paul <ajaykpaul@gmail.com> - 2015-05-10 03:08 -0700
    Re: how does a marker interface give specific instruction to jvm(java internals) Jeff Higgins <jeff@invalid.invalid> - 2015-05-10 07:41 -0400
    Re: how does a marker interface give specific instruction to jvm(java internals) Joerg Meier <joergmmeier@arcor.de> - 2015-05-10 14:00 +0200
      Re: how does a marker interface give specific instruction to jvm(java internals) Arne Vajhøj <arne@vajhoej.dk> - 2015-06-03 21:49 -0400
    Re: how does a marker interface give specific instruction to jvm(java internals) Ajay Paul <ajaykpaul@gmail.com> - 2015-05-12 08:54 -0700
      Re: how does a marker interface give specific instruction to jvm(java internals) Robert Klemme <shortcutter@googlemail.com> - 2015-05-12 18:53 +0200
      Re: how does a marker interface give specific instruction to jvm(java internals) Jeff Higgins <jeff@invalid.invalid> - 2015-05-12 19:07 -0400
        Re: how does a marker interface give specific instruction to jvm(java   internals) Robert Klemme <shortcutter@googlemail.com> - 2015-05-14 00:14 +0200
      Re: how does a marker interface give specific instruction to jvm(java internals) Jeff Higgins <jeff@invalid.invalid> - 2015-05-12 21:34 -0400
        Re: how does a marker interface give specific instruction to jvm(java internals) Arne Vajhøj <arne@vajhoej.dk> - 2015-06-03 21:27 -0400
      Re: how does a marker interface give specific instruction to jvm(java internals) Jeff Higgins <jeff@invalid.invalid> - 2015-05-13 22:33 -0400
        Re: how does a marker interface give specific instruction to jvm(java internals) Jeff Higgins <jeff@invalid.invalid> - 2015-05-13 22:49 -0400

#31661 — how does a marker interface give specific instruction to jvm(java internals)

FromAjay Paul <ajaykpaul@gmail.com>
Date2015-05-10 03:08 -0700
Subjecthow does a marker interface give specific instruction to jvm(java internals)
Message-ID<fb878f12-cf37-4889-9e38-91ed3a590af6@googlegroups.com>
For example if I implement Serializable for a class, it will give specific instruction to jvm that this class needs to be treated differently. Initially I thought that there might be a native method call inside this interface however when I see the Serializable.java source code, there is none.

How does declaring a class Serializable or clonable enable it to be treated differently.

[toc] | [next] | [standalone]


#31662

FromJeff Higgins <jeff@invalid.invalid>
Date2015-05-10 07:41 -0400
Message-ID<ming7f$2vm$1@dont-email.me>
In reply to#31661
On 05/10/2015 06:08 AM, Ajay Paul wrote:
> For example if I implement Serializable for a class, it will give specific instruction to jvm that this class needs to be treated differently. Initially I thought that there might be a native method call inside this interface however when I see the Serializable.java source code, there is none.
>
> How does declaring a class Serializable or clonable enable it to be treated differently.
>
<http://docs.oracle.com/javase/8/docs/platform/serialization/spec/serialTOC.html>

[toc] | [prev] | [next] | [standalone]


#31663

FromJoerg Meier <joergmmeier@arcor.de>
Date2015-05-10 14:00 +0200
Message-ID<19z5wn8o1648v.laqzl037eidg.dlg@40tude.net>
In reply to#31661
On Sun, 10 May 2015 03:08:08 -0700 (PDT), Ajay Paul wrote:

> For example if I implement Serializable for a class, it will give specific instruction to jvm that this class needs to be treated differently. Initially I thought that there might be a native method call inside this interface however when I see the Serializable.java source code, there is none.

> How does declaring a class Serializable or clonable enable it to be treated differently.

It doesn't in itself do anything at all, that is what "marker interface"
means. Other code can check (through normal typing, use of 'instanceof' or
Reflection) if something implements that marker interface and then do
anything they want.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.

[toc] | [prev] | [next] | [standalone]


#31762

FromArne Vajhøj <arne@vajhoej.dk>
Date2015-06-03 21:49 -0400
Message-ID<556fae90$0$292$14726298@news.sunsite.dk>
In reply to#31663
[sorry if duplicate post]

On 5/10/2015 8:00 AM, Joerg Meier wrote:
 > On Sun, 10 May 2015 03:08:08 -0700 (PDT), Ajay Paul wrote:
 >
 >> For example if I implement Serializable for a class, it will give 
specific instruction to jvm that this class needs to be treated 
differently. Initially I thought that there might be a native method 
call inside this interface however when I see the Serializable.java 
source code, there is none.
 >
 >> How does declaring a class Serializable or clonable enable it to be 
treated differently.
 >
 > It doesn't in itself do anything at all, that is what "marker interface"
 > means. Other code can check (through normal typing, use of 
'instanceof' or
 > Reflection) if something implements that marker interface and then do
 > anything they want.

Exactly.

And for the examples given, then it seems most likely that it indeed is
code in the Java library not code in the JVM that does the check.

Arne

[toc] | [prev] | [next] | [standalone]


#31680

FromAjay Paul <ajaykpaul@gmail.com>
Date2015-05-12 08:54 -0700
Message-ID<5b49c798-5b11-4b08-8d87-a241d9a3cfc0@googlegroups.com>
In reply to#31661
My understanding is that JVM looking for specific signatures for the Java class library marker interface just like it does for main method.
hence interfaces like Serializable, Clonable have a specific meaning to the jvm.

so, its roughly like an IoC principle: "Instead of I define myself, you define me".

Am I correct ?

[toc] | [prev] | [next] | [standalone]


#31682

FromRobert Klemme <shortcutter@googlemail.com>
Date2015-05-12 18:53 +0200
Message-ID<crepftFphklU1@mid.individual.net>
In reply to#31680
On 12.05.2015 17:54, Ajay Paul wrote:
> My understanding is that JVM looking for specific signatures for the Java class library marker interface just like it does for main method.
> hence interfaces like Serializable, Clonable have a specific meaning to the jvm.
>
> so, its roughly like an IoC principle: "Instead of I define myself, you define me".
>
> Am I correct ?

There is no signature in case of a marker interface without methods. 
It's just the "implements" relationship to a specific interface that 
needs to be checked.

Kind regards

	robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#31687

FromJeff Higgins <jeff@invalid.invalid>
Date2015-05-12 19:07 -0400
Message-ID<miu160$eg6$1@dont-email.me>
In reply to#31680
On 05/12/2015 11:54 AM, Ajay Paul wrote:
> My understanding is that JVM looking for specific signatures for the Java class library marker interface just like it does for main method.
> hence interfaces like Serializable, Clonable have a specific meaning to the jvm.
>
> so, its roughly like an IoC principle: "Instead of I define myself, you define me".
>
> Am I correct ?
>
Please read the "Java Object Serialization Specification".

[toc] | [prev] | [next] | [standalone]


#31703 — Re: how does a marker interface give specific instruction to jvm(java internals)

FromRobert Klemme <shortcutter@googlemail.com>
Date2015-05-14 00:14 +0200
SubjectRe: how does a marker interface give specific instruction to jvm(java internals)
Message-ID<cri0n3FkjtqU1@mid.individual.net>
In reply to#31687
On 13.05.2015 01:07, Jeff Higgins wrote:
> On 05/12/2015 11:54 AM, Ajay Paul wrote:
>> My understanding is that JVM looking for specific signatures for the
>> Java class library marker interface just like it does for main method.
>> hence interfaces like Serializable, Clonable have a specific meaning
>> to the jvm.
>>
>> so, its roughly like an IoC principle: "Instead of I define myself,
>> you define me".
>>
>> Am I correct ?
>>
> Please read the "Java Object Serialization Specification".

I am not sure that advice will help: the spec only covers the effects of 
tagging a class as serializable with the interface Serializable, but it 
does not explain how that tagging is technically done.  And this seems 
to be the point the OP is struggling with.  To resolve that question 
reading the JVM Specification might help, for example the section about 
the class file format:
http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [next] | [standalone]


#31688

FromJeff Higgins <jeff@invalid.invalid>
Date2015-05-12 21:34 -0400
Message-ID<miu9p0$smm$1@dont-email.me>
In reply to#31680
On 05/12/2015 12:55 PM, Stefan Ram wrote:
> Ajay Paul <ajaykpaul@gmail.com> writes:
>> Am I correct ?
>
>    A marker interface is used like an annotation.
>
I'm guessing your use of annotation is the common English usage.

Otherwise how do I use the following to indicate to the Java compiler
that a particular method is deprecated?

package example;
public interface Deprecated {}

[toc] | [prev] | [next] | [standalone]


#31760

FromArne Vajhøj <arne@vajhoej.dk>
Date2015-06-03 21:27 -0400
Message-ID<556fa972$0$295$14726298@news.sunsite.dk>
In reply to#31688
[sorry if duplicate post]

On 5/12/2015 9:34 PM, Jeff Higgins wrote:
 > On 05/12/2015 12:55 PM, Stefan Ram wrote:
 >> Ajay Paul <ajaykpaul@gmail.com> writes:
 >>> Am I correct ?
 >>
 >>    A marker interface is used like an annotation.
 >>
 > I'm guessing your use of annotation is the common English usage.
 >
 > Otherwise how do I use the following to indicate to the Java compiler
 > that a particular method is deprecated?

I think you can use an annotation instead of a marker interface
but not the other way around - use a marker interface instead of an
annotation.

Serializable is in fact an annotation (attribute in .NET
terminology) in .NET.

Arne

[toc] | [prev] | [next] | [standalone]


#31709

FromJeff Higgins <jeff@invalid.invalid>
Date2015-05-13 22:33 -0400
Message-ID<mj11is$8vj$1@dont-email.me>
In reply to#31680
On 05/12/2015 11:54 AM, Ajay Paul wrote:
> My understanding is that JVM looking for specific signatures for the Java class library marker interface just like it does for main method.

I don't understand this statement.

> hence interfaces like Serializable, Clonable have a specific meaning to the jvm.

A marker interface, like Serializable or Cloneable may have a specific
meaning to a Java Virtual Machine, or to a Java compiler, or to another
Java class.

In the particular case of deserializing a serialized Java object the
meaning of the Serializable interface to a JVM is that it is possible
that it can proceed to reconstruct that serialized object according to
the Java Object Serialization Specification.

What would a Java compiler do with the knowledge that a class implements
the java.io.Serializable interface?

What classes in the Java standard library could make use of the
knowledge that another class implements the java.io.Serializable
interface, and what could they do with this knowledge?

>
> so, its roughly like an IoC principle: "Instead of I define myself, you define me".

I don't understand this statement.

>
> Am I correct ?
>

[toc] | [prev] | [next] | [standalone]


#31710

FromJeff Higgins <jeff@invalid.invalid>
Date2015-05-13 22:49 -0400
Message-ID<mj12h9$b4n$1@dont-email.me>
In reply to#31709
On 05/13/2015 10:33 PM, Jeff Higgins wrote:
> On 05/12/2015 11:54 AM, Ajay Paul wrote:
>> My understanding is that JVM looking for specific signatures for the
>> Java class library marker interface just like it does for main method.
>
> I don't understand this statement.
>
>> hence interfaces like Serializable, Clonable have a specific meaning
>> to the jvm.
>
> A marker interface, like Serializable or Cloneable may have a specific
> meaning to a Java Virtual Machine, or to a Java compiler, or to another
> Java class.
>
> In the particular case of deserializing a serialized Java object the
> meaning of the Serializable interface to a JVM is that it is possible
> that it can proceed to reconstruct that serialized object according to
> the Java Object Serialization Specification.
                                              ^
                     when called upon to do so
>
> What would a Java compiler do with the knowledge that a class implements
> the java.io.Serializable interface?
>
> What classes in the Java standard library could make use of the
> knowledge that another class implements the java.io.Serializable
> interface, and what could they do with this knowledge?
>
>>
>> so, its roughly like an IoC principle: "Instead of I define myself,
>> you define me".
>
> I don't understand this statement.
>
>>
>> Am I correct ?
>>
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web