JAVA SE basic feed --02: Data Types Operators

JAVA SE feed base 02: Data Types Operators

JAVA基础知识点的核心提要,旨在回顾。

01.JAVA in relative term Description
Keywords: refers to the word that has special meaning in Java programs, such as public, class, void.
Identifier: refers to the variable or method name in the Java program you define.
mainMethods: The main method is a Java program, JVM will always start executing code from the main method.

JAVA data types

Java data types can be divided into basic data types and reference data types:

Basic data types Reference data types
Integer, float, boolean, character Type, an array, an interface

Basic data types:

Eight basic data types:
Here Insert Picture Description

The relationship between variables and constants:

Constant: the program is running does not become a constant amount is constant.
Variable: With the amount of running the program will change it is variable.
Java can only be saved in the variable amount of a data type, so the definition of variables must declare the variable type, similar to C / C ++.
Variable Definition Format:

变量名称 变量名 =数据值;
如:boolean load =trueint num=0float money=1.67F

Precautions:

In 1.Java default integer int, floating point by default double.
2. Define the variables are not assigned can not be used .
3. Definitions longWhen the data type, preferably together with the end of the data L.
4. Define flaotWhen the data type, preferably together with the end of the data F.
5. For the same variable name in braces can not be repeated .

0x04. Data type conversion

Calculation Java program data only among the same type, if not identical, data type conversion is generated.

Automatic conversion:

A smaller range of data types will be converted to a large range of data types. Such as:

int num1=1;
float num2=1.2;//那么num1+num2值为float型
float num3=num1+num2;//num3=2.2
short num4=5;
int num5=6;//尽管num5也在short范围内,但num4+num5的结果应为int型
int num6=num4+num5;

Specific conversion:

byte ->short ->int ->long 
int ->float ->double

Cast:

We need to manually convert called cast.
Conversion 在常量或变量的前面加一括号,括号内的内容为要转换的数据类型method: . Such as:

float num1=1.5;
int num2=(int)num1;//num1将会转换为int型,小数部分将会丢失,num2=1

Precautions:

1. automatic conversion will not cause loss of data, loss of data is likely to cast.
2. cast, the floating point to integer conversion would result in fractional part of the floating-point loss.
3. The mandatory conversion, long to short converter type may result in data loss, abnormal.

Operators 0x05.JAVA

Java is basically the same operator and C / C ++ in the operator.
The basic operators as follows:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
ternary operator: illustration

a=(b>c?c:d)
//分析:若b>c,则a=c,若b<=c,则a=d

Precautions:

1 a++and ++a, when used alone, have said avalue added 1.
2. If the a++and ++abrought assignment:

int a=1;
c=a++;//先赋值后+1,那么c=1;
c=++a;//先+1后赋值,那么c=2;

0x06. The core feed

A data type and memory footprint size range.
Two former cast will have to consider whether valid data loss.
III. Priority exists between the operator must pay attention to the priority see expression.

End of this chapter.
Published 19 original articles · won praise 7 · views 430

Guess you like

Origin blog.csdn.net/ATFWUS/article/details/104247477