Terminology: Are There Messages in Java?

S

Stefan Ram

How is »f(0)« called in »o.f(0)«?

I am inclined to call it a »message«.

It can not be referred to as »call« or »invocation«, because
the whole expression »o.f(0)« already is the call/invocation.

The object »o« is sometimes referred to as »target object«
or »context« of the call in the JLS, IIRC. But I am not aware
of wording for the part »f(0)«.

Let's ask the JDK:

public class Main
{ public static void main( final java.lang.String[] args )
{ class C { void f( final int arg ){} void f( final double arg ){} };
new C().f( true ); }}
Main.java:4: cannot find symbol
symbol : method f(boolean)

So a (possibly slightly extended) signature is referred to as
a »symbol« by the JDK, but this refers to »f(boolean)«, not
»f( true )«.

So, is there a more Javaish term for »f(true)« than »message«
in this case?
 
S

Stefan Ram

Mark Space said:
Does "method" not work? It confuses the call with the declaration, I
guess, but sometimes words get overloaded too, just like method names.

I hesitate to call »f( 2 )« a »method« for at least two
reasons:

In the call »( a() ? b : c ).f( 2 )«, »b« and »c« might have
different classes, with different methods matching »f( 2 )«.
So, the »f« in »f( 2 )« does not actually refer to a specific
method yet (before evaluation of the complete expression).
It is a simple method /name/ (»selector«), not a method.

»f( 2 )« contains more information than just the name »f«,
it also contains the argument value »2«, which might be deemed
to be just as »important« as the »f«.
 
L

Lew

Stefan said:
I hesitate to call »f( 2 )« a »method« for at least two
reasons:

In the call »( a() ? b : c ).f( 2 )«, »b« and »c« might have
different classes, with different methods matching »f( 2 )«.
So, the »f« in »f( 2 )« does not actually refer to a specific
method yet (before evaluation of the complete expression).
It is a simple method /name/ (»selector«), not a method.

»f( 2 )« contains more information than just the name »f«,
it also contains the argument value »2«, which might be deemed
to be just as »important« as the »f«.

It's a "method call" or a "method invocation".
 
S

Stefan Ram

Patricia Shanahan said:
"f(0)" is an "Identifier ( ArgumentList_opt )".
Why should this particular portion of the MethodInvocation need a term
of its own?

So that one can refer to it in teaching (when giving classes)
by a more simple means than »Identifier ( ArgumentList_opt )«.
 
S

Stefan Ram

So that one can refer to it in teaching (when giving classes)
by a more simple means than »Identifier ( ArgumentList_opt )«.

As an example, I am introducing the notion »object« (»instance
of a class«) at a point, where static methods, classes and
messages are already known (a »message« being »Identifier
( ArgumentList_opt )«). I then explain:

For a class, there might be so-called »instances« at run time.

An instance of a class also is called an »object«.

An object can interpret (execute) certain messages.

The class of an instance determines, which messages it can
execute and how it does execute them.

This section does not deal with the implementation of objects,
just with the application of objects of standard classes.

I believe the four sentences above give the most fundamental
assertions about objects in Java (omitting some details).

Maybe a reader would like to suggest alternative wording for
the contents of these four sentences that does not use the
term »message«.
 
A

Arved Sandstrom

Patricia said:
...

"f(0)" is an "Identifier ( ArgumentList_opt )".

Why should this particular portion of the MethodInvocation need a term
of its own? It is meaningless without the "o." portion.

It would be different if Java used the "send a message to an object"
model of communication between objects, but it doesn't.

Patricia

It depends on your semantics. A lot of commentators are quite happy to
say that method invocation _is_ dispatching a message.

Are messages first class objects in Java? No. They're internalized.
Which is what I believe you were getting at.

AHS
 
R

Roedy Green

So, is there a more Javaish term for »f(true)« than »message«
in this case?

You would call it an "expression". I don't know of something more
specific. "Message" is a Smalltalk term most Javites would not be
familiar with.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Think of the earth as a living organism that is being attacked by billions of bacteria whose numbers double every forty years. Either the host dies, or the virus dies, or both die."
~ Gore Vidal
 
M

Mark Space

Stefan said:
I hesitate to call »f( 2 )« a »method« for at least two
reasons:

In the call »( a() ? b : c ).f( 2 )«, »b« and »c« might have
different classes, with different methods matching »f( 2 )«.
So, the »f« in »f( 2 )« does not actually refer to a specific
method yet (before evaluation of the complete expression).
It is a simple method /name/ (»selector«), not a method.


There's a . in there though. .f(2) is definitely a method invocation.

1 + 2

o . f(2)


Is kind of how I look at that. o.f(2) means "o invokes the method f(2)",
which might fail if there are no methods named f with a matching
signature, but other operators have arguments which might fail too,
either at compile time or runtime.
 
S

Stefan Ram

Mark Space said:
There's a . in there though. .f(2) is definitely a method invocation.

Patricia got this right: it is just a part of the method invocation,
which is

Primary . NonWildTypeArguments_opt Identifier ( ArgumentList_opt )

. see JLS3, 15.2
1 + 2
o . f(2)

»1« and »2« are subexpressions. They can be put in parentheses:
»((1)+(2))«.

