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 Void Return Type Methods and Mathematical Functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Void Return Type Methods and Mathematical Functions" Watch "Void Return Type Methods and Mathematical Functions" New topic
Author

Void Return Type Methods and Mathematical Functions

Ken Austin
Ranch Hand

Joined: Aug 20, 2012
Posts: 39

While preparing for an upcoming Coursera course (Introduction to Algorithms) I came across this statement in the text

For example, the main() static method in our programs has a void return type
because its purpose is to produce output. Technically, void methods do not
implement mathematical functions
(and neither does Math.random(), which
takes no arguments but does produce a return value).
-- p. 24 Algorithms (4e), Sedgewick & Wayne

Bold mine.

The part in bold stumped me. Can someone walk me through that statement?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

The strict interpretation of a function is that basically, you give it some input (like 90 degrees), and you get some new value out - like 1. For any given input, there is exactly one possible output.

Since a method of type void does not give you back a return value, it does not fit the definition of a mathematical function.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
And since Math.random() takes no arguments, and since it gives you different results each time it's called, it's not a function either.
Ken Austin
Ranch Hand

Joined: Aug 20, 2012
Posts: 39

Ah, yes. Thank you, both.

I was missing the computer science specific definition of the word "implement."

I thought we were about to get into a deep discussion about design theory.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
No, more a deep discussion of maths.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Void Return Type Methods and Mathematical Functions