First acquaintance with JAVA, please take care

When autumn comes on September 8, I will kill a hundred flowers after the flowers bloom

Why choose JAVA

Features of JAVA:

  1. Simplicity
  2. Object-oriented
  3. distributed
  4. Robustness
  5. safety
  6. Architecture neutral
  7. portability
  8. Explanatory
  9. high performance
  10. Multithreading
  11. 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:

  1. C language is the basic builder, and almost all operating systems are written in C language.
  2. 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.
  3. 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.
  4. 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.
  5. 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

  1. Create a notepad and change the suffix to .java
    Insert picture description here

  2. Programming with note++
    Insert picture description here

  3. Run with cmd
    Insert picture description here

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
Insert picture description here

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.
Insert picture description here
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

  1. 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:
    Insert picture description here

Annotation method

  1. Line comment
    Insert picture description here
    only comment the current line
  2. Block comment comments on the
    Insert picture description here
    entire block of code
  3. Documentation comments
    Insert picture description here
    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:
Insert picture description here
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.

Guess you like

Origin blog.csdn.net/qq_40893595/article/details/108369384