I believe this is not possible: »((o).(f(2))« - »f(2)« is not a
subexpression.
 
L

Lew

Stefan said:
As an example, I am introducing the notion »object« (»instance
of a class«) at a point, where static methods, classes and
messages are already known (a »message« being »Identifier
( ArgumentList_opt )«). I then explain:

For a class, there might be so-called »instances« at run time.

An instance of a class also is called an »object«.

An object can interpret (execute) certain messages.

The class of an instance determines, which messages it can
execute and how it does execute them.

The Java literature generally doesn't use the term "messages" this way,
although it is consistent with the larger world of object-oriented thinking.
 
C

cbossens73

It would be different if Java used the "send a message to an object"
model of communication between objects, but it doesn't.

Your sentence needs clarification.

You can send messages to objects in Java. Actually everytime
you make a method call on some instance you're passing a message
to an object.

It is widely accepted that:

1. "Message passing" is central to OO (*)

2. It's possible to do OOP in Java.


So which "model of communication" does Java use if it's not
the "send a message to an object" [sic] model?

And how do you pass messages in Java?



(*)
"ACM, Armstrong, The Quarks of Object-Oriented Development.
"In descending order of popularity, the "quarks" are:
"Inheritance, Object, Class, Encapsulation, Method,
"Message Passing, Polymorphism, Abstraction

(These are the OO terms, not the "Java" terms --the
difference being most notable for the word "Class"
probably but all these OO concepts applies to third
generation OOP languages like Java, *including message
passing*)
 
M

Mark Space

Patricia said:
...

"f(0)" is an "Identifier ( ArgumentList_opt )".

Why should this particular portion of the MethodInvocation need a term
of its own? It is meaningless without the "o." portion.


You're quoteing from section 15.12?

15.12 Method Invocation Expressions
A method invocation expression is used to invoke a class or instance method.


MethodInvocation:
MethodName ( ArgumentListopt )
Primary . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )
ClassName . super . NonWildTypeArgumentsopt Identifier (
ArgumentListopt )
TypeName . NonWildTypeArguments Identifier ( ArgumentListopt )


Later in the text, they refer to something like "f" as a "simple name,"
to distinguish it from a fully qualified name I suppose.

So "name" and "method name" seem like they might also be candidates for
what "f" is referred to.

They also refer to the Identifier as a method: "If the Identifier
appears within the scope (§6.3) of a visible method declaration with
that name, then there must be an enclosing type declaration of which
that method is a member." It's a little unclear, but "that method"
could refer to the identifier.

Later still: "If it is a qualified name of the form TypeName .
Identifier, then the name of the method is the Identifier and the class
to search is the one named by the TypeName." So again "method" and
"name" are used.

Etc.

"Identifier" seems to be to be a term that's an artifact of the parsing
process. It's a potential method name, but might not be spelled
correctly or could have some other meaning, I suppose, depending on context.
 
M

Mark Space

1. "Message passing" is central to OO (*)


I always assumed that "message passing" was just a high level term for
virtual table dispatch and therefore polymorphism. It's just a way to
refer to call invocation without actually implying any underlying
implementation.
 
M

Mark Space

Stefan said:
»1« and »2« are subexpressions. They can be put in parentheses:
»((1)+(2))«.

I believe this is not possible: »((o).(f(2))« - »f(2)« is not a
subexpression.

Nope, you're right about that. o.(f(2)) is not a valid method invocation.
 
S

Stefan Ram

Patricia Shanahan said:
I think it arises because of the need to make the formal grammar
context-free. The problem is that properties such as being a method name
depend on declarations.

A method name can also be of the form »AmbigousName.Identifier«
(JLS3, 6.5), which is not allowed for the Identifier of a, er, message.

MethodName:
Identifier
AmbiguousName . Identifier

JLS3, 6.5
 
D

Daniel Pitts

Stefan said:
I hesitate to call »f( 2 )« a »method« for at least two
reasons:

In the call »( a() ? b : c ).f( 2 )«, »b« and »c« might have
different classes, with different methods matching »f( 2 )«.
Except the method can't be on different classes. The static type of both
b and c must have a shared base class that defines f(int );
So, the »f« in »f( 2 )« does not actually refer to a specific
method yet (before evaluation of the complete expression).
It is a simple method /name/ (»selector«), not a method.
Its not actually a method name selector, but a virtual method invocation.
»f( 2 )« contains more information than just the name »f«,
it also contains the argument value »2«, which might be deemed
to be just as »important« as the »f«.
The invocation contains the information of what is being invoked, and
what is being passed to it. Thats why the Method.invoke method is
declared to take arguments.
java.lang.reflect.Method.invoke(Object targetObject, Object...arguments)
 
S

Stefan Ram

Daniel Pitts said:
Except the method can't be on different classes. The static type of both
b and c must have a shared base class that defines f(int );

class B implements I { public void f( final int i ){ A.b(); }}
class C implements I { public void f( final int i ){ A.c(); }}

I believe most readers would say that the two declarations of
f above declare /two different/ methods (»on two different
classes«), even though they share a common signature (aka
»abstract method«) within an interface I.
 
L

Lew

class B implements I { public void f( final int i ){ A.b(); }}
class C implements I { public void f( final int i ){ A.c(); }}

  I believe most readers would say that the two declarations of
  f above declare /two different/ methods (»on two different
  classes«), even though they share a common signature (aka
  »abstract method«) within an interface I.

Your belief aside, the statement is not quite accurate.

I would say that the two declarations declare two different
*implementations* of the same interface method 'I#f(int)'. Both
declarations define the same method from the point of view of 'I', but
arguably different methods from the points of view of 'B' and 'C'.

The common base type is 'I'. Daniel's comment vis-a-vis the ternary
was that 'b' and 'c' in the expression need to be of a common type
that defines 'f(int)' for the expression to be grammatical. In the
ternary '( a() ? b : c ).f( 2 )', the method invoked is 'I#f(int)'.
(Assume that 'b' is of type 'B' and 'c' is of type 'C'.) Both 'b' and
'c' implement the same method 'I#f(int)'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top