Java Primitive Data Type Values

Data types for java
Data Types in Java

Primitive Values

What are primitive values? They are considered the most basic data types in Java.

Java Data Types

  • Here is the list of primitive values:
    • byte – a number between -128 to 128
    • short – 16 bit with a range of -32768 to 32768
    • integer – 32 bit whole number. Range -2147483648 to 2147483647
    • long – 64 bit number with a range of
      -9223372036854775808 to 9223372036854775807
    • double – a decimal point value with a range of 64 bit
      4.94065645841246544e-324 to 1.79769313486231570e+308
    • float – is a 32 bit value 1.40239846e-45f to 3.40282347e+38f
    • boolean – has only two possible values which are true and false.
    • char – a single 16 bit Unicode character with a minimum value of ‘\u0000’ or a maximum value of ‘\uffff’ (65,535 inclusive).d

Java programming is considered to be a statically typed language. This means that all variables must be declared according to their size before they can be used.

Think of it as if someone asked you to carry 2 ounces of water around a house and on one hand you have a cup that holds 6 ounces that is empty and another that holds 24 ounces. It would seem a waste of space and weight to carry 2 ounces of water in a 24 ounces cup when you can use a 6 ounce cup just fine to carry the 2 ounces of water. Using the 24 ounce cup of water to carry 2 ounces of water is a waste of resources. This is the same concept when declaring a variable in Java; you must be mindful of the value your container will hold. We need to make sure that the container is appropriate in size to hold the value, but at the same time the container itself is not too large where we are wasting resources.

For example: int i = 0;

By doing this, you ensure that the program stores the data needed in a appropriate container. A variables data type will determine the type of container that Java will allocate for storing your data.

Examples

Here are some examples of usage of primitive types.

boolean answer = true;

char characterV = ‘c’;

byte b = 127;

short s = 30000;

int i = 210000;

double d1 = 3.23

float f1 = 124.12f;

If you are interested in practicing some data types, click here.

If you would like to contact me, please go to http://www.rickrodriguezjr.com/contactme.html