In: Computer Science
TYPE |
SIZE (IN BYTES) |
DEFAULT |
RANGE |
boolean |
1 bit |
true, false |
|
Char |
2 |
‘\0000’ to ‘\ffff’ |
|
Byte |
0 |
||
Short |
0 |
-215 to +215-1 |
|
Int |
4 |
||
Long |
0L |
- |
|
Float |
4 |
00.0f |
|
Double |
8 |
-1.8E+308 to +1.8E+308 |
All the basics data types are available in JAVA are primitive types like int, boolean, char, short, etc.
and Reference types are used to point the object like String, File, Thread, etc.
main difference is that primitive types will always has a value while reference type is "NULL" , if int variabe is unintialized then it will have 0 value but if String variable is uninitialized then it will be "null".
-----------------------------------------------------------------
global variable are declared outside any function can be accessed into any function but local variables are declared within any function canbe accessed only in that function.
-----------------------------------------------------------------
initializing variables are useful for preventing bugs specifically for reference type initialization can be useful for preventing null reference errors.
-----------------------------------------------------------------
static variables are variables declared with static keyword outside of any method within class
instance variables are specific to instance of any class they are declared in class but outside of method and also called member variable
while local variable are only declared within any method and can be accessed by that method.
-----------------------------------------------------------------
in simple term widening mean conversion of value to data type that can handle any possible value of original data type , and also widening conversions preserve the source value but can change its representation like short to int.
narrowing mean conversion to data type that might not be able to handle the value of current data type like from float to int, or int to short.
--------------------------------------------------------------------
TYPE |
SIZE (IN BYTES) |
DEFAULT |
RANGE |
boolean |
1 bit |
false |
true, false |
Char |
2 bytes |
\0000 |
‘\0000’ to ‘\ffff’ |
Byte |
1bytes |
0 |
-128 to 127 |
Short |
2bytes |
0 |
-215 to +215-1 |
Int |
4bytes |
0 |
-2147483648 to 2147483647 |
Long |
8bytes |
0L |
-9223372036854775808 to 9223372036854775807 |
Float |
4bytes |
00.0f |
±1.4E-45 to ±3.4028235E+38 |
Double |
8bytes |
0.0 |
-1.8E+308 to +1.8E+308 |
------------------------------------------------------------------------
package is mechanism to grouping the classes, subpackages, and interfaces.
importance are: they are useful in preventing naming conflict, packages are useful for providing controlled access to classes and interfaces, packages are useful in data-hiding because they are actualy encapsulation of related classes and interfaces .