// lecture14.java: transition to Java // Language Elements: // ----------------- // Commentary: // what am I? a comment /* I am also a comment */ /* multiline comments are ok too */ // White space: // use as much as you want, but avoid breaking language elements // Keywords: // ex) $do$, $for$, $if$, $class$, etc (see ChapmanJ p16) // note: $goto$ is reserved, but not used! // Primitive data types/constants/literals: // - data that does not change // - integers, real numbers, booleans, characters // - boolean: $true$, $false$ (not 0 and 1!) // Operators: // - arithmetic, modulus (%), assignment (=), relation (&&, ||, !, ==, <,>, !=) // - neat things like increment ++, +=, *= // - related issues like promotion and casting // Names/variables: // - all vars must have TYPE! // syntax) type var // - TYPE means the classification of the data the variable may store // - holds values // syntax) var = expr // - vars generally have letters,numbers,underscore ($, too, but I won't use) // Punctuation: // end statements with ; // () for expressions and functions // {} for blocks of statements // [] used for arrays // '' chars // "" strings // \c escape characters // . access field //------------------------------------------------------------------------// // Control Flow // $if$: // if (cond) // if the condition evaluates to true, do the following statements // { statements } // else if (cond) // { statements } // // else // { statements } // // - $else if$s are optional // - may use just one $if$ // - if only 1 statement, not need {} // $while$ // while(cond) { // while the cond is true, do the following statements // statements // } // $do$-$while$ // do { // statements // while(cond) // do statements while cond is true // $for$ // for(init;cond;incr) // ex) // for(i=1;i<=4;i++) { // statements // } // see also $switch$ //------------------------------------------------------------------------// // Functions // Functions (called METHODS) // using: // ex) System.out.println("Hello, world!"); // creating your own: // modifiers returntype name(input args) { // statements // } // Program files: // - use ASCII (for chars in strings, UNICODE) // - store code in classes // - usually 1 class per file, but may do more // // example) // The magic lines: public class Lecture14 { public static void main(String[] args) { // The world's most basic Java program } }