Syntax Overview of JavaSE Basic Language Features

Java language features

  1. Cross-platform: For java programs, they only need to be developed once, and they can run on different platforms (operating systems).
  2. object oriented
  3. safety
  4. Multithreading
  5. interactive features
  6. Dynamic memory management mechanism

Java language architecture

JavaSE: Java Standard Edition (standard edition java foundation) core class library, basic grammar database connection, IO, network programming, thread...

JavaEE: Java Enterprise Edition (Enterprise Edition), including JavaSE to add Servlet related to the server

JavaME: Java Micro Edition (miniature version) java miniature version is replaced by Android

The operating mechanism of the Java language

Develop a source code (XXX.java) -----compile?----> bytecode file (.class) ----JVM (virtual machine) translation----> operating system

Syntax overview

note


● Notes are used to describe the program functions, marked with a specific symbol, and the program will not execute comments during the running process .

● The Java language has three comment methods:
// for single-line comments, the shortcut key ctrl+/
/ / for multi-line comments, the shortcut key ctrl+shift+/ ctrl+shift+\ to uncomment
/

* */ document comments, used to explain classes, methods (functions), and attribute functions, and can be prompted when calling

keywords

● Definition: a character string (word) endowed with special meaning by the Java language and used as a special purpose
● Features: all letters in keywords are lowercase

reserved word

identifier

● Identifier: The sequence of characters used by Java to name various variables, methods, and classes is called
an identifier. ● Define legal identifier rules:
● Composed of 26 English letters, 0-9, _ or $, numbers cannot begin.
● Keywords and reserved words cannot be used, but keywords and reserved words can be included.
● Java is strictly case-sensitive, and the length is unlimited.
● Identifiers cannot contain spaces.
● Note: When choosing a name, in order to improve readability, it should be as meaningful as possible, "see the name and know the meaning".

● Name naming conventions in Java:
● Package name: When composed of multiple words, all letters are lowercase: xxxyyyzzz
● Class name, interface name: When composed of multiple words, the first letter of all words is capitalized: XxxYyyZzz ● Variable name, method name: When composed of multiple words, the first letter of the first word is lowercase
, and the first
letter of each word starting with the second word is capitalized: xxxYyyZzz
● Constant name: All letters are capitalized. When there are multiple words, each word should be underlined XXX_YYY_ZZ

Java variables

  • A variable is the most basic storage unit in a program, and its value is variable during program execution.

● In essence, a variable is actually a small area in the memory, and the variable name is used to access this area. Therefore,
each variable must be applied for (declared) before being used, and then must be assigned (filled with content) before it can be used.

● Variables access this area by using variable names. ● Its elements include variable names and variable types.
● Each variable in a Java program belongs to a specific data type, which must be declared before use

Java data types

● The program defines specific data types for each type of data, and
allocates memory spaces of different sizes in the memory

1. Integer type

2. Floating point type

3. Logical type Boolean

● The boolean type is suitable for logic operations and is generally used for program flow control.
● The boolean type data in the java language can only take the value true or false.
● Note: 0 or non-zero integers cannot replace false and true, which is different from C language

4. Character type

Basic data type conversion:

● Java can transform from any basic type to another basic type.

● Exception: boolean type cannot be converted to other data types.
● Conversion is divided into default conversion and forced conversion
. ● Default conversion: Integer, character, and floating-point data are converted to each other in mixed operations. The conversion follows the following principles: Small-capacity types are converted to large-capacity data types by default; data types are sorted by capacity: byte, short, char->int->long->float->double byte, short, and char will not be converted to each other. They will first be converted to int type during calculation. For the data type, a mandatory conversion character must be added, but it may cause precision reduction or overflow; special attention should be paid when using it
.
● When there are mixed operations of multiple types of data, the system will first automatically convert all the data into the data type with the largest capacity, and then perform the calculation

operator

● The Java language supports the following operators:
● Arithmetic operators: +, -, *, /, %, ++, -- ● String concatenation operators: + ●
Relational (comparison) operators: >, <, >=, <=, != ●
Logical operators: !, & , | , &&, ||
● Assignment operators: =, + =, - =, =, / =
● Conditional operators (conditional expressions)?
operations on bits

<< fill the vacant bit with 0, discard the removed high bit, and fill the vacant bit with 0.

">>" The highest bit of the shifted binary is 0, after the right shift, the vacant bit is filled with 0;
the highest bit is 1, and the vacant bit is filled with 1.

">>>" is shifted, whether the highest bit of the binary is 0 or 1, and the vacant bit is filled with 0.
& performs & operation on binary digits, and the result is 1 only when 1&1 is performed, otherwise it is 0;
| performs | operation on binary digits, only 0 | 0 results in 0, otherwise it is 1
; Negate everyone

control statement

● Conditional statement - Execute different statements according to different conditions.
● if
● if … else
● if … else if
● if … else if … else if … else
● switch
● loop statement – ​​perform some action repeatedly
● for
● while
● do …while

Guess you like

Origin blog.csdn.net/weixin_52340450/article/details/125754049