In Java Language Use Data types
In java mainly two categories
of data types
o Primitive:
o Non Primitive
data types in java
o Primitive data types are
those data types which are not reference object in memory.
o There are eight type of
primitive data types in Java.
data types in java
data types in java
Data Types Default Value Default Size
byte 0 1 byte
short 0 2 byte
int 0 4 bytes
long 0 L 8 bytes
float 0.0 f 4 bytes
double 0.0 d 8 bytes
Boolean false 1 bit
char '\u 0000' 2 bytesbyte 0 1 byte
short 0 2 byte
int 0 4 bytes
long 0 L 8 bytes
float 0.0 f 4 bytes
double 0.0 d 8 bytes
Non Primitive
Those datatypes which
having reference variable object in a memory are knows as non-primitive
datatypes
o Arrays
o Strings
o User define classes etc.
data types in java
Variables Use Java Data
Storing the data in memory, for example : putting balls in basket.
In java there are three
types of variables
o Local variables: the variable which is declared inside the method body This variable cannot be access from outside of the method.data types in java
o Instance variables: the variable which is declared inside the class but outside the
method Is known as instance variable
o Static variables: if instance variable declared as static then it is known as
static variables, we will learn more about static variable in static
section .data types in java
o
Example
public class VariableDemo {
//instance variable
int a = 10;
// static variable
static int b = 20;
public static void main(String[]arg){
//local variable
int c - 30;
}
}
public class VariableDemo {
//instance variable
int a = 10;
// static variable
static int b = 20;
public static void main(String[]arg){
//local variable
int c - 30;
}
}
10 Operators Java Data
In java basically three
types of categories of operators
o Increment / decrements Operators
o Arithmetic Operators:
o Conditional Operators :
data types in java
Increment / decrements Operators::
o Increment and decrements operator: example int a;
Operator Name Description
a++ Post-increment First print the value then increment by one
++a Pre-increment First increment the value by one the print
a-- Post-decrements First print the value then decrements by one
--a Pre-decrements First decrements the value by one the print
a++ Post-increment First print the value then increment by one
++a Pre-increment First increment the value by one the print
a-- Post-decrements First print the value then decrements by one
--a Pre-decrements First decrements the value by one the print
Arithmetic Operators java data
o Arithmetic operator: example inta and int b
Operator Description Result
+ Add two variables a+b
- Subtract two variables a-b
* Multiply two variables a*b
/ Divide two variables a/b
% Remainder Of two variable a%b
data types in java
+ Add two variables a+b
- Subtract two variables a-b
* Multiply two variables a*b
/ Divide two variables a/b
% Remainder Of two variable a%b
data types in java
o Assignment Operator: example int x and int y
Operator Description Result
+= It will add two variable then result will assign to left +=y or x= x+y
variable
- = It will subtract two variable then result will assign to left x - = y or x = x - y
variable
*= It will multiply two variable then result will assign to left x *= y or x = x * y
variable
/= It will divide two variable then result will assign to left x /= y or x = x / y
variable
%= It will remainder two variable then result will assign to left x %= y or x = x %y
variable
data types in java
o Conditional Operators example int x and int y
Operator Name Example Result
== Equal to x == y Return true if both are equal
!= Not Equal to x != y Return true if both are not equal
< Less than x < y Return true if x has value less than y
<= Less than or equal to x <= y Return true if x has value less or equal to y
> Greater than x > y Return true if x has value greater than y
>= Greater than or equal to x >= y Return true if x has value greater or equal to y
data types in java
o Bit wise Operator: example int x = 31 (In binary: 0001 1111) and y = 13 (In binary: 0000 1101). These operators first convert the value into binary then perform the respected operation.Java Data
Operator Name Description
&& And Return True if both variable are true
|| OR Return True if any one variable is true
! Not Return True if variable is false
data types in java
Operator Name Description
& And (001 1111 & 0000 1101) = 0000 1101 = 13.
And bi twise operator chooses those 1’s bit which are common both side
| Or (0001 1111 | 0000 1101) = 0001 1111 = 31.
Or bit wise operator chooses only 1’s bit common and non-common from both side.
^ Xor (0001 1111 ^ 0000 1101) = 0001 0010 = 18.
Xor bit wise operator choose only 1’s bit but not common from both side.
<< Left shift (0001 1111 << 2) = 0111 1100 = 124.
Left shift operator moves the operand toward left side up to given position
>> Right Shift (0001 1111 << 2) = 0000 0111 = 7.
Right Shift operator moves the operand toward right side up to given limit . Java Data
& And (001 1111 & 0000 1101) = 0000 1101 = 13.
And bi twise operator chooses those 1’s bit which are common both side
| Or (0001 1111 | 0000 1101) = 0001 1111 = 31.
Or bit wise operator chooses only 1’s bit common and non-common from both side.
^ Xor (0001 1111 ^ 0000 1101) = 0001 0010 = 18.
Xor bit wise operator choose only 1’s bit but not common from both side.
<< Left shift (0001 1111 << 2) = 0111 1100 = 124.
Left shift operator moves the operand toward left side up to given position
>> Right Shift (0001 1111 << 2) = 0000 0111 = 7.
Right Shift operator moves the operand toward right side up to given limit . Java Data
o
Instance
of Operator: instance of operator is
only used for object reference variable, it checks the reference of object
variable is valid or not, if reference is valid it returns true otherwise it
returns false.
Ternary
o Conditional operator: it is work like if condition.
o Syntax:variable x = (expression)? value if true: value if
false
data types in java
No comments:
Post a Comment