Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Java syntax
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Primitive types== Primitive types in Java include integer types, floating-point numbers, [[UTF-16]] code units and a Boolean type. There are no unsigned types in Java except <code>char</code> type, which is used to represent UTF-16 code units. The lack of unsigned types is offset by introducing unsigned right shift operation (<code>>>></code>), which is not present in C++. Nevertheless, criticisms have been leveled about the lack of compatibility with C and C++ this causes.<ref>{{cite web|url=http://darksleep.com/player/JavaAndUnsignedTypes.html|first=Sean|last=Owens|title=Java and unsigned int, unsigned short, unsigned byte, unsigned long, etc. (Or rather, the lack thereof)|access-date=April 21, 2010|archive-date=February 20, 2009|archive-url=https://web.archive.org/web/20090220171410/http://darksleep.com/player/JavaAndUnsignedTypes.html|url-status=live}}</ref> <!-- This is a terrible citation. If you have a better one, use it. --> {| class="wikitable" |- !colspan="6"|Primitive Types |- ! Type Name ! [[Primitive wrapper class in Java|Wrapper class]] ! Value ! Range ! Size ! Default Value |- | <code>byte</code> | <code>java.lang.Byte</code> | integer | β128 through +127 | 8-bit (1-byte) | <code>0</code> |- | <code>short</code> | <code>java.lang.Short</code> | integer | β32,768 through +32,767 | 16-bit (2-byte) | <code>0</code> |- | <code>int</code> | <code>java.lang.Integer</code> | integer | β2,147,483,648 through +2,147,483,647 | 32-bit (4-byte) | <code>0</code> |- | <code>long</code> | <code>java.lang.Long</code> | integer | β9,223,372,036,854,775,808 through<br/> +9,223,372,036,854,775,807 | 64-bit (8-byte) | <code>0</code> |- | <code>float</code> | <code>java.lang.Float</code> | floating point number | Β±1.401298Eβ45 through Β±3.402823E+38 | 32-bit (4-byte) | <code>0.0f</code><ref>{{cite web|url=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html|title=Primitive Data Types}}</ref> |- | <code>double</code> | <code>java.lang.Double</code> | floating point number | Β±4.94065645841246Eβ324 through<br/> Β±1.79769313486232E+308 | 64-bit (8-byte) | <code>0.0</code> |- | <code>boolean</code> | <code>java.lang.Boolean</code> | Boolean | <code>true</code> or <code>false</code> | 1-bit (1-bit) | <code>false</code> |- | <code>char</code> | <code>java.lang.Character</code> | [[UTF-16]] code unit ([[Mapping of Unicode character planes#Basic Multilingual Plane|BMP]] character<br/>or a part of a surrogate pair) | <code>'\u0000'</code> through <code>'\uFFFF'</code> | 16-bit (2-byte) | <code>'\u0000'</code> |} <code>char</code> does not necessarily correspond to a single character. It may represent a part of a [[UTF-16#Encoding of characters outside the BMP|surrogate pair]], in which case Unicode code point is represented by a sequence of two <code>char</code> values. ===Boxing and unboxing=== This language feature was introduced in [[J2SE 5.0]]. ''Boxing'' is the operation of converting a value of a primitive type into a value of a corresponding reference type, which serves as a wrapper for this particular primitive type. ''Unboxing'' is the reverse operation of converting a value of a reference type (previously boxed) into a value of a corresponding primitive type. Neither operation requires an explicit conversion. Example: <syntaxhighlight lang="java"> int foo = 42; // Primitive type Integer bar = foo; /* foo is boxed to bar, bar is of Integer type, which serves as a wrapper for int */ int foo2 = bar; // Unboxed back to primitive type </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)