[Super invincible and detailed Han Shunping's java notes] From entry to proficiency---Java development

Table of contents

1. What is compilation?

2. What is operation?

Java development

1.Description of requirements

2. Development steps

Edit

Here is a description of the code

3. Schematic diagram of operating principle

Edit

What should I do when there are Chinese characters in the file?

3. Java development precautions and details


1. What is compilation?

javac hello.java

1. With the java source file, compile it into a bytecode file that can be recognized by the JVM through the compiler

2. In the source file directory, compile the Hello.java file through the javac compilation tool

3. If the program has no errors and no prompts, a Hello.class file will appear in the current directory. This file is called a bytecode file and is also an executable java program.

2. What is operation?

java hello

1. Have an executable java program (Hello.class bytecode file)

2. Execute the bytecode file by running the tool java.exe. The essence is to load the .class into the jvm machine for execution.

Java development

1.Description of requirements

It is required to develop a Hello.java program that can output "Hello, Java!"

2. Development steps

  • Write java code into a file with the extension Hello.java
  • Compile the java file through the javac command to generate a .class file
  • Run the produced class file through the java command
public class Hello{
    public static void main(String[] args){
        System.out.println("Hello,Java");
    }
}
//这是对代码的相关说明
//1、public class Hello 表示Hello是一个类,是一个public公有的类
//2、Hello{ } 表示一个类的开始和结束
//3、public static void main(String[] args)表示一个主方法,即我们程序的入口
//4、main(){}表示方法的开始和结束
//5、System.out.println("Hello,Java");表示输出Hello,Java到屏幕
//6:;表示语句的结束

Here is a description of the code

1. public class Hello means that Hello is a class, a public class.
2. Hello{ } means the beginning and end of a class.
3. public static void main(String[] args) means a main method, which is the main method of our program. Entry
4. main(){} indicates the start and end of the method
5. System.out.println("Hello,Java"); indicates the output of Hello and Java to the screen
6:; indicates the end of the statement

3. Schematic diagram of operating principle

What should I do when there are Chinese characters in the file?

  • In the file - set file encoding - GBK
  • Need to resave

 Note: The modified Hello.java source file needs to be recompiled, generate a new class file, and then execute it to take effect.

3. Java development precautions and details

1.Java source files have a .java extension. The basic component of the source file is a class (there can be many classes) , such as the Hello class in this class

2. The execution entry point of the Java application is the main() method. It has a fixed way of writing:

public static void main(String[] args){...}

3.Java language is strictly case sensitive

4.Java methods are composed of statements one by one, and each statement ends with ";"

5. Braces appear in pairs

6. There can be at most one public in a source file. The number of other categories is not limited

7. If the source file contains a public class, the file name must be named after the class name

8. There can be at most one public class in a source file. There is no limit to the number of other classes. You can also write the main method in a non-public class, and then specify to run the non-public class, so that the entry method is the non-public main method.

public class hello{
	public static void main (String[] args){
		System.out.println("hello,java");
	}
}

class Dog {
	public static void main (String[] args){
		System.out.println("hello,小狗");
	}
}
class Monkey {
	public static void main(String[] args){
		System.out.println("hello,猴子");
	}
}

run

document

4. Java code specifications

1. Comments on classes and methods should be written in the javadoc method.

2. Non-Java Doc comments are usually for the maintainers of the code. They focus on telling readers why they are written this way, any modifications, what issues to pay attention to, etc.

3. Use the tab operation to achieve indentation. By default, the whole thing moves to the right. Sometimes, use shift+tab to move the whole thing to the left (a few more lines are needed)

4. Operator = is customary to add a space on both sides. For example: 2 + 4 * 5 + 345 - 89

5. The source file is encoded using utf-8

6. Line width should not exceed 80 characters

7. Code writing style and end-of-line style

 

Guess you like

Origin blog.csdn.net/qq_45206556/article/details/131639467