Refactoring the basis of Java (1) | Talk about constants and variables in java

Java概述:

In 1991, James Gosling of Sun Company and others began to develop a language named Oak, hoping to be used to control microprocessors embedded in cable switch boxes, PDAs, etc.; in 1994, the Oak language was renamed Java, and it has prevailed since then~

1. Three technical architectures of Java:

  • JAVAEE:Java Platform Enterprise Edition, to develop applications in the enterprise environment, mainly for web program development;
  • JAVASE: Java Platform Standard Edition, complete the development of desktop applications, is the basis of the other two;
  • JAVAME: Java Platform Micro Edition, develop electronic consumer products and embedded devices, such as programs in mobile phones;

2. Common terminology in Java development

  1. JDK:Java Development Kit, java development and operating environment, java development tools and jre.
    Insert picture description here

  2. JRE:Java Runtime Environment, the running environment of java programs, the required class library + JVM (java virtual machine) for java running.
    Insert picture description here

  3. Configure environment variables: allow the tools in the java jdk\bin directory to run in any directory. The reason is that the directory where the tool is located is told to the system. When the tool is used, the system will help us find the specified directory.
    Configuration of environment variables:
    1): Permanent configuration: JAVA_HOME=%installation path%\Java\jdk path=%JAVA_HOME%\bin
    2): Temporary configuration: set path=%path%;C:\Program Files\Java \jdk\bin
    Features: By default, the system first goes to the current path to find the program to be executed, if not, go to the path set in path to find it.
    Classpath configuration:
    1): Permanent configuration: classpath=.;c:;e:
    2): Temporary configuration: set classpath=.;c:;e:\

Note: When defining the classpath environment variable, you need to pay attention to the situation.
If the environment variable classpath is not defined, after java starts jvm, it will find the class file to be run in the current directory;
if the classpath is specified, it will search in the specified directory The class file to run.
Will it still be found in the current directory? Two cases:
1): If there is a semicolon at the end of the classpath value, and the running class is not found in the specific path, it will be searched again in the current directory by default.
2): If the value of classpath results in no semicolon, the running class is not found in the specific path, and it will not be found in the current directory.
Generally, the semicolon is not specified. If the class file to be run is not found in the specified directory, an error will be reported so that the program can be debugged.

3. javac command and java command

What do javac and java commands do?
You must know that java is divided into two parts: one is compiling and the other is running.

  • javac: Responsible for the compilation part. When javac is executed, the java compiler program will be started. Compile the .java file with the specified extension. A bytecode file that can be recognized by jvm is generated. It is the class file, which is the running program of java.
  • java: The part responsible for running. It will start the jvm. Load the class library required at runtime and execute the class file.
    To be executed, a file must have a starting point for execution, which is the main function.

Java基础语法

1. Variable

1.1 Definition

Variable: It is a storage space in the memory used to store constant data during the running of the program.
Function: Convenient for calculation. Because some data is uncertain. So determine the nouns and storage space of the data.
Features: Variable space can be reused.

[修饰符] 变量的类型    变量名=value;

Naming conventions:

  • It is composed of letters, numbers, underscores (_) and dollar signs ($), but cannot start with a number; it cannot be a keyword in the Java language.
  • Java keywords are: abstract, boolean, break, byte, continue, case, catch, char, class, const, default, do, double, else, extends, false, final, finally, float, for, if, implements, import, instanceof, int, interface, native, long, new, null, package, private, protected, public, return, short, static, super, switch, synchronized, throw, throws, this, transient, try, void, while, etc. The keywords of the C language are reserved, and there are no other uses in Java for the time being, they are used for future expansion.
  • Reserved keywords are: goto, const
1.2 Data type
  1. Basic data types: byte, short, int, long, float, double, char, boolean
  2. Reference data types: array, class, interface.
    The level from low to high is: byte, char, short (these three equal levels) -> int -> float -> long -> double
    automatic type conversion: from low level to high level, the system automatically converts;
    forced type conversion : Assign a high-level number to a low-level variable other than that number;
1.2.1 Basic types
Variable type Digits range Remarks
byte 8th place -27-------27-1 Signed integer
short 16th place -215-------215-1 Signed integer
int 32nd place -231-------231-1 Signed integer
long 64th -263------263-1 Signed integer
char 16th place 0-----216-1 Unsigned integer
float 32nd place Single-precision symbol
double 64th Double-precision symbol
boolean First place Value: true or false
1.2.2 Characters and strings
  1. A character is a single outputable symbol used in a source file. They are the basic data types character and string. Note: Characters cannot be used as variables, which means that they cannot be assigned values. Therefore, the Java language defines another form of character text representation, which is prefixed with \u followed by a 4-digit hexadecimal integer;
  2. A string refers to a sequence of characters enclosed in double quotes, for example: "java". Note: The difference between "a" and'a'. In the Java language, strings are object types, and characters are basic types.
1.2.3 escape characters
Escape character Representative characters
\ Slash
\r Carriage return
\n Wrap
\t Tab
\b backspace
\’ apostrophe
\” Double quotes
\f Paper
1.2.4 Representation of integer and floating point
  1. Integer representation:
    Decimal: the default is decimal representation, for example: int x=10;
    octal: octal representation represented by 0 as a prefix, for example: int x=016;
    hexadecimal: 0X or 0x as prefix Represents the hexadecimal notation, for example: int x=0x1f;
    Note: The alphabetic book in hexadecimal can be either uppercase or lowercase.
  2. Floating point representation:
    decimal: the default is decimal representation. For example: double f=2.0;
    scientific notation: expressed in MEN form. For example: double f=1E3;
    Note: M can be a positive or negative number, but it must have a number. N can be positive or negative, but must be an integer.
1.3 Scope and lifetime of variables
  • The scope of the variable: the
    scope starts from the position where the variable is defined and ends with the pair of braces where the variable is located;
  • Life cycle:
  1. Variables live in memory from the defined position;
  2. The variable disappears in memory when it reaches its scope;

2. Constant

2.1 Definition

Constant: The data that does not change in the program.
format:

[修饰符] 常量类型 常量名=;

注意:The modifier can be an access permission modifier, and the final keyword must be used. It is a non-access permission modifier; the
constant must be finalized; the constant name is best to be capitalized; it must be assigned; once the constant is assigned, it cannot be changed.

3. Keywords & reserved words

  • Keywords: Words that are given special meanings in a certain language.
  • Reserved words: words that have not yet been given a special meaning, but are prepared to be used in the future.
  • Identifier: It is a noun customized in the program. Such as class name, variable name, function name. Contains 0-9, az, $, _;

Guess you like

Origin blog.csdn.net/weixin_43853746/article/details/107726028