Hi sushil,
Here we go....
Create your own class called myString
public myString
{
public String value = "VAlue of string you want to store and change in
method";
public String toString()
{
return value;
}
}
Now your application(test) will look like...
public class test
{
public static void main(String args[])
{
myString str1 = new myString();
str1.value = "AAAAAA";
// String str1 = "AAAAAA";
method1(str1);
System.out.println("After returning from str1: " + str1);
}
static void method1(myString str1)
{
System.out.println("str1: " + str1);
str1.value = "xxxxxx";
}
}
This is what you want, I guess !!!!
Hope this help you ...
Mahesh
"Singh, Sushil" <[EMAIL PROTECTED]> wrote:
Hi Mahesh:
Thanks for your reply.
I will be really greatful to you if you can provide me more information
about about how to manipulate the String clasess in terms of "Passed by
reference".
Thanks,
Sushil
-----Original Message-----
From: Mahesh Patil [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 16, 1999 5:01 AM
To: [EMAIL PROTECTED]
Subject: Re: [Re: Parameters passed by reference]
Hi sushil,
In Java object parameters are passed by reference but String class is a
immutable so you can not change the value of string object. You can make a
wrapper class to String and manipulate string value inside.. If you are
still
not clear let me know....
Mahesh
"Singh, Sushil" <[EMAIL PROTECTED]> wrote:
Hi Mann:
Thanks for your reply.
I am providing you the listing of a small program:
================= Start of program ======================
import java.lang.*;
public class test
{
public static void main(String args[])
{
String str1 = "AAAAAA";
method1(str1);
System.out.println("After returning from str1: " + str1);
}
static void method1(String str1)
{
System.out.println("str1: " + str1);
str1 = "xxxxxx";
}
} // End of test
===================== End of program ========================
In this java program, I am setting value of variable str1=AAAAAAA and then I
am calling another method which is just simply printing the value of str1
and set again set a new value which is "xxxxxxx" but now if I print the
value of str1 its containing the old value only.
Actually my requirement is for servlet only. I am using "AS/400 Record
level of access", in order to access the DB2. In servlets I am having lots
of methods: method1 is for positioning of file pointer, method2 is for
reading the record and so on.
So in order to maintain the file pointer my requirement is to pass the AS400
file object as reference.
Thanks,
Sushil
Email: [EMAIL PROTECTED] (Personal)
[EMAIL PROTECTED] (Official)
-----Original Message-----
From: Kito Mann [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 15, 1999 1:20 PM
To: [EMAIL PROTECTED]
Subject: Re: Parameters passed by reference
Sushil,
First, this question is way off topic.
All Objecs in Java are passed by reference. Objects include Strings and
Arrays, but not the primitive types: (ints, chars, longs, floats, etc.).
So, for instance, in the following excerpt:
public void test()
{
String s = "This is a string";
myMethod(s);
myMethod(s.clone());
myMethod2(5);
}
public void myMethod(String s)
{
System.out.println(s);
}
public void myMethod2(int i)
{
System.out.println(i);
}
The first call to myMethod() is passing the variable "s" by reference; the
second call is passing a _copy_ by reference, which is the closest you can
get to passing an Object by value. The call to myMethod2() will _always_
pass the variable by value, since the parameter is a primitive type and not
an Object. You can't pass primitive types by reference, but you can use one
of the wrapper Objects (Integer, Float, etc.) and pass those by reference.
Kito D. Mann
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Wednesday December 15, 1999 09:27 AM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc: (bcc: Kito Mann/PSG/Prudential)
Subject: Parameters passed by reference
Hi,
I would like to know that how can we pass a variable by REFERENCE to a
method within the same class.
I have read that in order to pass by reference, we have to pass the object
itself. But in my case I have to pass a variable say string to a method
inside the same class.
Thanks,
Sushil
Email: [EMAIL PROTECTED] (Personal)
[EMAIL PROTECTED] (Official)
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html