CSC/ECE 517 Fall 2012/ch1 1w21 aa: Difference between revisions
Line 14: | Line 14: | ||
! Range | ! Range | ||
! Usage | ! Usage | ||
! Default Value | |||
|- | |- | ||
| byte | | byte | ||
Line 20: | Line 21: | ||
| -128 to 127 | | -128 to 127 | ||
| This datatype can be used in arrays where there is a space constraint to save memory. | | This datatype can be used in arrays where there is a space constraint to save memory. | ||
| 0 | |||
|- | |- | ||
| short | | short | ||
Line 26: | Line 28: | ||
| -32,768 to 32,767 | | -32,768 to 32,767 | ||
| This datatype can also be used to save memory in large arrrays. | | This datatype can also be used to save memory in large arrrays. | ||
| 0 | |||
|- | |- | ||
| int | | int | ||
Line 32: | Line 35: | ||
| -2,147,483,648 to 2,147,483,647 | | -2,147,483,648 to 2,147,483,647 | ||
| This datatype is generally the default datatype for all the numbers we use in our program. | | This datatype is generally the default datatype for all the numbers we use in our program. | ||
| 0 | |||
|- | |- | ||
| long | | long | ||
Line 38: | Line 42: | ||
| -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807 | | -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807 | ||
| This type is used when we require a value that is outside the range of values provided by int. | | This type is used when we require a value that is outside the range of values provided by int. | ||
| 0L | |||
|- | |- | ||
|float | |float | ||
Line 44: | Line 49: | ||
| 32-bit IEEE 754 floating-point numbers.See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3] | | 32-bit IEEE 754 floating-point numbers.See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3] | ||
| Use this datatype to save memory in large arrays. | | Use this datatype to save memory in large arrays. | ||
| 0.0f | |||
|- | |- | ||
| double | | double | ||
Line 50: | Line 56: | ||
| 64-bit IEEE 754 floating-point numbers. See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3] | | 64-bit IEEE 754 floating-point numbers. See [http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.3] | ||
| This data type is generally the default for decimal values. | | This data type is generally the default for decimal values. | ||
| 0.0d | |||
|- | |- | ||
| boolean | | boolean | ||
Line 56: | Line 63: | ||
| false, true | | false, true | ||
| Use this data type for flags that track a true or false condition. | | Use this data type for flags that track a true or false condition. | ||
| false | |||
|- | |- | ||
| char | | char | ||
Line 62: | Line 70: | ||
| Unicode character \u0000(0) through unicode character \uffff(65,535) | | Unicode character \u0000(0) through unicode character \uffff(65,535) | ||
| This type is used to define single characters. | | This type is used to define single characters. | ||
| '\u0000' | |||
|} | |} | ||
Besides these 8 primitive data types java provides support to characterstrings through Java.lang.String class. String is not a primitive datatype but its usage and functionality makes us think of it being so. | |||
== Primitive data types in C# == | == Primitive data types in C# == |
Revision as of 20:50, 9 September 2012
Primitive Objects
Introduction
A primitive data type is a basic or in-built type that a programming language provides for its users. These data types can be used for building other complex and composite data types [1]. In most languages, primitive types usually consist of basic value types for representing the data to be stored. As these data types are built-in, the compilers for these languages usually provide inbuilt support for these data types and so would support most basic operations. In dynamically typed languages like Ruby, these are represented as objects and are referred to as primitive objects. This article discusses the various primitive data types/objects that are present in various objected oriented programming languages and their benefits.
Primitive data types in C++
Primitive data types in Java
There is a certain group of data types that is used very frequently by the programmer. These types are included in the Java language as the primitive data types.These data types have a fixed size which does not change from one system to another and adds to the portability feature of java. There are 8 primitive data types defined in java which are as follows:[2]
Name | Description | Size(in bits) | Range | Usage | Default Value |
---|---|---|---|---|---|
byte | Signed two's complement integer | 8 bits | -128 to 127 | This datatype can be used in arrays where there is a space constraint to save memory. | 0 |
short | Signed two's complement integer | 16 bits | -32,768 to 32,767 | This datatype can also be used to save memory in large arrrays. | 0 |
int | signed two's complement integer | 32 bits | -2,147,483,648 to 2,147,483,647 | This datatype is generally the default datatype for all the numbers we use in our program. | 0 |
long | signed two's complement integer | 64 bits | -9,223,372,036,854,775,808 to 9,223,373,036,854,775,807 | This type is used when we require a value that is outside the range of values provided by int. | 0L |
float | Single-precision IEEE 754 floating point | 32 bits | 32-bit IEEE 754 floating-point numbers.See [3] | Use this datatype to save memory in large arrays. | 0.0f |
double | Double-precision 64-bit IEEE 754 floating point | 64 bits | 64-bit IEEE 754 floating-point numbers. See [4] | This data type is generally the default for decimal values. | 0.0d |
boolean | Boolean | 1- bit | false, true | Use this data type for flags that track a true or false condition. | false |
char | a char is a single 16-bit character encoded using Unicode | 16 bit | Unicode character \u0000(0) through unicode character \uffff(65,535) | This type is used to define single characters. | '\u0000' |
Besides these 8 primitive data types java provides support to characterstrings through Java.lang.String class. String is not a primitive datatype but its usage and functionality makes us think of it being so.