First, JavaThe history of the language
Java is a high-level programming language introduced by SUN (Stanford UniversityNetwork, Stanford University web company ) 1995 , and is an application The programming language of the Internet.
1, is Easy and easy to learn , completely object-oriented, secure, platform-independent programming language.
2, Java is an object-oriented language.
Ii. Three versions of the Java language
1.ee (Java 2 Platform Enterprise Edition) Corporate Edition
is a set of solutions for developing applications in an enterprise environment. The technologies included in the technology system, such as Servlet Jsp , are mainly for Web application development.
2. j2se(Java 2 Platform standard Edition) edition
is a solution for developing common desktop and business applications. The technology system is the basis of the other two, can be completed some desktop application development. Like the Java version of Minesweeper.
3.J2ME (Java 2 Platform micro Edition) Mini version
It is a solution for the development of electronic consumer products and embedded devices. The technology system is mainly used in small electronic consumer products, such as mobile phone applications.
after the Java5.0 version, renamed to java EE javase javame
Previous Versions : 1.0 1.1 1.2 1.3 1.4 1.5---"Java5 Java6 Java7 Java8
Iii. Common terminology in Java
1. JVM : java virtual machine,java program running in it, it is so Java is platform-independent programming language, different platforms as long as the installation of a different JVM can run the program, is a cross-platform language.
2.JRE(Java Runtime Environment Java Run Environment )
include Java VMS (JVM java Virtual machine) and the core class libraries required by Java programs , and so on, if you want to run a well-developed Java program, you only need to install the computer JRE can be
3.JDK(Java Development Kit Java Development Kit )
The JDK is available to Java developers, which includes Java Development tools and the JRE. So with the JDKinstalled, you don't have to install the JRE separately . One of the development tools: the Compilation tool (javac.exe) Packaging tool (Jar.exe) and so on.
4.Java API(application programming Interface)
Application programming interfaces are pre-defined functions designed to provide applications and developers to access a set of routines based on a piece of software or hardware (routines that function like functions, but with a richer meaning.) A routine is a collection of functional interfaces or services that a system provides externally. ) without having to access the source code or understand the details of the internal working mechanism.
5.GC(Garbage Collection) garbage collection mechanism
Iv. installation and environment configuration of the JDK
1. Installation
Always point to the next step, and pay attention to selecting the installation path.
2. Environment configuration
Purpose: You can access the Javac Java in any directory below.
Action: Configure environment variables by configuring the path of the Javac Java tool to the operating system ---, and then need to reopen the command prompt window after configuring the environment variable
the value of Java_home is the root directory of the JDK
If you have configured Java_home , then Path can also be configured like this
Path%java_home%\bin
Five, 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 the JVM can recognize .
Grammar : javac source file . Java, perform this operation in a command Prompt window
Hello.java is a java source file that is written and modified by the main programmer, and theJVM is not able to directly identify
Hello.class bytecode files (running in the JVM )
only need to run the bytecode file, do not need Java files (can be deleted)
VI. Java
Basic Knowledge
1. Basic Grammar
1, the code is the smallest existence unit is class
2, All punctuation must be in English state
3. Java is strictly case-sensitive
4, byte code file name and class name consistent, it is recommended that the source file name and class name consistent
5, a Java source file can write multiple parallel classes, after compilation will generate a number of independent bytecode files , the actual development of a Java file only one class
6, if a class using public decoration, must be the same name as the source file, and we generally will only write a class in a java file, it is not recommended to write more than one class. only one class can be modified by public in a source file
2. Java Annotations
1, the role of annotations
comments can actually be considered as remarks, mainly written to (self) programmers See, the code runs without the comment content, can enhance the readability of the code.
2, three kinds of annotations
single-line comment, one line of comments ( whichever is the line terminator )
/* */ Multi-line comment, can comment on multiple lines , each line preceded by * just to look good
/** * /document comments, the effect is much like multiple lines of comments, can also comment on multiple lines, features: You can use a command Javadoc The contents of the document comments to produce documents
Note : Single-line comments and multiline comments cannot be nested with each other
3. When to write notes
The habit of writing notes when writing code--the readability of the code is enhanced
1) idea Flow
2) key code
3) The whole description of the class; Field method construction method The comment is written before
3. Separators
semicolon (; ): The split of the statement, the end of a sentence, as we use the period.
Curly Braces ( {}): Represents a block of code, is a whole, curly braces are to be used in pairs.
square brackets ( []): used when defining arrays and accessing array elements.
Parentheses ( ()): Widely used, specifically used in detail.
Dots (. ): Used when classes and objects access its members.
spaces ( ): Divides a whole sentence into a few paragraphs, the number of spaces is not limited.
A space between the general words can be
4. Keywords
- reserved words - identifiers
Java keyword : at the beginning of the Java Language design, words that were given special meaning. Public, class ...
usually used to Program Control , Error Handling , Basic Type , class , method, and variable modifiers ... Wait a minute
Common denominator: all the letters all lowercase
Reserved Words :Goto Const is not yet given a special meaning in java and may be used later, reserved.
identifiers: To enhance the readability of the program a custom name . For example: Class name, method name, variable name, etc.
Naming rules for identifiers:
1. All identifiers should be in letters ( A-Z or A- z), a dollar symbol ($), or an underscore (_), Number (cannot start with a number)
2. Keywords cannot be used as identifiers
3. identifiers are case-sensitive
4. Examples of legal identifiers:age,$salary,_value
5. examples of illegal identifiers:123abc,-salary
Writing advice:
1, generally are to take some meaningful words
2. The first letter of the class name must be capitalized
3. method Name, first letter of variable name lowercase
4. If there are multiple words, the first letter of each word is capitalized (camel name)
Summary: The keyword is defined by the language itself, and the identifier is our own name, these words are to allow us to better understand the program, unify everyone's cognition, so that programmers, between the programmer and the machine can communicate well. There are many rules, but they are worth keeping.
Java Basics (i)