File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes calling methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling methods" Watch "calling methods" New topic

calling methods

Elon Zibitt

Joined: Apr 30, 2001
Posts: 2
ok, so i have a class that has 2 methods. method 1 parses an xml document and grabs a specific value. the second method formats the value. do i have to run both methods from a thrid method in order for the main to print out the formatted value? if so how would i do that?
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
You could call both methods from within the main method.
public static void main(Sting[] args)
// this example is assuming the value is a String
// of course it may be whatever
String value = method1( xmldocument);
String foirmattedValue = method2( value );
// or you could do it this way but it is a little less obvious
// chaine the output of method1 into the call to method 2
String formattedValue = method2( method1(xmldocument) );
Peter Tran

Joined: Jan 02, 2001
Posts: 783
timonthy's solution assumes that everything inside the class containing this main method is static. If they aren't and method1 and method2 are instance methods, then you'll need to allocate an instance of the class before you call those methods.

I agree. Here's the link:
subject: calling methods
jQuery in Action, 3rd edition