CTG - Java Syntax

Overview
  [Supercomputing]
  [Project Development]
  [Project Design]

Login Procedure
  [ssh (Putty) ]
  [Tutorial]

Unix
  [Basic Commands]
  [Utilities]
  [Pico]
  [Cygwin]

C++
  [Background]
  [Tutorial]
  [Advanced Syntax]

Java
  [Background]
  [Tutorial - Unix]
  [Tutorial - PC]
  [Advanced Syntax]

Graphics
  [gnuplot]
  [Tutorial]

Extras
  [Cygwin-X11]
  [E-mail]
  [ftp]
  [HTML]
  [Resources]

Supercomputing Challenge
  [Home Page]
  [Technical Guide]

This page inlcudes syntax only and is intended for those with some programming experience. You will not learn when to use the code, why it works, or how to incorporate it into your program.

You may include any or all of the following syntax into your program to make your code handle increasingly complex problems.

Note: Notice how close Java and C++ are in their syntax!

  • Comments
    // This is a single-line comment.
    
    /* This comment spans across
    more than one line. */
  • Conditional Statements
    if (boolean expression)
    {
    	statement 1;
    	statement 2;
    	statement 3;
    }
    else if (boolean expression)
    {
    	statement 1;
    }
    else
    {
    	statement 1;
    	statement 2;
    }
    
  • While Loop
    while (condition)
    {
    	statement 1;
    	statement 2;
    }
    
  • For Loop
    for (initialize ; condition ; update )
    {
    	statements;
    }
    
  • Do Loop
    do
    {
    	statement 1;
    	// notice semicolon at the bottom
    	statement 2;
    } while (condition);
    
  • Arrays
    int [] my_array = new int[10];
    	// Declaring Array w/10 Integers
    my_array[0]=12;
    my_array[1]=35;
    	// Initializing Array elements
    
    int [] my_array2 = {3,1,9,3,7,5,8,7,1,8};
    	// Declaration & Initialization
    
  • Strings
    String my_string = new String();
    	// Declaration
    my_string = "Hello World";
    	// Initialization
    
    String my_string = "Hello World";
    	// Declaration & Initialization
    
  • Functions (Static Methods)
    public static rtrn_type methodName (args)
    {
    	statemets;
    }
    
    /* example **************************
    public static int square (int n)
    {
    	int sq=0;
    	sq = n*n;
    	return sq;
    }
    ********************************** */
    

Supercomputing ChallengeQuestions? e-mail: consult