stu nicholls dot com | menu - Professional dropdown #3

click here

Data types and Operators

Datatypes of Java



Java Syntaxes

Constants:
Constants are those value do not change during the execution of the Program.
Ex: 55, 3.14,'A', "World"
Variables:
Variables are those whose value can be changed during the execution of the program.
Ex: int n; float area; char c;

The Conventions used to declare Identifiers

Identifiers are programmer designed tokens. They are used for naming classes, methods, variables, objects, labels, packages and interfaces in a program.
Java identifiers follow the following rules:-

Java developers have followed some naming conventions and they are as follows

Operators

Increment and decrement operators
     ++, --
Arithmetic
    +, -, *, /, %
Shift
    >>, <<
Comparison
    ==, !=, <, >, <=, >=
Bitwise
    &, |, ^, ~
Logical
    &&, ||, !
Assignment
    +=, -=, *=, /=,%=,&=, |=, ^=, <<=, >>=, >>>=

Bit wise operators

Shift operators

Left Shift:
op1<<op2 ; shifts bits of op1 left by distance op2.
EX: 1010<<1 Result: 10100.
Left shift operation is multiplication by two operation.
Right Shift:
op1>>op2; shifts bits of op1 right by distance op2.
EX: 1010>>1 Result: 0101.
Right shift operation is division by two operation.

Operator Precedence

When more than one operator is used in an expression, then an operator precedence rule is followed to determine the order in which the operators are executed.
The order is

Ex: 2+5*4/2-3=
3*(2+3)/5+2=
(3+2)>(2*1) && (2-2)<=(5-5)

Ternary Operator Pair

?:
Syntax:
expression1?expression2:expression3;

If expression1 is true then expression2 is evaluated else expression3 is evaluated
Ex:
(a>b)?System.out.println("a is greater"):System.out.println("b is greater");

Our aim is to provide information to the knowledge seekers. 

comments powered by Disqus
click here
Footer1