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: lmj0221@163.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
1. 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 Press the conventions to 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 is as follows:
(1) Class name HelloWorld, press Java practice, the first letter of the Java's class name is capitalized (of course, lowercase programs will run normally); (2) This class has an inlet method (function) main, this The function is called by the Java virtual machine. Note that the definition of this method should be modified as a 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 call in the HelloWorld class directly uses the class name. Method name Call, 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
That is, use Javac to compile the HelloWorld.Java program. If the editor will generate a helloworld.class file, you can use Java HelloWorld to execute it correctly, if you correctly output "Hello World!" In the screen.