Description
This document is a Java entry learning note. All examples of this document have been edited successfully under Window XP, that is, the default operating system is Window XP, and the JDK has been successfully installed. If there is something wrong, please be pointed out (email: 828033@tzenet.com) and make progress together.
This document does not introduce the basic idea of object-oriented, only records content related to Java.
2. Hello World
Write a Hello World as a Getting Started by Java. Open the text editor, enter the following code:
Class helloworld {
Public static void main (string args []) {
System.out.println ("Hello World!");
}
}
The program describes the following:
(1) Class name HelloWorld, press Java conventions, the first letter of the Java class name is capitalized (of course, lowercase programs will run normally);
(2) This class has an inlet method (function) main, which is called by Java Virtual Machine, Note that the definition of this method should be modified as PUBLIC Static Void, indicating that the class can be executed after editing;
(3) This class is not a normal class because it has a method (ie method) as a method of public static as a modifier (ie method), indicating that the class can call this class by hellowworld.main without instantification. MAIN method Of course, the MAIN method is usually called by Java virtual machine. The following is an example of another class call HelloWorld class method. MAIN:
Class HelloWorldCallee
{
Public static void main (string args [])
{
HelloWorld.main (ARGS);
}
}
Note In this example, the MAIN calls in the HelloWorld class use the class name. Method name (list) This method is called, that is, you don't need to instantiate the HelloWorld class first.
Then save the HelloWorld, saved file named helloworld.java, note that the file must be the same as the category, the file extension is Java.
Set the directory where helloWorld.java is located as the current directory in the command line, and enter the following command:
Javac HelloWorld.java
Use
Javac
Compile
HelloWorld.java
Program, if editing success will be generated
HelloWorld.class
File, you can use it for this file
Java HelloWorld
To do it, if the correct execution should be output in the screen
"Hello World!".