Java underlying data types

Source: Internet
Author: User
Tags float double integer numeric lowercase variables range string variable
Data | data type

1. Simple data type
Logical Type Boolean
Text type char,string (special type)
Integer type Byte,short,int,long
Floating-point type Double,float

Boolean two values: True and False
Char 16-bit unsigned (non-positive) Unicode characters must be enclosed in single quotes (')
eg: ' \ t ' represents a tab character
' \u???? ' represents a special Unicode character???? should be replaced in strict accordance with the 4 16 numbers.
String is not a simple data type but a class (class) that is used to represent a sequence of characters. The character itself conforms to the Unicode standard
The backslash notation for the char type above applies to string.
Different from C and C + +, string cannot end with ' \o '. (originally to write ' \ 0 ', but it is not show, no recruit son, use O to replace it ~ ~)
byte short int long
Follow the data directly with a letter "L". L means this is a long value. In the Java programming language L is equally valid in both uppercase and lowercase, but because lowercase l is easy to confuse with number 1, using lowercase is not a wise choice.
Length and range of values for integer data
--------------------------------------------------------------------------------------------------------------- -------
Length data type numeric range
--------------------------------------------------------------------------------------------------------------- -------
8 bits Byte-2 (7) ~2 (7)-1
Bits Short-2 (15) ~2 (15)-1
Bits Int-2 (31) ~2 (31)-1
Bits Long-2 (63) ~2 (63)-1
--------------------------------------------------------------------------------------------------------------- ------
Float double
The value contains the decimal point or exponent, or the letter F or F (float) after the number, D or D (double)
The length and range of values of floating-point data
--------------------------------------------------------------------------------------------------------------- -------
Length data type numeric range
--------------------------------------------------------------------------------------------------------------- -------
Bits float 1.401e-45~3.402e+38
The bits long 4.94e-324~1.79e+308d
--------------------------------------------------------------------------------------------------------------- -------

2. Declaration and assignment of simple data type variables
public class assign{
public static void Main (string[] args) {
int x,y; DECLARE int variables
float z=3.414f; Declare and assign float variable
Double w=3.1415; Declare and assign double variable
Boolean truth=true; Declare and assign Boolean variable
char c; DECLARE character variable
String str; DECLARE String variable
String str1= "Bye"; Declare and assign String variable
c= ' A '; Assign value to char variable
Str= "Hi out there!"; Assign value to String variable
x=6;
y=1000; Assign values to int variable
...
}
}

Here are some illegal assignment statements:
y=3.1415926; is isn't an int. Requires Casting and decimal would be truncated
w=175,000; The comma symbol (,) cannot appear
truth=1; A common mistake made by ex-c/c++ programmers
z=3.14156; Can ' t fit double into a Float



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.