Java Quick Start Notes-01 HelloWorld analyzes the first java program

1. Hello World!

  • Write source code
    Hello.java:
public class Hello 
{
    
    
    public static void main(String[] args) 
    {
    
    
        System.out.println("Hello, world!");
    }
}

Note that the name of the class here must be consistent with the file name.

  • Compiling
    the java source code needs to be compiled into a .class bytecode file before it can run on the java virtual machine.
    Compile with the javac compiler:
javac Hello.java
  • Execution
    The .class file generated after compilation can be executed using the java command:
    just pass the class name during execution Hello, and the virtual machine will automatically search for the corresponding class file and execute it.
java Hello

insert image description here
As can be seen from the above process, the java program needs to be compiled -> execute two steps, compared with the four steps of preprocessing, compiling, assembling and linking of C/C++ , it is still relatively small.

2. Analysis & Summary

Although the Helloworld program is simple, it embodies the most basic elements that a programming language needs to have. Similar to the smallest system of an embedded single-chip microcomputer, Helloworld embodies the minimum conditions for system work.

  1. Java is an object-oriented language, and the basic unit of a program is a class
  2. A Java source code can only define one class of public type, and the class name and file name must be exactly the same;
  3. Use javac to compile .java source code into .class bytecode;
  4. Use java to run a compiled Java program, the parameter is the class name;
  5. Java stipulates that Java programs are always executed from the main method, similar to C/C++ from the main function;

Guess you like

Origin blog.csdn.net/qq_41790078/article/details/113077920