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 Pass by ref- pgm err Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pass by ref- pgm err" Watch "Pass by ref- pgm err" New topic
Author

Pass by ref- pgm err

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Hi,

I am having doubt in Pass by Value and Pass By Reference in Java. So I tried to run the following pgm. It displaying error:



Error Message:
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

public static void changeObjectRef(MyDate ref)

{
ref = new MyDate(1, 1, 2000);
}
public static void changeObjectAttr(MyDate ref)
{
ref.setDay(4);
}

Your method should define the argument "ref" of type "date" and not "Mydate".


If you are not laughing at yourself, then you just didn't get the joke.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

try changing all your MyDate to Date.
Moreover Date(int year, int month, int date) is deprecated.
Try using java.util.Calendar;
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

I am having doubt in Pass by Value and Pass By Reference in Java.
There's nothing to doubt; Java is always pass-by-value. Pass-by-reference is not possible in Java.

(Don't let that stop you from experimenting, though...)
Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200
Yes, I imported java.util.calendar; and replaced MyDate with Date. Still it's pointing out the same error.

Error
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Java is case sensitive: java.util.calendar is not java.util.Calendar.

Second, in order to use Date, you have to import java.util.Date, not java.util.Calendar.

(Thirdly, I never import java.util.Date anyway, since the package name is short and java.util.Date can be confused with java.sql.Date, so I always spell them out anyway...)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
Consider Paul's rocket mass heater.
 
subject: Pass by ref- pgm err