Escolar Documentos
Profissional Documentos
Cultura Documentos
Fundamentals
These are in-built data types offered by the Java compiler. Java Integral Fractional Character Boolean
supports 8 primitive data types.
Numeric Data types: Byte float char
byte, short, int, long, float, double and char. short double
String Data type is also used in Java which
Non-Numeric Data types: holds group of characters enclosed in . It
int
boolean belongs to Reference data type because
String is a pre-defined class in Java.
2. Reference Data Type: long
+ Unary plus Represents positive int a=+25; Java supports ++ and -- operator which adds
values. or subtract 1 from its operand. i.e.
- Unary minus Represents negative int a=-25; a=a+1 equivalent to ++a or a++
values. a=a-1 equivalent to --a or a--
+ Addition Adds two values int x= a+b; ++ or -- operator may used in Pre or Post
- Subtraction Subtract second int x=a-b; form.
operands from first.
first
* Multiplication Multiplies two values int x= a*b; ++a or --a (increase/decrease before use)
/ Division Divides first operand int x=a/b; a++ or a-- (increase/decrease after use)
by second
Ex. Find value of P? (initially n=8 and p=4)
% Modulus Finds remainder after int x= a%b;
(remainder) division.
p=p* --n; 28
+ Concatenate or Adds two strings ab+cd abcd p=p* n--; 32
String addition 25+12 2512 Ex. Evaluate x=++y + 2y if y=6.
+5 5
=7+14 = 21
+5+xyz 5xyz
The process of converting one It is performed by the compiler, when different data
types are intermixed in an expression. It is also
predefined type into another is called called Coercian.
type conversion. In Implicit conversion, all operands are promoted
In mixed expression, various types of (Coercion) up to the largest data type in the
constant
t t and d variables
i bl are converted
t d expression.
expression
Example: Consider the given expression, where f is float, d is
into same type before evaluation. double and I is integer data type.
Java facilitates two types of conversion. Result= (f * d) - ( f + i) + ( f / i)
double