java--two major data types __java

Source: Internet
Author: User
Tags wrapper
Two major data types for Java:
Built-in data types
Reference data type


Built-in data types
The Java language provides eight basic types. Six numeric types (four integers, two floating-point types), one character type, and one Boolean type.


Byte
The byte data type is a 8-bit, signed integer that is represented by a binary complement;
The minimum value is-128 ( -2^7);
The maximum value is 127 (2^7-1);
The default value is 0;
Byte types are used to conserve space in large arrays, primarily in place of integers, because byte variables occupy only One-fourth of the type of int;
Example: Byte a = 100,byte B =-50.


Short
The short data type is a 16-bit, signed integer represented by a binary complement
The minimum value is-32768 ( -2^15);
The maximum value is 32767 (2^15-1);
Short data types can also save space as Byte. A short variable is one-second of the space occupied by the int type variable;
The default value is 0;
Example: Short s = 1000,short r =-20000.


Int:
The int data type is a 32-bit, signed integer expressed in binary complement;
The minimum value is-2,147,483,648 ( -2^31);
The maximum value is 2,147,485,647 (2^31-1);
Generally, integer variable defaults to int type;
The default value is 0;
Example: int a = 100000, int b =-200000.


Long
A Long data type is a 64-bit, signed integer represented in binary complement;
The minimum value is-9,223,372,036,854,775,808 ( -2^63);
The maximum value is 9,223,372,036,854,775,807 (2^63-1);
This type is mainly used on systems that require larger integers;
The default value is 0L;
Example: Long a = 100000l,long B = -200000l.


Float
Float data type is a single precision, 32-bit, IEEE 754-compliant floating-point number;
Float saves memory space when storing large floating-point number groups;
The default value is 0.0f;
Floating point numbers cannot be used to represent exact values, such as currency;
Example: float f1 = 234.5f.


Double
The double data type is a double-precision, 64-bit, IEEE 754-compliant floating-point number;
The default type for floating-point numbers is type double;
The double type cannot also represent an exact value, such as a currency;
The default value is 0.0d;
Example: Double D1 = 123.4.


Boolean
A Boolean data type represents one bit of information;
Only two values: true and false;
This type is used only as a sign to record the true/false situation;
The default value is false;
Example: Boolean one = True.


Char
The char type is a single 16-bit Unicode character;
The minimum value is ' \u0000 ' (that is, 0);
The maximum value is ' \uffff ' (that is, 65,535);
Char data type can store any character;
Example: char letter = ' A '.


Attention:
We do not have to force memory for the range of values of the basic types of numeric types, since their values are already defined in the corresponding wrapper class as constants.
Both the minimum and maximum values of float and double are output in the form of scientific notation, and the ending "e+ number" indicates how many times the number before E is multiplied by 10. For example, 3.14E3 is 3.14x1000=3140,3.14e-3 is 3.14/1000=0.00314.
In fact, there is another basic type Void in Java, which also has the corresponding wrapper class java.lang.Void, but we can't manipulate them directly.




Reference type
Reference type variables are created by the constructors of the class, and you can use them to access the referenced objects. These variables are specified as a specific type when declared, such as employee, Pubby, and so on. Once a variable is declared, the type cannot be changed.
objects, arrays are reference data types.
The default values for all reference types are null.
A reference variable can be used to reference any type that is compatible with it.
Example: Animal Animal = new Animal ("Giraffe").


Java Constants
A constant is a fixed value. They do not need to be computed, directly representing the corresponding values.
Constants are quantities that cannot be changed. In Java, the final flag is declared in the same way as a variable:
Final double PI = 3.1415927;
Although constant names can also be lowercase, in order to be easy to identify, you typically use uppercase letters to represent constants.
Literal quantities can be assigned to any built-in type of variable. For example: Byte a =68;char a = ' a '
byte, int, long, and short can be represented in decimal, 16, and 8.
When using constants, the prefix 0x represents 16-in.
As in other languages, the string constants of Java are also sequences of characters that are enclosed in two of quotes.
Both string constants and character constants can contain any Unicode character. For example: char a = ' \u0001 '; String a = "\u0001";


The Java language supports some special escape character sequences.
Symbolic character meaning
\ n line Wrap (0x0a)
\ r Carriage return (0x0d)
\f Page Feed (0x0c)
\b Backspace (0x08)
\s Space (0x20)
\ t tab
\ "Double Quotes
\ ' Single quotes
\ reverse Slash
\DDD octal character (DDD)
\uxxxx 16 binary Unicode characters (xxxx)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.