Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > What are the difference between Descriptor and Signature

Reply
Thread Tools

What are the difference between Descriptor and Signature

 
 
bearice@gmail.com
Guest
Posts: n/a
 
      02-15-2008
When looking at java class file. many thing has two attribute:
Descriptor and Signature. at most time they looks the same. So who can
tell what are the differences between them? Thank you.
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      02-15-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> When looking at java class file. many thing has two attribute:
> Descriptor and Signature. at most time they looks the same. So who can
> tell what are the differences between them? Thank you.


The term "descriptor" (lower-case "d") in a Java context usually refers to a
text file (often XML) that contains configuration information for a program or
a system, such as for a Web app. Literally it just means "something that
describes."

The "signature" (lower-case "s") of a method is the formal pattern of a
method, that is the argument types and their order, the return type and the
exception types.

--
Lew
 
Reply With Quote
 
 
 
 
Tom McGlynn
Guest
Posts: n/a
 
      02-15-2008
On Feb 15, 1:56 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> When looking at java class file. many thing has two attribute:
> Descriptor and Signature. at most time they looks the same. So who can
> tell what are the differences between them? Thank you.


While descriptor has a lot of possible meanings, if you are comparing
it with signatures, you may be thinking of descriptors in the context
of usage
in the JVM (e.g., http://java.sun.com/docs/books/jvms/...File.doc.html).

If so, then the signature of a method is the specification of the
types of the formal parameters of the method. I don't know that there
is any canonical representation of the signature of a method beyond
the method name and argument list as used in a Java program.
Generally the signature is something that the compiler worries about
but isn't used so much at run time. The descriptor includes the return
type of the method, which is not part of the signature, and has a very
specific string representation for all of this that is used within the
class files.


Regards,
Tom McGlynn
 
Reply With Quote
 
Tom McGlynn
Guest
Posts: n/a
 
      02-15-2008
On Feb 15, 8:22 am, Lew <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > When looking at java class file. many thing has two attribute:
> > Descriptor and Signature. at most time they looks the same. So who can
> > tell what are the differences between them? Thank you.

>
> The term "descriptor" (lower-case "d") in a Java context usually refers to a
> text file (often XML) that contains configuration information for a program or
> a system, such as for a Web app. Literally it just means "something that
> describes."
>
> The "signature" (lower-case "s") of a method is the formal pattern of a
> method, that is the argument types and their order, the return type and the
> exception types.
>
> --
> Lew


I believe the signature includes neither the return type nor the
exceptions thrown, just the method name and the types of the
parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
edition). E.g.,
"Two methods have the same signature if they have the same name and
argument types."
See <http://java.sun.com/docs/books/jls/third_edition/html/
classes.html#8.4.2>

Regards,
Tom McGlynn
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      02-15-2008
(E-Mail Removed) wrote:
> When looking at java class file. many thing has two attribute:
> Descriptor and Signature. at most time they looks the same. So who can
> tell what are the differences between them? Thank you.


A method descriptor is the name followed by the formal parameter types
followed by the return type. The signature is the same, but includes
generic types.

