root

personal (1)
cycling (4)
japan (1)
korea, south (4)
literature (1)
natural law (1)
Platonism (1)
CSS 3 (1)
social networking (1)
java (2)

3 months ago

Latest comments:
1 year ago by Michael Han
1 year ago by Michael Han
1 year ago by Socrates
1 year ago by Michael Han
1 year ago by John Doe
1 year ago by Michael Han

HTML 5 Site

8 Primitive Types of Java

, | 0 comments

There are so called EIGHT "primitive" data types in Java. They themselves could be separated into four separate categories as the following:

boolean
represents a binary value of either true or false (i.e. true)
character
represents a single Unicode UTF-16 character (i.e. '£')
integer)
represents a non-decimal value (i.e. 12/dd>
floating point
a non-integer, a real number (i.e. 3.14159)

Boolean and character data types have only one data type each, and there are 4 types of integer data types, and 2 types of floating point.

A boolean data type is expressed as boolean, and it can be either true or false. One would think the object of this type would only take a bit of the memory, but it actually takes up around 4 bytes or so for each object of this data type.

A character type is expressed as char, and it is 16-bit wide, allowing representations of 65536 characters.

An integer type can be expressed as the following:

  1. byte: 8-bit integer (signed), -128 <= n <= 127
  2. short: 16-bit integer (signed), -32,768 <= n <= 32,767
  3. int: 32-bit integer (signed), -2,147,483,648 <= n <= 2,147,483,647
  4. long: 64-bit integer (signed), -9,223,372,036,854,775,808 <= n <= 9,223,372,036,854,775,807

There are two data types for representing a real value, float and double. According to Sun (now Oracle), it is not recommended to use float or double for precise values. A "wrapper" class such as BigDecimal is recommended for precise values such as currency. A real value can be expressed as the following:

  1. float: 32-bit single precision IEEE 754 floating point
  2. double: 64-bit double precision IEEE 754 floating point

no comments

Add a new comment.
All comments are NOT moderated as of today.

(optional)
(optional)

Please enter the captcha value carefully.
You can lose your comment if you enter a wrong captcha value.
captcha image