Subroutines, Functions, and Methods


Subroutines, Functions, and Methods

A Fortran subroutine or function is a named section of code that can be called from somewhere else in a Fortran program. A subroutine or function declaration consists of the subroutine name and input argument list. The body of the subroutine or function follows the declaration and is terminated with an END SUBROUTINE statement. A Fortran subroutine or function is called using the call keyword followed by the subroutine or function name and input argument list.

A Java method is a named block of code that can be called from somewhere else in a Java program. A Java method declaration consists of the method return type, method name, input parameter list, and, optionally , one or more modifying keywords. The body of the method is enclosed in braces ({}). Java methods can be declared to be public , private , protected static , abstract , final , native , and synchronized .

Java methods can be instance or static. An instance method is associated with an instance of a class (an object). A static method is associated with a class rather than with an instance of a class. Static methods are sometimes referred to as class methods. Instance and static methods are called in different ways. Inside the class in which they are defined, both instance and static methods are called by simply typing the method name and providing the correct number and type of arguments. Outside of the class in which they are defined, instance methods are called by referencing a specific object. Static methods are called by typing the class name, a period, and then the method name.

All arguments to Java methods are passed by value. For arguments representing primitive data types, a copy of the argument value is sent to the method. Any changes made to the value inside the method will not be made to the original value. For arguments representing reference types (objects or arrays), a copy of the reference to the location in memory where the data for the object or array is stored is sent to the method. Any changes made using this reference inside the method will also be made to the original object.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net