Java Tutorial - Data Types


Basically, Java has about 8 or more Primitive data types namely:

1. byte
2. short
3. int
4. long
5. float
6. double
7. boolean
8. char

These datatypes are the type of data that can be input and stored using java programming language. Well we have others like string and reference types, but these eight are the types i will be explaining in this tutorial.

So straight to work:

  1. byte: A byte generally comprises 8-bits which means a byte contains 8-bit memory space, and it stores only  three numeric characters or what we generally know as hundreds i.e 123, or 102, 113 as long as the three numbers stored in the byte data type do not exceed 123 or go below -124. The default numeric value for any byte type is 0, to store a byte variable in java you would enter a code to look like... "byte a = 12" or "byte b = - 13", this way java can accept your byte data and save it in memory space a or b. I almost forgot to mention that it is a 2's complement storage i mean (2^7)
  2. short: Unlike byte, the short data type saves in ten thousands, i.e 32,767 at most and -32,767 at least. This tells us that the short data type is 16 bit and a 2's complement memory, (2^15). From the example of creating a byte memory space and saving a value in it we can also create a short memory space the same way, short x = 23330, or short y = 30675. maximum value of 32767 and minimum value of -32,768.
  3. int: The integer data type is a 32 bit and also 2's complement memory data type, at 2^31, the integer data type is capable of storing up to 11 numbers i.e 2147438648 at maximum and -2147438649 at minimum. To create an integer space we use int (the name of your space) = (your number);. NOTE: NEVER FORGET TO ADD COLON AT THE END OF EVERY LINE. 
  4. long: The long data type is 64 bit and 2's complement based that hols about 19 numeric characters, with a minimum of  -9,223,372,036,854,775,808 and a maximum of  9,223,372,036,854,775,807 the long data type is declares by long (the name of the space) = (your value); this is used when a wider range of int is required.
  5. float: 

Comments