Section 5j

Using External Methods


 

 

 

 

 

 

 

 

 

 

 

 

Other people's programming

One of the difficulties to writing simple programs is that some of the things we think are simple are actually kind of complex. It seems like it should be easy to get the square root of a number or take a number to an exponent power in a computer program but it turns out the code can get larger and more complicated than we need for our simple programs.

The use of library, or external, methods helps keep simple programs simple by providing commonly used mathematical methods to programmers who include the particular library in their programs. The most common library is the Math class which can conduct the following actions, and many more.

sqrt, calculates the square root of a double value

sin, cos, tan, returns the appropriate trigonometric value, although it takes its input in the form of radians

pow, accepts a double base and exponent, and calculates the base to the power

There are thousands of other library methods that can conduct several different operations. You only need to look these up and apply them. The most commonly suggested resource is at the Oracle® site. Oracle owns the Java language and does their best to keep the references up to date.

Again, watch this video for more information about library methods. The program provided for this video is a good example of a testbed program where you can just check out how things work. Again, it is worth your while to try out the code and keep up your comfort level with whipping out programs.