Char data type:
In java we are allowed to use any worldwide alphabets character and java is Unicode based to represent all these characters one byte is not enough compulsory we should go for 2 bytes.
Size: 2 bytes
Range: 0 to 65535
Example:
char ch1=97;
char ch2=65536;//C.E:possible loss of precision
CORE JAVA Basics
Information about Basics Core JAVA
10/09/2015
boolean data type:
Size: Not applicable (virtual machine dependent)
Range: Not applicable but allowed values are true or false.
Which of the following boolean declarations are valid?
Example 1:
boolean b=true;
boolean b=True;//C.E:cannot find symbol
boolean b="True";//C.E:incompatible types
boolean b=0;//C.E:incompatible types
Example 2:
10/09/2015
Floating Point Data types:
Long:
Whenever int is not enough to hold big values then we should go for long data type.
Example:
To hold the no. Of characters present in a big file int may not enough hence the return type of length() method is long.
long l=f.length();//f is a file
Size: 8 bytes
Range:-2^63 to 2^63-1
***
Note: All the above data types (byte, short, int and long) can be used to represent whole numbers. If we want to represent real numbers then we should go for floating point data types.
Int:
This is most commonly used data type in java.
Size: 4 bytes
Range: -2147483648 to 2147483647 (-2^31 to 2^31-1)
Example:
int i=130;
int i=10.5;//C.E:possible loss of precision
int i=true;//C.E:incompatible types
Short:
The most rarely used data type in java is short.
Size: 2 bytes
Range: -32768 to 32767(-2^15 to 2^15-1)
Example:
short s=130;
short s=32768;//C.E:possible loss of precision
short s=true;//C.E:incompatible types
Short data type is best suitable for 16 bit processors like 8086 but these processors are completely outdated and hence the corresponding short data type is also out data type.
Example:
byte b=10;
byte b2=130;//C.E:possible loss of precision
byte b=10.5;//C.E:possible loss of precision
byte b=true;//C.E:incompatible types
byte b="durga";//C.E:incompatible types
byte data type is best suitable if we are handling data in terms of streams either from the file or from the network.
The most significant bit acts as sign bit. “0” means “+ve” number and “1” means “–ve” number.
“+ve” numbers will be represented directly in the memory whereas “–ve” numbers will be represented in 2’s complement form.
10/09/2015
Byte:
Size: 1byte (8bits)
Maxvalue: +127
Minvalue:-128
Range:-128to 127[-27 to 27-1]
NOTE :
Except Boolean and char all remaining data types are considered as signed data types because we can represent both “+ve” and”-ve” numbers.
10/09/2015
Diagram
Click here to claim your Sponsored Listing.
Location
Category
Contact the school
Telephone
Website
Address
BTM 1st Stage
Bangalore
560029
Opening Hours
| Monday | 7am - 9am |
| Tuesday | 7am - 9am |
| Wednesday | 7am - 9am |
| Thursday | 7am - 9am |
| Friday | 7am - 9am |
| Saturday | 7am - 9am |
| Sunday | 7am - 9am |