Java BASICS (1), Java BASICS (
I. History of Java
Java is a high-level programming language launched by SUN (Stanford University Network, Stanford University Network company) in 1995. It is a programming language applied to the Internet.
1. It is a programming language that is easy to learn, fully object-oriented, secure and reliable, and has nothing to do with the platform.
2. Java is an object-oriented language.
2. Three Java versions
1.J2EE (Java 2 Platform Enterprise Edition) Enterprise Edition
Is a set of solutions for developing applications in an enterprise environment. Technologies included in this technology system, such as Servlet Jsp, are mainly used for Web application development.
2.J2SE (Java 2 Platform Standard Edition) Standard Edition
Is a solution for developing common desktop and business applications. This technology system is the basis of other two technologies and can be used to develop some desktop applications. For example, Java version clearance.
3.Small Edition of Java 2 Platform Micro Edition
Is a solution for developing electronic consumption products and embedded devices. This technology system is mainly used in small electronic consumer products, such as applications in mobile phones.
After Java5.0, change the name to JAVAEE JAVASE JAVAME
Previous versions: 1.0 1.1 1.2 1.3 1.4 1.5 --- Java5 Java6 Java7 Java8
Iii. Common Terms in Java
1,JVM:Java Virtual Machine (VM) and java program run in it. Therefore, Java is a platform-independent programming language. different platforms only need to install different JVMs to run programs. It is a cross-platform language.
2,JRE(Java Runtime Environment)
Including the core class libraries required by Java Virtual Machine (JVM Java Virtual Machine) and Java programs. To run a developed Java program, you only need to install JRE on the computer.
3,JDK(Java Development Kit)
JDK is provided for Java developers, including java development tools and JRE. Therefore, if JDK is installed, you do not need to install JRE separately. Development tools: compilation tool (javac.exe) Packaging tool (jar.exe) and so on.
4,Java API(Application Programming Interface)
The application programming interface is a number of predefined functions to provide applications and developers to access a group of routines based on a software or hardware, but the meaning is richer. A routine is a set of functional interfaces or services provided by a system .) Without accessing the source code, or understanding the details of the internal working mechanism.
5,GC(Garbage Collection) Garbage Collection mechanism
Iv. JDK installation and environment Configuration
1. Installation
Click Next. Select the installation path.
2. Environment Configuration
Purpose: To access javac java in any directory
Operation: configure the path of the javac java tool to the operating system --- configure the environment variable. After the environment variable is configured, open the Command Prompt window again.
The JAVA_HOME value is the JDK root directory.
If JAVA_HOME is configured, the Path can also be configured as follows:
Path % JAVA_HOME % \ bin
5. The first Java program
1. Hello World!
1 public class Hello {2 public static void main(String[] args){3 System.out.println("Hello World!");4 }5 }
2. compilation process
Compile the. java file (Java source file) into a. class file (bytecode file) that can be recognized by JVM ).
Syntax: javac source file. java. Execute this operation in the Command Prompt window.
Hello. java is a Java source file. It is mainly written and modified by programmers and cannot be directly recognized by JVM.
Hello. class bytecode file (running in JVM)
Only bytecode files are required during running, and java files are not required (you can delete them)
6. Java
Basic knowledge 1. Basic syntax
1. The smallest unit of code is class.
2. All punctuation marks must be in English
3. Java is case-sensitive.
4. The name of the bytecode file is the same as the class name. We recommend that the source file name be the same as the class name.
5. You can write multiple parallel classes in a Java source file. After compilation, multiple independent bytecode files are generated. In actual development, a java file has only one class.
6. If a class uses the public modifier, it must be the same as the source file name, And we generally only write one class in a java file. We do not recommend writing multiple classes.In a source file, at most one class can bePublic Modifier
2. java annotations
1. Functions of annotations
Comments can be viewed as comments, mainly written to (your own) programmers. When the code is running, it does not care about the comments and enhances the readability of the Code.
2. Three annotations
// Single line comment, comment a line (based on the line terminator)
/**/Multi-line comment. You can comment multiple rows. Add the comment at the beginning of each line. * This is just for good looks.
/***/Document comments. The effect is similar to multi-line comments. You can also comment multiple lines. Features: You can use javadoc to produce the content in the comments.
Note:: Single-line comment and multi-line comment cannot be nested with each other
3. When to write comments?
Develop the habit of writing comments when writing code-enhanced readability of the Code
1) thought process
2) key code
3) The overall description of the class. comments will be written before the construction method of the field method.
3. delimiter
Semicolon (;): Statement segmentation, indicating the end of a sentence. It is like the end of a sentence.
Curly braces ({}): represents a code block, which is a whole and must be used in pairs.
Square brackets ([]): used to define arrays and access array elements.
Parentheses (): It is widely used and used in detail.
DOT (.): used when class and object access its members.
Space (): splits the entire statement into several segments. The number of spaces is unlimited.
A space can be entered between words.
4,
Keywords-Reserved Words-identifier
Java keywords: words that are given special meanings at the beginning of the Java language design. Public, class ......
It is usually used for program control, error handling, basic types, classes, methods, and variable modifiers ...... And so on.
Commonalities: All letters are in lowercase.
Reserved Words: goto const has not yet given it special meaning in java. It may be used in the future and reserved.
Identifier: the name customized to enhance the readability of the program. For example: Class Name, method name, variable name, etc.
Naming rules for identifiers:
1. All identifiers should start with a letter (A-Z or a-z), dollar sign ($), or underscore (_), number (cannot begin with a number)
2. Keywords cannot be used as identifiers
3. The identifier is case sensitive.
4. Examples of valid identifiers: age, $ salary, and _ value
5. Example of invalid identifiers: 123abc and-salary
Writing suggestions:
1. Generally, some meaningful words are used.
2. The first letter of the class name must be capitalized.
3. method name. The first letter of the variable name is lowercase.
4. If there are multiple words, the first letter of each word is capitalized (named by the hump method)
Summary: keywords are defined by the language, and identifiers are named by ourselves. These words are used to allow us to better understand the program and unify everyone's cognition, this enables good communication between programmers and machines. Although there are many rules and regulations, they are worth observing.