Basic Java Learning Summary-Basic Syntax 1

Source: Internet
Author: User
Tags arithmetic operators logical operators variable scope

A. identifiers

  

two. Key Words

  

three. JAVA underlying data type 3.1. Java Constants

  

3.2. Java variables

  

Essentially, a variable is actually a small area of memory, and when a program runs, it's actually in memory, and then it starts running. An. exe file is not run on the hard disk, and the. exe file that you see on your hard disk is nothing more than a file, and when we double-click the. exe file, the entire. exe file is actually placed in memory, and then the operating system finds the Main method, which is the entry for the program, and then starts executing the 。 Execution of the process, will continue to allocate some areas in memory, variables in memory is a small area, the variable has two concepts, one is the name of the variable, the other is the value of the variable, that the small area is a name, containing a value, So in the future, to access the contents of this small area can be accessed according to the name of the small area. Therefore, the essence of a variable is a small area of memory. In terms of variables, how much storage space should be allocated in memory? Different variable types allocate different sizes of storage space, each of which belongs to a particular data type, declared as a different data type, and it allocates different storage space in memory.

Variable scope: The scope of the variable is only valid for "{}", and it doesn't work if the "{}" is out.

3.3. Classification of Java Variables

  

3.4. Java local variables and member variables

  

3.5. Java Data Type Partitioning

  

Four. Java Data type explanation 4.1 . Boolean --Boolean type

  

4.2 . char--Character Type

    

The world's words are all in the computer. 0 and 1,unicode are a way of unifying the language of the world's languages, which can be used to connect the words of the world's nations. Unicode encoding is divided into two kinds, one is Utf-8, the other is Utf-16. Java uses the Utf-16, each character occupies 2 bytes, and any country's text in Unicode is accounted for 2 bytes.

4.3 . integer Type

  

C language Compiled program why not transplant, If you put the. exe file under Linux is not executable, a very big reason is that the C language definition of variables on different operating systems accounted for the size is not the same, declaring an int type of variable, under Windows accounted for 32 bits, but placed under Linux can only occupy 16 bits, then it is likely to indicate that The size is different, declaring a large number under Windows, which is likely to overflow under Linux. So that's why the C language can't be ported after the compilation is complete.

4.4 . floating-point types

  

4.5. Conversion of basic data Types

  

A byte short char is not converted to each other when they are calculated first converted to int type
byte b3= (Byte) (B1+B2);//system will be converted to int type operation, cast (int→ convert byte)

Type conversion test

1 Public classTestconvert {2 Public Static voidMain (String arg[]) {3intI1 = 123; 4intI2 = 456; 5DoubleD1 = (i1+i2) *1.2;//the system will be converted to a double type operation6floatF1 = (float) ((I1+I2) *1.2);//need to strengthen the conversion character7byteB1 = 67; 8byteb2 = 89; 9byteB3 = (byte) (B1+B2);//The system is converted to an int operation and requires a cast character10System.out.println (b3);11DoubleD2 =1e200;12floatF2 = (float) D2;//will generate overflow13System.out.println (F2);14floatF3 = 1.23f;//must add f15LongL1 = 123;16LongL2 = 30000000000L;//must be plus l17floatf = l1+l2+f3;//system will be converted to float type calculation18LongL = (Long) F;//The cast will shed the fractional part (not rounding)19     }20}

Five. operator

  

5.1. arithmetic operators (self-plus and decrement operators)

  

Note: + + (--) arithmetic operation Shizhan Self-subtraction
First operation and then the value
To take a value before the operation

5.2. Logical operators

  

5.3. Assignment Operators

  

5.4. String Connector

  

5.5. Expressions

  

5.6. Three mesh operator

  



Basic Java Learning Summary-Basic Syntax 1

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.