Basic Syntax


Java is a C-based language, which doesn't help you much coming from a Fortran background. There are significant differences in the basic syntax between Java and Fortran. Don't worry too much about this. The Java compiler is very good at pointing out if and where you slipped back into the Fortran way of doing things.

Both Fortran and Java allow free-form coding. You can indent the executable statements any way you like. Indentation is normally used to make a code more readable. Unlike Fortran, Java is case sensitive. All Java keywords ( new , public , final , etc.) must be entered in lowercase. Identifiers are likewise case sensitive. For example, myVariable is not the same as MYVARIABLE or MyVariable to the Java compiler. All executable statements in Java are terminated with a semicolon. There are no PARAMETER or DIMENSION statements in Java. Java does not have common blocks.

In Java, blocks of code are designated using braces. Since Java classes and methods are named blocks of code, their contents are placed inside braces. You can designate blocks of code pretty much wherever you like. Code blocks define areas of scope. Variables exist only in the block of code in which they are declared. Once program execution leaves a block of code, any variables declared inside the block disappear.

Comment statements are different in Fortran and Java. Java defines both multiline or single line comments. A multiline comment starts with the characters /* and ends with the characters */ . As the name implies, a multiline comment can span multiple lines. Single line Java comments start with the characters // . Java also supports documentation comments. This type of comment can be incorporated into an HTML file describing the Java source code.

The basic mathematical and assignment operators, *, /, +, -, and =, are the same for both languages. Java supports additional types of operators including combination mathematical/assignment operators and operators used when working with objects. Java uses the symbolic Fortran relational operators ( == , < , <= , > , and >= ) rather than the original Fortran operators ( .NE. , .LT. , .LE. , .GT. , and .GE. ).

There are similarities and differences in the loop and flow control structures between the two languages. Fortran defines an IF-END IF conditional structure. Java defines a similar construct using the syntax if-else . The Fortran DO-END DO loop is similar in nature to the Java for loop. The Fortran SELECT-CASE structure is similar in nature to the Java switch statement. Java provides additional flow control structures that Fortran does not, including the while and do-while statements.



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