The history of Java The 1990s saw the emergence of single-chip computer systems in hardware In 1991, sun (Stanford University Network, Stanford University Network Company) established the Green project team to develop the oak language, including Patrick, James Gosling and others. In January 1996, SUN officially released Java's first development kit (JDK1.0) Java Language Platform J2SE: Standard Edition, mainly for the development of ordinary desktop applications, and the basis for the other two J2EE: Enterprise Edition, which provides a set of solutions for developing applications in an enterprise environment J2ME: Small version, mainly refers to the development of mobile devices or embedded devices JVM,JRE,JDK what is cross platform Platform refers to the operating system (eg: windows, Linux, mac, etc.) Cross-platform: Java programs can run on any operating system, write once and run anywhere Principle: To achieve cross-platform need to rely on Java's virtual machine JVM (Java Virtual Machine) Diagram principle: Java program windows Linux Mac jvm for mac win version jvm Linux version jvm JVM is a Java virtual machine. Java programs need to run on the virtual machine. Different platforms have their own virtual machines, so the Java language can be cross-platform, and different platforms have their own virtual machines, so the Java language can be cross-platform. JRE includes Java Virtual Machine (JVM) and core class libraries required by Java programs, etc. If you want to run a developed program, you only need to install JRE in your computer. JDK The JDK is provided for Java developers, which includes the Java development kit and JRE, so after installing the JDK, there is no need to install the JRE separately. JDK contains JRE and Java development tools The relationship of the three JDK>JRE>JVM (inclusive relationship) Common dos commands: dir,cd,cd..,javac,java,java -version,win+r,win+e,win+d,cd\,cls,exit Install and configure JDK This is mainly to control environment variables, set JAVA_HOME Notes: single line comment: // comment content Multi-line comments: /*... Comment content....*/ Text comment: /**.. Comment content....*/ Such annotations can be used to automatically generate documentation. There is a javadoc tool in the JDK, which can generate an HTML document from the source file. Annotating the content of the source file in this way looks professional and can be saved as the source file is saved. That is to say, when modifying the source file, it is also possible to modify some commentary texts such as the requirements of the source code. Then, at this time, the source code and the document can be saved together without creating another document. Documentation comment location (1) Class annotations. Class annotations are used to describe the functionality, features, etc. of the entire class, and it should be placed after all "import" statements and before the class definition. This rule also applies to interface annotations. (2) Method annotations. Method annotations are used to describe the definition of the method, for example, the parameters of the method, the return value and the function of the method. A method annotation should be placed before the method definition it describes. (3) Attribute annotations. By default, javadoc only documents public and protected properties - usually static constants. (4) Package comments. The annotations of classes, methods, and attributes are directly placed in the Java source file, while the annotations for the package cannot be placed in the Java file. This can only be achieved by adding a package.html file in the directory corresponding to the package. Purpose. When generating the HTML file, the contents of the <BODY> and </BODY> sections of the package.html file will be extracted as the package description. Regarding package annotations, there will be further explanations later. (5) Summary notes. In addition to package comments, there is one type of documentation that cannot be extracted from Java source files, and that is a file that provides an overview of all class files. Similarly, you can also create a separate HTML file for this type of annotation, the file name is "overview.html", and the content between its <BODY> and </BODY> tags will be extracted. ·@author: The author. · @version: version. ·@docroot: Indicates the root path of the generated document. · @deprecated: Deprecated method. · @param: The parameter type of the method. · @return: The return type of the method. · @see: Used to specify the content of the reference. · @exception: The exception thrown. · @throws: exception thrown, synonymous with exception keywords Words given special meanings by the Java language The letters that make up the keyword are all lowercase syntax format Constants and Variables A constant is a quantity whose value cannot be changed during program execution. A variable is essentially a small area in memory. The amount by which its value can change during program execution variable definition format data type variable name = initialization value type of data Whether it is a memory or a hard disk, the smallest unit of information in a computer storage device is called a "bit", which is also called a "bit", usually represented by a lowercase letter b. The smallest storage unit of a computer is called a "byte", usually represented by a capital letter B, and a byte is composed of 8 consecutive bits. 1B=8bit 1KB=1024B …… Java is a strongly typed language Java data types are divided into: Basic data types: Integer: byte(1), short(2), int(4), long(8) Float: float(4), double(8) Character type: char(2) boolean: boolean(1) Reference data type: class interface array ([]) identifier Consists of letters, underscores, dollar signs and numbers The characters here use the unicode character set, so it includes moiré uppercase and lowercase letters, Chinese characters, numeric characters, etc. Note: Numbers cannot start cannot be a Java keyword Naming rules: Know your name Package name: all lowercase, usually the domain name is reversed Class or interface: capitalize the first letter, camel case Method or variable name: lowercase the first word, capitalize the first letter starting from the second Constant all uppercase letters, if it is more than one word, it needs to be linked with an underscore under each word Notes on variables: The variable is not assigned and cannot be used directly A variable is only valid in its scope type conversion implicit conversion byte,short,char-->int -->long-->float-->double cast (destination type) = (destination type) the type that needs to be converted; operator Symbols that operate on constants and variables are called operators expression Expressions that conform to Java syntax by connecting constants and variables with operators can become expressions arithmetic operators +,-,*,/,%, ++,-- For ++ and -- separate operations, there is no difference between before and after, both operate on themselves. However, in the expression before, it means that it first performs the operation on itself, and then participates in the expression operation. After the expression, it first participates in the expression operation, and then operates on itself. Summary: "Previous Self" assignment operator +=,-=,*=,/=,%=,== It needs to be explained here, two symbols, hiding the forced type conversion Ryo: byte a = 10; a+=20;=》a=(byte)(a+20) And a=a+20; but it will report an error, because the default 20 is of type int, the type does not match, but the above will not report an error relational operator >,<,>=,!= Description: The result of a relational operator is itself a boolean value Logical Operators &,|,^,! &&,|| Binocular is short-circuiting. When the current previous expression has a decisive result, the latter expression is not executed. In actual development, short-circuiting is often used. Ternary operator expression? Expression 1: Expression 2 Check if the value of expression 1 is true, execute expression 1 if it is true, otherwise execute expression 2 keyboard entry Scanner in=new Scanner(System.in); The package needs to be imported, the invocation is to construct (instantiate) an object using the constructor method, and use the object to invoke its methods. control flow statement sequential structure There is no specific syntax, and it is executed at one time according to the order of the code. Inside the main method of Java, it is actually executed sequentially choose structure if statement if (relational expression) { statement body; } loop structure for for(initialization condition; judgment condition; control conditional statement) { loop body statement; } while initialization statement; while (judgment conditional statement) { loop body statement; control conditional statements; } do…while initialization statement do{ loop body statement; control conditional statements; }while (judgment conditional statement) The difference between the three cycles Do...while loop will execute at least once for and while loops will only execute the loop body when the condition is true Difference between for and while loop The variable that controls the conditional statement cannot be accessed after the for loop ends, and it can continue to be used after the while loop. The variable disappears from the memory, which can improve the efficiency of memory usage. The while loop is mainly for loops with an indefinite number of loops. Use the infinite loop of while and for loop cleverly. multiple selection Switch switch(expression){ //The value of the expression is byte, short, int, char, //After JDK5, it can be an enumeration, and after JDK7, it can be a String Case expression value 1: //The value of the root behind the case is compared with the value of the expression statement body 1; break; ….. default: statement body n+1; break; } break control statement break和continue Use scenarios of break In select structure switch statements and loop statements It is meaningless to leave the usage scene, the role of break is to jump out of the single-level loop. coutinue scene Used in a loop statement, it doesn't make sense to leave the usage scenario The difference between break and continue break to exit the current loop Coutinue ends this cycle Random generate random numbers usage: // construct an object Random s=new Random(); //get random number Int number = s.nextInt(10); //Get a random number between 0-10, including 0, but not including 10. array understand An array is a container for storing multiple variables of the same type, and the data types of these multiple variables must be consistent. concept Arrays are containers that store multiple elements of the same data type. Arrays can store both primitive and reference data types. array definition format Format 1: data type[] array name; Format 2: data type array name[]; After these two definitions are completed, there are no elements in the array. Arrays in Java must be initialized before they can be used The so-called initialization: is to allocate memory space for the array elements in the array, and assign values to each array element. Dynamic initialization: datatype[] array name=new datatype[array length]; Int[] arr=new int[3]; Dynamic initialization, only the length is specified, and the initialization value is given by the system Static initialization: data type [] array name = {1, 2, 3}; // put the elements directly Static initialization, the initialization value is given, and the system determines the length.
Java basic grammar knowledge summary
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324655621&siteId=291194637
Recommended
Ranking