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 Passing arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Passing arguments" Watch "Passing arguments" New topic
Author

Passing arguments

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
I'm having a problem with passing arguments, and I figure it's something really stupid that I'm doing wrong. The arguments are going into the routine right, but the routine is suppose to modify them and return the modified values back. What's coming back is the original values.

Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Java is pass by value.

If you find yourself passing two values to a function, and wanting to return the two values, those values prob'ly belong in their own class. And indeed there is a Date class in java you can use.

I suggest the new method take the Date instance, create a new Date instance with the new value, and return that.

[edit: Date not Data, fixed typo]
[ February 08, 2008: Message edited by: Bill Shirley ]

Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9948
    
    6

When you pass something into a method, you basically make a copy of it. in your case, you'll have a datePascha from the main method, then inside your getDateOfPacha method, you create a second variable called dateOfPascha, and you give it the same value.

When you change dateOfPascha inside your method, that does nothing to datePascha outside of your method.


Never ascribe to malice that which can be adequately explained by stupidity.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Bill,

Thanks. From the article I cheated, passing an array in and out, then reassigning the array to a scalar. Not the best method, but quick and works.

Do you have a link to something that would explain the Data Class?

Thanks,

Mike
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
The API docs on the Date class are pretty good.

Also, Calendar may be of some use.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Originally posted by Bill Shirley:
If you find yourself passing two values to a function, and wanting to return the two values, those values prob'ly belong in their own class. And indeed there is a Data class in java you can use.


Bill, you mentioned a "Data class", that is what I was asking about, not the Date routines. Do you have a link to something about the Data class?
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Originally posted by Mike Lipay:
Bill, you mentioned a "Data class"... class?


Sorry, typo

Data -> Date
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Passing arguments
 
Similar Threads
Static method can only handle static variables but why is it still working in case of local variable
first java am stuck
oop Concept
array index out of bound problem
Worker thread. Comments please