File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes return value??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "return value???" Watch "return value???" New topic
Author

return value???

Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
i have 2 class....class A and class B....in class A i want to call a method in class B and send 2 parameter(v1 and v2).....in class B, it will transform v1 and v2 into v3 and v4.....the problem is...i need to send back the 2 new variables(v3 & v4) to class A....we can only return one value.....so, what i can do to send v3 & v4 back to class A???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You can return an array if the values are of the same type or you can send back an object that contains the two values as it's properties.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
if i send back an object does that means after that i can separate it into 2...???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, create setter and getter methods for the two properties.

Set the two properties from within your method, return the object and then read the properties to get the values.
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
sorry...i cant really understand u....can u give me some example...
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If v1 and v2 are objects instead of primitives, the easiest solution is an Object array (or a specific array if they have the same class). Here's a trivial example:This will output the following.Does that clarify it? Ben's suggestion is to define a class with fields that will hold the returned objects along with a pair of get/set methods (accessors) for each. This class would satisfy the JavaBean requirements, so you might want to look that up at Sun's Java site if you need examples.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I hope this isn't too hard to read.
I tried to make it, simple, terse, and readable, in a short amount of time.




[ February 22, 2005: Message edited by: Ben Souther ]
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
thanks everybody....i manage to solve my problem....thanks to ben and david...i really appreciate the help from both of u...
Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Hii

Can we define a function in A class which can take 2 variables and call the function in B class so that v3 and v4 can be sent to class A ?

Thanks
Regards
M.Kartik
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Kartik Mahadevan:
Hii

Can we define a function in A class which can take 2 variables and call the function in B class so that v3 and v4 can be sent to class A ?

Thanks
Regards
M.Kartik


Yes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return value???