JDK installation and configuration (02)

JDK installation and configuration

Before installing JDK, turn off all firewalls on your computer, otherwise dire consequences will occur.

In the middle of installing JDK, you will be asked whether to install JRE (Java runtime environment), choose to install.

In the process of using Java development, the two most used commands are: javac.exe java.exe, but these two commands themselves do not belong to the Windows system, so it is necessary to configure the directories where these two commands are located in the system environment. .
Program directory: D:\Java\jdk1.8.0_74\bin;
and then modify the content of the PATH attribute of the environment, and use ";" to separate it from other content. The colon is used under Linux.
Operation steps: [My Computer]->[Right-click Properties]->[Advanced]->[Environment Variables]-Edit Add D:\Java\jdk1.8.0_74\bin to the top
of all environment properties;

All command line methods must be restarted to read all environment variables.

try the first program

If you want to write a java program, the suffix of all program files must be *.java files. Create a new directory as follows:
d:\mydemo;

Example: Create a Hello.java file.
The content is:

public class Hello {
  public static void main(String argsp[]){
    System.out.println("Hello World!");
  }
}

When the program is written, execute, the steps are as follows:

  • Compile the source code file and form it into a *.class file: javac Hello.java, which will form a Hello.class file
  • Explain Java program: java Hello

However, the following issues need to be paid attention to for the above program:

  • Definition of program class: A class is the basic unit in java, and all Java programs exist in the form of classes. Class definitions come in two forms:
public class 类名称 {}:类名称必须与文件名保持一致。
class 类名称{}:文件名称可以与类名称不同,生成的字节码文件就是:“类名称.class”,
在一个*.java文件里面可以使用class定义多个类,并且编译之后会形成不同的*.class 文件。
对于初期学习可能会在一个*.java文件定义多个类,方便浏览。但是在真正的开发环境中,一个*.java文件中只允许定义一个类。

类名称:首字母必须大写

del *.class 删除class文件,所有的class文件都是

Main method: The main method is the starting point of everything, that is to say, all programs must be executed through the main method. The main method is defined as follows:

public class Hello {
  public static void main(String args[]){
    主方法中编写的代码才是你的整个程序
  }
}

In the future, we will make the class where the main method is located the main class, and half of the main class will be declared as public class.

Information output: It refers to the printing operation of information on the screen, and the information output has two syntaxes:

  • Newline after output: System.out.println(content)
  • Do not wrap after output: System.out.print(content)

Example: Watching Output Actions

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325727627&siteId=291194637