Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2008, 10:16 PM
Member
 
Join Date: Jan 2008
Posts: 7
frejon26 is on a distinguished road
method calling?
hello,
I was wondering in what order are method calls completed on an object?
left to right? or right to left?

say you have a large StringBuffer object with many characters and you want to 1). convert it to a String, 2). get a substring within it and 3). test for an indexOf(".exe");
does it matter how it is written?

string_buff.toString().substring(start,end).indexO f(SPECIAL_EXTENSION);

-thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-24-2008, 11:20 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
This is simple, go over your code above from both direction you will realize you can't get index of exe before you have that substring and you cant get that substring before you convert that object to string.
Answer is obvious. Forgive me not giving direct answer but i hope you will love the approach.
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-24-2008, 11:39 PM
Member
 
Join Date: Jan 2008
Posts: 7
frejon26 is on a distinguished road
well that is my question, from which direction does it start? if from left to right then, 1)it first turns it to a string, then 2) it turns it to a substring then 3) gets the index of it.
if method calling starts from the right then it would make sense to write the code,
string_buff.indexOf(SPECIAL_EXTENSION).substring(s tart,end).toString();
so which way does the virtual machine call the methods?

Last edited by frejon26 : 01-24-2008 at 11:46 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-25-2008, 12:29 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 251
roots is on a distinguished road
Let's for the sake of discussion indexOf returns String and we are playing with string only.

If we see last part it's toString() of something not substring of toString() of nothing. Rather than the direction it's problem of the dot operator. I think both of us know the answer and do you like if the dot operator on string_buff is associated with toString() in your second code.
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-25-2008, 04:38 AM
Member
 
Join Date: Jan 2008
Posts: 7
frejon26 is on a distinguished road
thanks roots,
I'm still a little confused but I don't think it makes sense the other way I wrote it (my second post). I also didn't ask the question very well. I see that it is objects calling methods, so...
if you have object.method1().method2().method3();
it goes object.method1() which in its place is the return on the method so then return value is used with the next value return.method2() which then returns another value which will finally be used with method3();

thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic method calling Java Tip Java Tips 0 02-15-2008 09:46 AM
Calling a method in another class uncopywritable New To Java 8 01-14-2008 05:37 PM
i'm no good in calling Method please help lowpro New To Java 1 11-26-2007 06:15 PM
Help with Calling a method Albert New To Java 3 07-10-2007 04:27 PM


All times are GMT +3. The time now is 04:24 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org