Wednesday 12 October 2011

Java Tokens and Data Types



         Smallest individual units in a program are known as Token. Java Language includes different types of tokens. They are listed below.

  1. Reserve Keyword
  2. Identifiers
  3. Literals
  4. Operators
  5. Separators
  6. White space
  7. Comment

1. Reserve Keyword
Keywords are an essential part of a language definition. They implement specific features of the language .Java has reserved 60 words as keywords.
These keywords combined with operators and separators according to a syntax from definition of the Java language.
Keywords can not use as a names of variables, classes, method  and so on.
All keywords are to be written in lower case letters. Java is case sensitive.

list of keyword

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



2. Identifiers

Identifiers are used for naming classes, method, variable, objects, Packages and inheritances in a program. It is the program defines tokens.

 Rules
1. They can have alphabets, digits, and the underscore and dollars sign characters
2. They must not begin with a digit
3. Uppercase and Lowercase letters are distinct
4. They can be of any Length.

3. Literals      

Literals in a Java are a sequence of characters that represent constant values to be stored in variables.    

Types of Literals

            1.Integer Literals                    100   
            2.Floating point Literals          100.50
            3.Character Literals                ‘A’
           
Java supports a set of character literals known as escape sequence which can not be printed.


Escape Sequence             Description
\ddd                                   Octal character (ddd)
\uxxxx                                Hexadecimal UNICODE character (xxxx)
\’                                        Single quote
\”                                       Double quote
\\                                        Backslash
\r                                        Carriage return
\n                                       New line (also known as line feed)
\f                                        Form feed
\t                                        Tab
\b                                       Backspace


            4.String Literals            “Computer”
            5.Boolean Literals          True/False

4. Operators

An operators is a symbol that takes one or more arguments and operators on them to produce a result

Types of Operators

1.Arithmetic Operators
            ( +, -, *, /, %)
           
2.Relational Operators
            (< ,> ,>==,<==,==,!==)

3.Logical Operators
            (&&,||,!)

4.Assignment Operators
            (+=,-=,*=,!=,%=)

5 Increment and Decrement Operators
            (++,--)Prefix/Postfix

6 Conditional Operators
            (?,:)

7 Bitwise Operators
            (&,!,^,<<,>>,>>>)
            >>>:-Shift right with Zero Fill

8 Special Operators
(Instanceof)
             
     Instanceof :
          It is an Object reference Operators and returns true if the object on the left-hand side is an instance of the class given on right-hand side

            Ex. data instanceof Information.

          Is true if the object data belongs to the class Information ; otherwise it is false

Operators Precedence and their associativity

Operator    Description                              Associtivity       Rank
.                  Member Selection                     Left to Right          1       
( )               Function Call                  
[ ]               Array element refrance
-                  Unary Minus                             Right to Left          2
++              Increment
--                Decrement
~                 Once complement
!                  Logical Negative
(type)        Casting

*                 Multiplication                            Left-To-Right          3
/                 Division                                   
%               Modulus
           
+                 Addition                                   Left-To-Right          4
-                  Substraction

<<              Left Shift                                  Left-To-Right          5
>>              Right Shift
>>>           Right Shift with Zero Fill

<                 Less Than                                Left-To-Right          6
<=              Less than or equal to
>                 Greater Than
>=              Greater Than or qual to
Instance Type Comparison

==              Equality                                    Left-To-Right          7
&                 Bitwise                                     Left-To-Right          8
^                 Bitwise XOR                             Left-To-Right           9
|                  Bitwise  OR                              Left-To-Right          10
&&              Logical AND                              Left-To-Right          11     
||                Logical Or                                 Left-To-Right          12
?:                Conditional Operator                 Left-To-Right          13
=                 Assignment Operators              Left-To-Right          14
OP=            Shorthand assignment
                    
Example :
                           If(x==10+15  &&  y>b)
                           If(x==25  && y<b)
                            X==25   is False
                            Y<10  is True
                             If(False && True)

5. Separators

Seperators are symbols used to indicate where groups of code are divided and arranged.        
            Separators   ( ( ),{ },[ ], ; , , .)

6. WhiteSpace

            Whitespace is a space,tab or Newline.

7. Comments

            Three types of comments
            (1) Single line Comments  (//)
            (2) Multi line Comments    (/* ------ */)
            (3) Documentation Comments.(Used to Produce an
                             HTML file.Begins with /** and end with */



Primitive Data type and its initial Values

Every variable in Java has a data types.Data type in Java Under various categories.They are as below

1.     Premitive (Intrinsic)
  • Numeric
1.     Integer
2.     Floating Point
  • Non-Numeric
1.     Character
2.     Boolean



2. Non-Primitive (Derived)
  • Classes
  • Arrays
  • Interface   

Primitive Data Type

Numeric

(1)Integer

Integer type can hold whole numbers. The memory size and range of all the four integer data types is as below.

Type    Size                   Minimum             Maximum

byte     1 Bytes              -128                        127
short    2 Bytes              -32,768                   32,767
int        4 Bytes              -2,147,483,648       2,147,483,647
long     8 Bytes              -9,223,372,036       9,223,372
                                      854,775,808          036,854,775,807
(2) Floating Point

Floating Point types hold numbers containing factorial part such as 27.59 and -1.375
There are two types of floating point:

            Float(Single-Precision)
            Double(Double Precision)

Type      Size                   Minimum              Maximum

Float      4 Bytes               3.4e-038               3.4e+.038
Double   8 Bytes               1.7e-308               1.7e+308

The floating point numbers are treated as double precision quantities. To force them to be in single precision mode ,need to append f or F to the numbers.

Ex, 1224.56F

Non-Numeric

(1) Character

To Store Character value. Character data types is used. It called char. Its size is 2 Bytes. It can hold only a single Character.
         
(2) Boolean

Boolean type is used when want to test a particular condition during the execution of the program. It has two Values True or False Boolean type is denoted by the keyword boolean and uses only one bit of storage.

Posted by : Ruchita Pandya

1 comment:

  1. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
    Data Science training in rajaji nagar
    Data Science with Python training in chennai
    Data Science training in electronic city
    Data Science training in USA
    Data science training in bangalore

    ReplyDelete