Java basic knowledge---------variables and data structures

Source: Internet
Author: User

We write programs in Java, so what is the program? Program is the data structure + algorithm, that is, we write the program is essentially the operation of the data, digital, text, pictures, audio, video These are a form of information, we are programmed to manipulate the data, so as to achieve different functions. When it comes to data, variables are used to store the calculated result of zero, which means that the variable is the space for storing data and used to refer to a data. I. Variables 1. Declaration of a variable int a;//declares an integer variable named a int b,c;//declares 2 integer variables that are named B and C 2 variables initialized (first assignment) 2.1 Initialize int a = 0;//Declare an integer variable initialized to 0 2.2 at the beginning of the declaration Initialize int b;//Declare an integer variable b b=90;//initialize B for 90 3 variables using 3.1 pairs of variables is the operation of the number of its stored int a=8; int b = a+3; System.out.println (b); 3.2 When using the data type must match int a =3.14;//compilation does not pass, data type mismatch 3.3 must declare and initialize int a before using; System.out.println (a)//compilation does not pass, uninitialized. b=0; SYSTEM.OUT.PRINTLN (b)//compilation does not pass, not declared. The name of the 4 variable named 4.1 variable can only be made up of numbers, letters, _, and $, and cannot be sensitive to the case of a 4.2 variable name beginning with a number, to be strictly differentiated. 4.3 cannot be the same name as the keyword 4.4 can be used in Chinese, but not recommended, suggested English see the text to understand. Two. Data type 1. Integer (int), 4 bytes,-2.1 billion to 2.1 billion more than 1.1 integers the direct amount defaults to the int type, but cannot go beyond the range of 1.2 2 integers to divide the result or integer, the decimal unconditionally discards the 1.3 integer operation when out of range, overflow, overflow to avoid. 2. Long integer, 8 bytes, +-19 digits 2.1 Long integer direct amount to be added after the L 2.2 operation, if possible overflow, it is recommended that after the first number plus L 2.3system.currenttimemillis () to be taken from 1970.1.1 0 o'clock the number of milliseconds to this moment 3. Floating point (double) 8 byte 3.1 default double, if you want float then add F 3.2 floating point type participate in the operation of the error may occur, the exact situation is not applicable. 4. Boolean (Boolean) One byte 4.1 has only 2 values True,false 5. Character type (char) 2 byte 5.1 is encoded in Unicode character set, each characterThere is a corresponding code, the expression form is char, but is actually an int code, ASCII code (' A ' =97, ' a ' = 65, ' 0 ' =48) 5.2 characters directly put in single quotes, can only put one. 5.3 Special characters need to be escaped by/to three. Type conversions

12 Different ways
1.1 Automatic conversion, from small to large
1.2 cast, from large to small, see loss of precision
22-Point Rule
2.1 Integer Direct quantities can be assigned to Byte,short,char, but cannot be out of range.
When 2.2byte,short,char participates in the operation, it is first converted to the int type.

Java basic knowledge---------variables and data structures

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.