Third day of Java Learning-Basic knowledge Summary

Source: Internet
Author: User
Tags arithmetic operators

First, Introduction to Java

Advantages of 1,java language

The biggest advantage of the Java language is platform-agnostic, with the same code available on Windows 9x, Windows NT, Solars, Linux, MacOS, and other platforms. The "write once, run Everywhere" feature makes it widely used on the Internet.

2,java language Features: Concise and effective, portability, object-oriented, interpretive, suitable for distributed computing.

3,java the framework of a program: identifiers, keywords, annotations, variables, data types, operators, and expressions, classes.

4, Program detection: syntax error, semantic error.

5, improve the readability of the program: (1) Note; (2) Appropriate indentation.

Second, constant and variable

1, constant

Declaration: Final data type constant name "= value"

PS: Constant names are usually capitalized, such as Pi, year, and so on.

2, variable

A variable is a declaration that preserves a block in memory for use by the program. The data types that can be declared as blocks are integer, character, float, or other data types.

3, naming rules for variables

A variable is also an identifier, so it follows the naming conventions of identifiers.

(1) Variable names may consist of any order of uppercase and lowercase letters, numbers, underscores (_), and dollar signs ($);

(2) The variable name cannot begin with a number;

(3) The variable name cannot be a reserved keyword in java.

4, the scope of the variable: (1) member variable (2) local variable

  Third, the data type

1, integral type data

(1) Basic data type:

Numeric type:

Integer type (byte, short, int, long;

Floating-point type (float, double);

Character type (char);

Boolean type (Boolean);

(2) Reference data type:

Classes (Class)

Interface (interface)

Array

The 2,byte type, occupying 1 bytes, takes a range of values: -128~127.

3,short type, occupies 2 bytes of memory space, the value range: -32768~32767.

4,int type, occupies 4 bytes of memory space, the value range: -2147483648~214736483647.

5,long type, occupies 8 bytes of memory space, the value range: -9223372036854775808~9223372036854775807.

The 6,float type, which occupies 4 bytes. A double type that occupies 8 bytes.

7, character type, occupies 2 bytes.

8, Boolean type (True, false).

9, conversion of data types:

(1) Automatic type conversion

1) The data type before conversion is compatible with the converted type;

2) The converted data type has a larger representation range than the type before the conversion (small turn Large).

(2) Coercion type conversion: (the data type to be converted) variable name;

10, the default value for the base data type:

byte:0

short:0

int:0

long:0l

float:0.0f

double:0.0d

Char: \u0000 (empty)

Boolean:false

Iv. operators, expressions, and statements

1, Operator: + 、-、 x,/,%, etc.

2, assignment operator: =

3, unary operator: +-! ~

4, arithmetic operator: +-*/%

5, relational operator: if statement;

6, Increment and decrement operator: + +--

7, logical operator: && | |

8, the parentheses Operator: (), the expression in parentheses has a high precedence.

9, expression: is a statement that is composed of constants, variables, or other operands and operators.

10, arithmetic expression: used for numeric calculations, consisting of arithmetic operators and variables or constants, and the result is a numeric value.

11, relational expression: commonly used in program judgment statements, composed of relational operators, the results of the operation is logical type.

12, logical expression: is an expression made up of logical operators, and the result is also a logical type.

13, conditional expression: by operator "? : "Composition, whose basic form is: A?x:y, if the A value is not 0, then the value of the entire expression is x, otherwise y.
14, copy expression: The copy expression consists of an assignment operator and an operand, and the assignment operator is used to assign a value to the variable.

15, the expression type conversion:: With no loss of data as a precondition.

(1) A type with less bytes is converted into a type that consumes more bytes;

(2) The character type is converted to int type;

(3) int type will be converted to float type;

(4) If an operand is of type double in an expression, the other operand is also converted to a double type;

(5) Boolean types cannot be converted to other types.

Third day of Java Learning-Basic knowledge Summary

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.