home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
syntax-week1
Java Syntax (v1)
Our Mantras
-
To call a function:
object-dot-functionName-openParen-arguments.
-
A function's signature:
returnType-functionName-openParen-paramterTypeAndNames
Java Syntax
Here's a list the Java syntax covered so far, as of week1:
(You are encouraged to look at this while looking at some
actual code.)
-
class-declaration ::=
class nameClass {
method-declaration…
}
-
type ::= int | double
-
method-declaration ::=
typereturn name ( parameter-declaration ) {
return expression;
}
-
parameter-declaration ::= type nameparam
-
expression ::=
literal-value | method-call | ( expression ) |
expression+expression | expression-expression | expression*expression | expression/expression
-
method-call ::= expressionobject . namemethod ( argument-list )
-
argument-list ::= empty-argument-list | non-empty-argument-list
-
empty-argument-list ::=
-
non-empty-argument-list ::= expression [, non-empty-argument-list]
How to read Backus-Naur Form (BNF):
- colored text is replaced with
a particular instance of that type.
(Subscripts are informative only, and don't technically mean anything.)
- uncolored text is typed in literally
(not replaced with something else).
- “::=” means “consists of”.
- “|” means “or”
- “[bracket-optional-part]”
can be included, or be omitted.
- “...” means zero or more
repetitions of the preceding item.
See also:
Lies
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs