DataTypes
DATA TYPES
Data types are the type of data that we use in our program. There are 2 types of data types:-
1. Primitive
2. Non primitive or reference
PRIMITIVE DATA TYPES
Primitive data types are those data types which are predefined by the language and named by a reserved keyword. There are 8 primitive data types in Java each having a fixed size:-
For example- int a=5;
float b=5.6;
double c=8.998;
char d='a';
boolean e= true;
byte f=100;
short g=1000;
long h= 2000 l;
A difference between the "int" data type in Java and that in C is the size of "int" in Java is 4 bytes for both 32 bit and 64 bit operating systems. In C the size is 2 bytes for 32 bit and 4 bytes for 64 bit operating systems.
REFERENCE DATA TYPES
There are some data types whose size are not fixed. These data types store the memory address of an object (generally the memory address of a class or an array). These are called reference data types. For example class, array, interfaces. Basically these data types are initialized using the new operator.
Let us a say that there is a process started. It needs an active memory (means Random Access Memory) to store its data, code and stack. The JVM (Java Virtual Machine) reserves memory space for it based on what it can determine before run-time (based on variables defined in the source code) and during the application execution.
So the process needs two memory zones :-
1. Stack - Its size is fixed. Its size is determined based on information available before execution of function. This information is given out by function, local and input variables.
2. Heap - It is dynamic thus its size is not fixed. It represents the memory requirements that may be needed or not at the runtime. We do not know for sure if we need it and what would be its size. In order to reserve this space we use the new operator.
Comments
Post a Comment