Java Note------(conversions for variables, base data types, data types)

Source: Internet
Author: User

A. Variable : The variable is the amount that the value is allowed to change while the program is running. (Of the data, the pronoun, the number of its existence)
1) Statement:
int A;//declare an integer variable named a
int b,c,d;//Declare three integer variables named B,c,d
2) Name:
2.1) can only contain letters, numbers, _, $ characters,and cannot start with a number
2.2) Strictly case-sensitive
2.3) cannot use keywords
2.4) can be named in Chinese, but not recommended
2.5) Suggestions: See the name of the idea, the hump named Law
3) Initialization: First time assignment
3.1) declaring simultaneous initialization
NT A = +;
3.2) First declaration after initialization
int A;
a = +;
4) Use:
4.1) The use of variables must match the data type
int a = 25.678;//Compilation Error
4.2) variables must be declared and initialized before they are used
System.out.println (a);//compilation error, a not declared
int A;
System.out.println (a);//Compilation error, a uninitialized
int a = +;
System.out.println (a);//Correct
4.3) The use of the variable is the use of the number it has stored
int a = 5;
A = a + 10;//Take out a value of 5, plus 10, assign to a
//On the basis of a itself


Two. Basic data types

1) int: integer, 4 byte,-21 million to 21 multi billion
1.1) Integer Direct quantity default int type, cannot exceed range
int a = 250;//250 default int type
int b = 10000000000;//compilation error, 10 billion default int type, but Hyper range
1.2) Divide two integers, the result is an integer, the decimal place is unconditionally discarded
System.out.println (5/2);//2
System.out.println (2/5);//0
1.3) When an integer operation is over-range, an overflow occurs, which needs to be avoided
2) Long: Long Integer, 8 bytes
2.1) long direct amount after the number plus L or l
long a = 250L;
long B = 10000000000;//compilation error, 10 billion int type
long C = 10000000000L;
2.2) Large number of operations may overflow, it is recommended to add L after the first number
2.3) Gets the number of milliseconds since 1970.1.1 0 o'clock to this moment
Long a = System.currenttimemills ();
3) Double: floating-point, 8-byte
3.1) Floating-point direct quantity defaults to double type
Double A = 25.6378;//25.6378 default double type
3.2) Rounding error, can not be used in precise operation situations
4) Char: Character type, 2 bytes
4.1) Unicode encoding format, each character has a corresponding code
Char is a representation, essentially an int
4.2) Have and have only one character
4.3) The direct amount of the character must be placed in a pair of single quotation marks
4.4) For characters that are not easy to output, you need \ to escape
5) Boolean: Boolean, 1-byte, only true and false

Attachments: Basic Data types


Three. Conversion of data types:
1) divided into two types: from small to large in turn byte,short,int,long,float,double
Char
1.1) automatic type conversion (implicit type transfer): From small type to large type
1.2) Forced type conversion: from large type to small type
(The data type to convert to) variable
There may be a loss of overflow or precision
2) Two-point rule:
2.1) Integer direct amount can be directly assigned to Byte,short,char, but not over range
2.2) When the BYTE,SHORT,CHAR variable participates in the operation, it is converted to int again.

Java Note------(conversions for variables, base data types, data types)

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.