Tuesday, August 19, 2014

Lexical Structure of Java.

Lexical structure :

Unicode :
Programs are written using the Unicode character set.

Comments :

In java single line comment is //
In java multiline command is /*   */

Identifier:
An identifier is an unlimited-length sequence of Java letters and Java digits, the
first of which must be a Java letter

Key words :
  50 character sequences, formed from ASCII letters, are reserved for use as
keywords and cannot be used as identifiers.

abstract
assert
boolean
break
byte
continue
case
catch
char
class
const
default
do
double
else
enum
extends
final
finally
float
for
goto
if
import
implements
instanceof
int
interface
long
native
package
private
protected
public
return
synchronized
switch
short
static
strictfp
super
this
throw
throws
transient
try
void
volatile
while

Literals:
Literal is source code representation of primitive value.

  Integer Literal:
    Integer literal may be expressed in decimal, hexadecimal, binary, octal.
An integer literal is of type long if it is suffixed with an ASCII letter L or l, Otherwise it is type of int.

In a hexadecimal or binary literal, the integer is only denoted by the digits after
the 0x or 0b.

Examples of int literals:
0
2
0372
0xDada_Cafe
1996
0x00_FF__00_FF

Examples of long literals:
0l
0777L
0x100000000L
2_147_483_648L
0xC0B0L

  Floating point literals:
The largest positive finite literal of type float is 3.4028235e38f.
The smallest positive finite non-zero literal of type float is 1.40e-45f.
The largest positive finite literal of type double is 1.7976931348623157e308.
The smallest positive finite non-zero literal of type double is 4.9e-324.

Examples of float literals:
1e1f
2.f
.3f
0f
3.14f
6.022137e+23f

Examples of double literals:
1e1
2.
.3
0.0
3.14
1e-9d 1e137

Boolean literals:
true or false

Character literals can only represent UTF-16 code units, they are limited
to values from \u0000 to \uffff.

'a'
'%'
'\t'
'\\'
'\''
'\u03a9'
'\uFFFF'
'\177'
'™'

String literals;

class Test {
 public static void main(String[] args) {
 String hello = "Hello", lo = "lo";
 System.out.print((hello == "Hello") + " ");
 System.out.print((Other.hello == hello) + " ");
// System.out.print((Other.Other.hello == hello) + " ");
 System.out.print((hello == ("Hel"+"lo")) + " ");
 System.out.print((hello == ("Hel"+lo)) + " ");
 System.out.println(hello == ("Hel"+lo).intern());
 }
}
class Other { static String hello = "Hello"; }

output:
true true true false true

Null literal.
null.

Separators:
Twelve tokens, formed from ASCII characters, are the separators.

(
)
{
}
[
]
;
,
.
...
@
::

Operators:
38 tokens, formed from ASCII characters, are the operators.
=
>
<
!
~
?
:
->
==
>=
<=
!=
&&
||
++
--
+
-
*
/
&
|
^
%
<<
>>
>>>
+=
-=
*=
/=
&=
|=
^=
%=
<<=
>>=
>>>=



No comments:

Post a Comment