1. The first HelloWorld

The first HelloWorld

public class HelloWorld{
	public static void main(String[] args){
		for(int i=0;i<args.length;i++){
		System.out.println(i+":"+args[i]);
		}
		System.out.println("HelloWorld!");
	}
}

public: permission modifier, indicating that this class is a public class.

class: class declaration.

HelloWorld: class name (the class name of the main class is the same as the file name).

void: The return value is empty.

static: Set the function to be static.

String[] args : Arguments at command line runtime.

how to run java program

Java generates a class file (bytecode file) by compiling

Compile: javac filename.java

(javac  HelloWorld.java)

run: java filename

(java  HelloWorld)


command line arguments

Add parameters at runtime.


 What's inside the .class file?

A class corresponds to a class file, and the class file stores the basic information of the current class.

View basic information about the class. javap -c classname

package declaration

package: declares a custom package.

Import: Import the package in the java library.


Guess you like

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