aspose file tools*
The moose likes Java in General and the fly likes Passing Parameter between Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Passing Parameter between Methods" Watch "Passing Parameter between Methods" New topic
Author

Passing Parameter between Methods

Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
I have some problems because i don't really know how to pass parameter between methods in a java class.
How can i do that? below is the code that i did.

I want to pass in the parameter from a method called dbTest where this method will run StringTokenizer to capture the input from a text file then it will run storeData method whereby later it will then store into the database.

How can i pass data between this two methods whereby i want to read from text file then take the value to be passed into the database to be stored?

Thanks alot


[ November 08, 2006: Message edited by: Eric Tan ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Well, you seem to already know how to pass arguments to a method, as (for example) here:

File f = new File("c:\\abc.txt");

In that line, you're sending the String "c:\\abc.txt" to the File constructor; the File constructor does whatever it want to with that String. If you saw File's constructor, it would look like

File(String filename) { ...

That means the constructor takes a single String argument. Inside the File constructor, the String is available as the variable "filename".

So you want "storeData" to take some number of arguments. For example, you might like four arguments:

public void storeDate(String fname, String lname, String city, String state) ...

and then you'd pass those four arguments when you call it, and inside storeData, those four variables would be available.

Now the problem here is that you've written storeData so that it calls dbTest, and written dbTest as if it were going to call storeData; I think you just need to clarify in your mind what each routine does.

Does this help?


[Jess in Action][AskingGoodQuestions]
Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
I understand what you mean about the clarification regarding the storeData and dbTest. Sometimes i also confuse myself on the way i wrote the codes. But i know that i have two instance method inside a class file and my main method is to run the dbTest first and then storeData. I might be wrong in this but please do correct if i am wrong. I will look into the info that you told me. Thanks alot..
Eric Tan
Ranch Hand

Joined: Oct 11, 2006
Posts: 72
In order for me to pass in the parameter from dbTest to storeData. in my main method, how can i declare an object to store it? i know that inside the parentheses is the value what you need to return in order for me to use the storeData method to store my data. Can anyone guide me again on this? i might be wrong in my explanation. Sorry about that. Thanks alot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Parameter between Methods