Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Java compatibility issues (WAS: MF having issues?)
Michael Wojcik<mwojcik@newsguy.com> 03/08/06 12:21 PM >>>
>
>In article <476delFe2lamU2@individual.net>, "Frank Swarbrick"
<Frank.Swarbrick@efirstbank.com> writes: 
method 
from 
>
>Same reason why you need them around a literal program name in a call
>statement.  The method name can be a data-item as well as a literal:
>
>   move "myMethod" to method-name
>   invoke myObject method-name ...
>
>This is actually quite different from the C-derived languages, which
>support *neither* of those name-resolution methods directly.  In C,
>for example, a called function can only be specified using a variable
>of a function-pointer type, or the name of a function - which is
>actually the name of a function-type variable, and decays to a
>pointer-to-function-type variable in most contexts.  (Function-type
>variables in C are immutable, so "variable" is a bit of a misnomer,
>but from the language's point of view that's what they are.)
>
>C-derived languages thus require other mechanisms to call a function
>using a name determined at run-time, and in fact there's no standard
>way to do that in C.
>
>Thus in Java you write:
>
>   myObject.myMethod(...);
>
>because you can't write:
>
>   String myMethodName = "myMethod";
>   myObject.myMethodName(...);
>
>But in COBOL, in effect, you can do the latter, so it has to be
>distinguished from the equivalent of the former.

Makes sense!  Thanks for the clarification.

I believe you can do something similar in Java, though.  I just now tried
this.

instead of:
try {
worksock.connect(s_addr);
}
catch (Exception e) {
System.out.println(e);
return;
}

You can do:
try {
Class[] methodParms = new Class[1];
methodParms[0] = SocketAddress.class;
Class socketClass = worksock.getClass();
Method myMethod = socketClass.getMethod("connect", methodParms);
Object[] parmObjs = new Object[1];
parmObjs[0] = s_addr;
myMethod.invoke(worksock, parmObjs);
}
catch (Exception e) {
System.out.println(e);
return;
}

Not that I'd recommend it!  You may be able to simplfy it somewhat, but I'm
not Java expert, so I'm not sure how...

Frank


---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO  USA

Report this thread to moderator Post Follow-up to this message
Old Post
Frank Swarbrick
03-08-06 11:55 PM


Re: Java compatibility issues (WAS: MF having issues?)
In article <4793b3FekqcoU1@individual.net>, "Frank Swarbrick" <Frank.Swarbrick@efirstbank.c
om> writes:
> Michael Wojcik<mwojcik@newsguy.com> 03/08/06 12:21 PM >>> 
>
> Makes sense!  Thanks for the clarification.
>
> I believe you can do something similar in Java, though.  I just now tried
> this.
>
> ...
> 	Method myMethod = socketClass.getMethod("connect", methodParms);
> 	Object[] parmObjs = new Object[1];
> 	parmObjs[0] = s_addr;
>                 myMethod.invoke(worksock, parmObjs);

Right, but there's the extra indirection of creating a Class object
and a Method object and so forth.  (This is what there's no standard
for in C.  There *is* a standard way to do it in Java, as you've just
described.)

COBOL, on the other hand, has syntactic sugar to do the "look this
name up and resolve it to the code I want to call" bit, right in the
CALL or INVOKE verb.

Languages with first-class functions, like Scheme and OCaml, have yet
another variation on this: you can have function names and function
variables and functions you compute at runtime, and you can pass
functions as parameters and return new functions.  They're even more
flexible when it comes to invoking functions and methods because the
thing they're invoking may not have existed until right before the
invocation.

In summary:

C: You can only call functions known at compile time, directly or
through pointers, in the standard language.

Java: You can call methods using a name known at runtime, but you
have to go through extra hoops to do so.

COBOL: You can call programs and methods directly or by name, but
they have to have been previously compiled.

Functional languages: You can call functions you just made up a
moment ago in the running program.

--
Michael Wojcik                  michael.wojcik@microfocus.com

Duck: No secret what's worth a hoot ought to be kept quiet.
Pogo: Secrets is usually perty doggone fascinatin'.
Duck: Egg-zackly ... it's completely illogical to keep a secret secret.
Pogo: An' unfair.					-- Walt Kelly

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Wojcik
03-09-06 11:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:04 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.