Java start (basic)

data type

Boolean 1 bit byte 1 byte (8 bits) short 2 bytes char 2 bytes int 4 bytes long 8 bytes

The default type uses double and int by default. If you want to use float or long, you need to add f or l after its number

Why char is two bytes? In C, char is the ascll character set, with a maximum of 255, while in Java, char is the Unicode character set, with a maximum of 65535, which contains the characters of various countries. Therefore, Chinese characters cannot be used as variable names in C, while Java can

Boolean type boolean type only occupies one bit. Unlike C language, it can realize non-zero or true. Its value must be true or false

Automatic type conversion small type will be automatically converted to large type byte - > short - > int - > long - > float - > double

Quantity and operation

Variables and constants

Class variable: the variable will be automatically assigned with an initial value of zero and belongs to the class object. The class static variable must be used through the class object: the variable will be automatically assigned with an initial value of zero and belongs to the class. It is best to use the class name to call the local variable: the local variable has no initial value and can be used only after manual assignment

Constant: an amount whose value is immutable (final int II = 10;)

The scope of the scope local variable is {}

Ternary operation

Switch()... Case. Its value can be numbers, characters and strings. Strings cannot be used before, but in jdk1 7 that is, the string will be available later

Bit operation or logic operation

Bit operations: [&], [|], [~], [^] (exclusive or by bit, the same returns 0, different returns 1) logical operations: [&], [& &], [|], [|], [!]

The picture comes from Shang Xuetang

For example: "~" and "!" Differences: 1 "~" binary bit inversion, 1 is (0000 0001) 2, ~ 1 = 1111 1110 2. "!" Logical negation, non-0 is true and 0 is false

Mathematical operation

random number

Exponential operation public static double pow (double a, double B)

Square root public static double sqrt (double a)

Console input

Next() receives a string, space or carriage return ends, nextline() receives a string, carriage return ends, nextint() receives an int type data, nextdouble() receives a double type data, nextboolean() receives a boolean type data

Output of escape characters

【\】、【”】、【”】、【\n】

anomaly detection

Exception statement block

Throw exception

Java environment

1. It can be seen from the figure that the three are inclusive relationships. JDK includes JRE and JRE includes JVM; 2. When developing Java programs, you must install JDK. 3. It's good to have JRE when running Java programs. 4. When JVM is virtual machine, the virtual machine corresponding to each system of JVM is officially provided. Therefore, when developing Java programs, you can ignore the differences of each platform and realize the effect of programming everywhere. 5. JDK download address: https://www.oracle.com/technetwork/java/javase/downloads/index.html

The first Java program on the command line

code:

Create a new directory Myjava and a new file Dong java

Enter directory

A with the same name will appear after compilation Class file, which is the virtual machine interpretation file

implement

Operation results

When an error occurs:

Download and installation of editing tools

download

Download from the official website https://www.eclipse.org/downloads/ This article uses: links: https://pan.baidu.com/s/10ZDqTZbhnQy6sGnYmw0_tw Extraction code: sxz2 installation

Select workspace workspace is the place where the project is stored. You can check the following box to remember this selection

New project

New class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>