E.g.:
Set.get(K k):
Descriptor: put(Ljava/lang/ObjectLjava/lang/Object;
Signature: put(TKTV;

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      02-16-2008
Tom McGlynn wrote:
> On Feb 15, 8:22 am, Lew <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> When looking at java class file. many thing has two attribute:
>>> Descriptor and Signature. at most time they looks the same. So who can
>>> tell what are the differences between them? Thank you.

>> The term "descriptor" (lower-case "d") in a Java context usually refers to a
>> text file (often XML) that contains configuration information for a program or
>> a system, such as for a Web app. Literally it just means "something that
>> describes."
>>
>> The "signature" (lower-case "s") of a method is the formal pattern of a
>> method, that is the argument types and their order, the return type and the
>> exception types.
>>
>> --
>> Lew

>
> I believe the signature includes neither the return type nor the
> exceptions thrown, just the method name and the types of the
> parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
> edition). E.g.,
> "Two methods have the same signature if they have the same name and
> argument types."
> See <http://java.sun.com/docs/books/jls/third_edition/html/
> classes.html#8.4.2>


You are correct. However, it is still useful to think of return type and
exception types as part of the signature. If you don't respect those, you can
get compiler errors. So informally I think of the signature as including
those factors.

For example, if you declare two methods in a class with the same signature,
it's a compiler error. If you declare two methods that differ only in
(non-covariant) return type, you get an error. If you add checked exceptions
to a method override, you get an error. The mental dodge of pretending that
exceptions and return types are part of the signature helps me keep that straight.

Still, it is pretending. You are right about the definition.

--
Lew
 
Reply With Quote
 
Daniele Futtorovic
Guest
Posts: n/a
 
      02-16-2008
On 2008-02-16 02:50 +0100, Lew allegedly wrote:
> Tom McGlynn wrote:
>> On Feb 15, 8:22 am, Lew <(E-Mail Removed)> wrote:
>>> (E-Mail Removed) wrote:
>>>> When looking at java class file. many thing has two attribute:
>>>> Descriptor and Signature. at most time they looks the same. So who can
>>>> tell what are the differences between them? Thank you.
>>> The term "descriptor" (lower-case "d") in a Java context usually
>>> refers to a
>>> text file (often XML) that contains configuration information for a
>>> program or
>>> a system, such as for a Web app. Literally it just means "something
>>> that
>>> describes."
>>>
>>> The "signature" (lower-case "s") of a method is the formal pattern of a
>>> method, that is the argument types and their order, the return type
>>> and the
>>> exception types.
>>>
>>> --
>>> Lew

>>
>> I believe the signature includes neither the return type nor the
>> exceptions thrown, just the method name and the types of the
>> parameters. This is discussed in the JLS (in 8.4.3 in the 3rd
>> edition). E.g.,
>> "Two methods have the same signature if they have the same name and
>> argument types."
>> See <http://java.sun.com/docs/books/jls/third_edition/html/
>> classes.html#8.4.2>

>
> You are correct. However, it is still useful to think of return type
> and exception types as part of the signature. If you don't respect
> those, you can get compiler errors. So informally I think of the
> signature as including those factors.
>
> For example, if you declare two methods in a class with the same
> signature, it's a compiler error. If you declare two methods that
> differ only in (non-covariant) return type, you get an error. If you
> add checked exceptions to a method override, you get an error. The
> mental dodge of pretending that exceptions and return types are part of
> the signature helps me keep that straight.


The examples you give tend to prove the opposite of what you seem to
intend, rather. If the return type and the exceptions clause were part
of the signature, then two methods which differ only in return type
would have a _different_ signature, and thus it wouldn't be an error.

df.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      02-16-2008
Daniele Futtorovic wrote:
> The examples you give tend to prove the opposite of what you seem to
> intend, rather. If the return type and the exceptions clause were part
> of the signature, then two methods which differ only in return type
> would have a _different_ signature, and thus it wouldn't be an error.


An excellent point. Actually, the JVM's definition of "descriptors" matches
what I was saying before. Thus am I corrected and have learned something new.

--
Lew
 
Reply With Quote
 
Daniele Futtorovic
Guest
Posts: n/a
 
      02-16-2008
On 2008-02-16 04:40 +0100, Lew allegedly wrote:
> Actually, the JVM's definition of "descriptors"
> matches what I was saying before.


And so the loose ends are joined together and it seems like we have
answered the original question in a rather exhaustive manner. Not bad
for a runaway OP. )
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
Turning a signature-changing decorator into a signature-preservingone Gustavo Narea Python 14 02-16-2009 04:58 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
UTF-8 with signature & UTF-8 without signature JJBW ASP .Net 1 04-24-2004 10:21 AM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments