When autumn comes on September 8, I will kill a hundred flowers after the flowers bloom
Why choose JAVA
Features of JAVA:
- Simplicity
- Object-oriented
- distributed
- Robustness
- safety
- Architecture neutral
- portability
- Explanatory
- high performance
- Multithreading
- Dynamic
In terms of grammatical structure, JAVA is relatively simpler than C/C++, because of the lack of pointers, JAVA will appear simpler.
In addition, JAVA has good cross-platform performance. After the version is selected, it can run normally on both MAC and Windows platforms. However, C/C++ is likely to run on different platforms or even different computing bits. Will be different. For JAVA: compile once, run everywhere
Of course, language is not absolutely good or bad.
Each language has its suitable and good application environment:
- C language is the basic builder, and almost all operating systems are written in C language.
- C++ is an object-oriented C language, and it is constantly improving. Compared with JAVA, C++ has shown higher superiority when developing large-scale games.
- Python is used for system management, and provides APIs for scientific computing, text processing, etc. through high-performance pre-compiled libraries. It is a mandatory interpretive language for Linux.
- The GO language has built-in concurrency capabilities, which can compile local code; a large proportion of the current new network-related projects are written in the GO language, such as Docker, Kubernetes, etc.
- JavaScript is a language that can run in the browser, and the rich front-end interface cannot do without Javascript. In recent years, Node.js has gained
a place in the backend .
There are also PHP for writing web pages, Lisp/Scala for functional programming, and Swift/Objective-C for writing iOS programs.
Let JAVA say hello to my life
-
Create a notepad and change the suffix to .java
-
Programming with note++
-
Run with cmd
Parsing
In programming, we should pay attention to:
Regarding the first line:
1. In a java file, there can only be one public class
2. The class name needs to be the same as the file name
3. According to the naming convention, the class name uses the capitalized initials Interval
4. The left parenthesis should immediately follow the current line.
About the class body:
the part enclosed by the outermost brace is called the class body. The
class body contains: fields, methods
What have we learned from the simplest piece of programming?
Java's main method is static (static). The
main method has no return value.
Main is a method body.
"Hello World!" is a string type (not in C language)
About running:
without using a compiler, we can clearly understand a java program
When we compile java, we need to enter the location of the file, use the javac command to generate the class file in the location, and hand the binary file to the machine for identification.
Among them, a class in the java file corresponds to a class file.
The advantage of this is that for the virtual machine, it can be taken at any time, which class is used, and the class is obtained without occupying a large amount of memory at the same time.
When running with the java command, the class file will be loaded into the JVM virtual machine to run.
Among them, java and javac belong to JDK commands
Interview questions
- What are JDK, JRE, and JVM?
JDK: Java development tools
JRE: Java Runtime Environment Java Runtime Environment
JVM: Java Virture machine Java virtual machine
(it is the use of the JVM virtual machine, which proves that Java is compiled once and runs everywhere, regardless of operating system or platform The difference affects the result of the code) The
relationship between the three:
Annotation method
- Line comment
only comment the current line - Block comment comments on the
entire block of code - Documentation comments
are generally used to specify the code author and related description.
About reporting errors
From the perspective of the running process, you only need to use the javac HelloWorld.java command to achieve compilation, so why do I add
-encoding UTF-8 here ?
When the java file contains Chinese characters, the following error will appear when using javac alone:
This is caused by the bytecode format mismatch. When the bytecode format is not declared, the system defaults to the GBK format.
At this time, we can With the -encoding UTF-8 command, you can instruct javac to use the UTF-8 format during the compilation process and convert it to the result we want.