aspose file tools*
The moose likes Beginning Java and the fly likes Methods!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Methods!!" Watch "Methods!!" New topic
Author

Methods!!

usman ahmad
Ranch Hand

Joined: Mar 06, 2001
Posts: 46
Hi!
when I use a method, I must know three pieces of information to use the method to it's full potential.
1)the type and no. of arguments the method requires.
2)The methods' return type.
3)The type and number of Exceptions the method throws.
Can anybody please elaborate on the above statement.More detailed.
Regards and best wishes
Usman Ahmad.
paul edwards
Greenhorn

Joined: Mar 12, 2001
Posts: 6
Hi,
A method requires certain things to be passed to it to work. For example a method that sets a name would require a name be passed it;
ie: setName("Paul");
some methods require more than one.
ie: addInts(5, 6);
some methods require none;
ie: isTrue();
which brings up return type, int the first example, the method is simply going to set somethings name property, so it returns nothing, and would be declared void.
in the second example, you are running the method and expecting a numerical result, in this case an integer(int), so you might use the method like this:
int x = a.addInts(5, 6);
in the third example, you are expecting a yes or no answer, which is a boolean value of true or false, so . . .
boolean tester = a.isTrue();

exceptions opens up a whole can of worms. Basically, to get a program to compile you have to know what exceptions it's methods throw so that you can take them into account via a try/catch/finally exception handler, or via a throws(some exception) statement in the class declaration.
There is a big section on exception handling in the java tutorial. this is just a very brief explanation.

Hope that helps!
Paul
usman ahmad
Ranch Hand

Joined: Mar 06, 2001
Posts: 46
Thanks! that helped.
Regards usman
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods!!