The first Java program

Source: Internet
Author: User

Program code:

Analytical:

    • public static void Main (string[] args)
      • this main method is the execution entry address of a program. the Java program's bytecode file is called by the Java virtual machine, and the main () method is the JVM is called.
      • for The format of the main method, it is a fixed format, and no previous keyword can be less. But there are several variants as well:
      • Because the argument list is a character array, the character array is expressed in a different way, so it can be written as follows:
static public void Main (string[] args) public static void Main (String args[]) public static void Main (string[] name)
    • Attention

if In a Java program where a class is decorated with public, the Java file must have the same file name as the class name. The difference will be an error.

reason, compile error is because The class name of the class that the JVM requires to add public must always be the same as the source file name, because the elevated permissions, access to the external, if the file is consistent, so that the JVM to find the class file is more convenient, can improve the efficiency of the search, so do such a coercive measure (when not found, You can find the source file according to the file name)

    • the console uses commands to compile and run Java sources, such as operations:

  • Javaand theJavacexplanation of the order
    • javac is a command, is a java The source of the compilation command, through this command compiled to generate bytecode files, through this command called a set of underlying java javac Span style= "FONT-FAMILY:CALIBRI;" >java .java The calling compiler is primarily for java The source program checks the syntax.
    • Java is also a command, and its underlying program is the JVM. invoking the JVM through Java it will find the . class file at the specified location , and then load the bytecode file into memory, The explanation executes the bytecode file generated by the machine code, which is operated by the CPU .
  • A few common mistakes

First: Unable to find the *.java file

    • there could be *.java The file directory entry error
    • It is also possible that when the console is running, Java Drive letter Path error for source file
    • could be an error with the file name extension, window platform, the default file is txt , and the suffix name of the file is hidden, so you name the Test.java the file is actually a txt file Test.java.txt . The solution is to turn the window suffix display to the non-hidden state, and then change the file suffix to . Java .

The second one:the main method is spelled incorrectly.

      • General eyes are not good still can not see out.

The first Java program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.