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
package declarationJava 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: declares a custom package.
Import: Import the package in the java library.