java 8
This excerpt is based upon the java language specification from the oracle site :
Important
Note that the introduction.organization chapter (1.1) in this document is a rather good quick recap to read.
introduction
First a not about the versions. I chose version 8 , while 12 is already available. The versions 1-6 are already out of long time support, so they are out by default. Also note that only some versions are marked LTS : 8 and 11. We have to pick one of those naturally.
The versions with their most prominent changes :
- java 1.0 : first release, the versions were called 1.x then
- java 1.1 : inner classes and jdbc
- java 1.2 : swing and collections framework
- java 1.3 : jpda (debugger), hotspot JVM
- java 1.4 : perl regexp, java webstart
- java 5 : generics, enum, foreach, static import
- java 6 : annotations
- java 7 : supported until July 2022. binary literals, strings in switch
- java 8 : march 2025, lambda expressions
- java 9 : no LTS
- java 10 : no LTS
- java 11 : Sep 2026, but still open for bug fixes
- java 12 : no LTS
- java 13 : latest preview version
- java 14 : future release
From this list java 8 seems the best option, since 11 still sounds experimental. This also means we adopt lambda expressions as a basic language feature !! Also it is the one installed by default and the one they ask for in most job offers.
It seems internally they still call it 1.8
grammar
In the grammar normally tokens are split up in three steps :
- a translation of unicode characters. Here normal ascii streams are also converted to a unicode stream by translation sequences like uxxxx. So you could write source code in pure unicode or you can let step 1 do it for you.
- translate the unicode stream from step 1 into a stream of input characters and line terminators.
- translate the resulting stream into tokens using whitespace and comments, but then discarding them.
The longest match is normally taken even of a shorter match would have been a valid construct like :
| tokenize | |
|---|---|
Still this is a syntax error.
The exception is for these instances :
| longest match | |
|---|---|
So in this case, we like to tokenize this as
or
> > .
unicode
Unicode characters are in the form uXXXX Exactly 4 hex (X) numbers and possibly 1 or more uuu's these multiple uu's are used to translate back unicode program texts to ascii.
You can transform any unicode program text to plain ascii by converting the unicode characters to the escape notation. The native2ascii tool for instance does this :
| unicode | |
|---|---|
If you run this println you get two smileys because uuuuu2639 is the same as u2639. Note that the smiley is turned back into the u2639 unicode escape.
But if you reverse this code you get :
| unicode | |
|---|---|
This is NOT the original, however if you use uu2639 all reverts fine. You can even make it work in multiple conversions by adding a u in one direction and removing it in the opposite.
Important
The character produced by a Unicode escape does not participate in further Unicode escapes.
For instance, u005cu005a will become u 0 0 5 a (5c is the character), but it will NOT start a new u005a (Z) unicode character !
line termination
CR, or LF or CRLF. If CR and LF are together in that order they count as one line terminator. So LFCR would be two !! line terminators. !!
identifiers
Identifier:
: IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
: JavaLetter {JavaLetterOrDigit}
JavaLetter:
: any Unicode character that is a "Java letter"
JavaLetterOrDigit:
: any Unicode character that is a "Java letter-or-digit"
$ and _ may be used to start an identifier, but $ is strongly discouraged.
So you can make horrible names like :
| could but don\'t | |
|---|---|
Important
DON'T
keywords
Don't memorize them all, just stay clear of ANY keyword of ANY language. If you walk through the list of reserved words there is not one that you are tempted to use.
Note that const and goto are also reserved, but never used in the java language. Some names like true,false and null are NOT keywords but literals, of course you still can't use them for variable names.
literals
Note that numbers may be interleaved with underscores like :
| literals | |
|---|---|
Important
you can write hex floating literals in java
If you write an exponent part in a hex float you cannot use f which is a hex digit, you p/P instead. Also the exponent indicator (p/P) is mandatory. So these examples :