Lebyte Education is a full-stack education institution integrating online education and offline training. Lebyte is committed to developing high-end IT technology, cultivating high-end IT talents, and enabling more people to receive better education.

Today, we are going to write a Java program. Then take a look at how Java programs are executed and the problems and solutions encountered by Java novices.

The writing of the HelloWorld

① Create a new xxx.java file (the file extension is displayed)

② Write code, write in class units, write entry functions/methods

Public static void main(String[] args){system.out.println ("HelloWorld"); // End with a semicolon}}Copy the code

3. Run the javac command to compile the Java file.

④ Run the Java program and run the. Class file/bytecode file through the Java command

Run the following command:

Among them:

-classpath /-cp specifies the path.

If not specified, Java will look for the current directory, not the Java lang package.

If the path is specified, for example, -classpath /-cp. C: \ file name

The Java command looks for the file name in the current directory. If it cannot find the file name in the specified C directory, it looks for the file name in the Java lang package.

. Indicates the current path

; Separate paths

Remember: You need a space between the path and the file name

Application to explain

A: The most basic unit of A Java program is A class, so we need to define A class.

The class on behalf of the class

Format: class Class name

Example: class HelloWorld{}

B: When writing content in a class, enclose it in braces.

C:Java programs must have main methods in order to execute.

Public static void main(String[] args){}

D: What do you want to point to? Put curly braces around it as well.

E: Output statement: system.out.println (” output “);

Note: A class is compiled to correspond to a.class file. A source file can have multiple classes. If a public class exists, the file name must be the same as the public name. Therefore, there can be at most one public class in a source file.

Java program development and execution process

A: Write Java source program (.java) source file/source code

B: Compile. Class files (bytecode files) using javac command

C: Run.class files (bytecode files) through Java commands

Faqs and Solutions

1. The extension name is hidden

How to find: Tools – Folder Options – View – Remove the check box that hides the extension

2. We now generally have the same file name as the class name.

The class name (the name after class) in the.java file is compiled as the name of the.class file.

Note, however, that javac is followed by the file name + extension

The class names that follow Java do not have extensions.

3. The Java language is case-sensitive

4. Don’t spell the words wrong

5. See illegal characters: It must be Chinese.

We wrote a program that required all punctuation marks to be in English.

6. Matching of parentheses.

In general, parentheses come in pairs.

7. The main method cannot be found in class HelloWorld.

8. Forgetting to write a semicolon after a statement.

The article reprinted self – delight bytes