20145234 Huangfei The second week of Java programming

Source: Internet
Author: User
Tags logical operators

Summary types of learning contents of textbook

Java can be distinguished as a base type (Primitive type) and a class type, where the class type is also called the reference type (Reference type).

A byte type, also known as a byte type, is 1 bytes long, typically when processing data in bytes (shape processing, encoding processing, and so on).

Integers can be subdivided into 4 types, which can be divided into short integers (2 bytes), int integers (4 bytes), and long integers (8 bytes), depending on the size of the space occupied in memory.

Floating-point numbers are used to denote decimals, which can be classified as float (4 bytes) and double (8 bytes).

The character char type is used to store some character symbols, each of which is 2 bytes, and both Chinese characters and English character are stored in Java in double-byte.

Boolean: Only True and false two are represented.

After the JDK5, with printf (), this is similar to the C language of the PrintOut statement, and its usage is basically consistent with the C language, it is necessary to use some format control symbols to set the format type of the output.

Variable

The name of the variable, usually named after the camel case, starts with a lowercase letter and capitalizes the first letter at the beginning of each word.

With regard to the use of variables, it is important to initialize the variable before calling it, that is, to assign a value to the variable before it can be used, or, if you do not want the subsequent action to change the value of the variable, the assignment statement should be preceded by final, for example: final double PI = 3.141596, the subsequent operation cannot be re-assigned, or the compilation will be an error.

When representing a numeric constant, a binary number is represented by 0b, and a hexadecimal number is represented by 0x.

Operator

The characteristic of,&& in logical operators is that if the left side of the && is false, the logical judgment returns the result false regardless of the right truth; is characterized by the fact that if | | On the left is true, the logical judgment of the return result is true regardless of the right truth. This, to a certain extent, can improve the efficiency of code compilation and execution. That is, headed on the left. Therefore, in the increment, decrement operator, it is important to note whether the operator is placed on the left or right side of the variable, if the operator is on the left side of the variable, then the variable value is changed before the operation, if the operator on the right side of the variable, then the first operation and then the corresponding addition and subtraction of variables.

Type conversions

In Java, the variable type is very strict, in the case of unspecified, the integer is generally the type int, the decimal is the default double type, if you do not pay particular attention to these are easy to err.

Another case is that different types of operands follow some principles when doing operations. If the operands are integers that are not more than int, all are automatically promoted to the int type, and if the operands are of different types, the operation is dominated by the longest type.

Process Control

If...else Conditional type

Switch conditional type

For loop If there is no description in the Judgment section, the default is true, which is an infinite loop.

While loop

When the type loop: while (conditional) {description clause}, first judge the conditional Boolean type, if it is established, then execute the description sentence.

Until the type cycle: do{description sentence}while (conditional), characterized by the first time to perform a description of the sentence, and then judge the condition, if the condition is set up and then execute the description sentence, until the condition is not established.

It is important to note that while there are two types of differences, in the notation, note that there is no semicolon after the type while, and the second has a semicolon.

Break continue

Break: Ends the current loop.

Continue: Skips the current loop once.

Break, continue can also be used in conjunction with the label. When break is matched with a label, all the statements contained in the label are closed, and all statements contained by the label are skipped when the continue is matched with the label.

20145234 Huangfei The second week of Java programming

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.