Get started with "Hello World" and helloworld
First, install jdk in Windows and input the following command in dos:
C: \ Users \ Administrator> java-version
Appears
Java version "1.6.0 _ 12"
Java (TM) SE Runtime Environment (build 1.6.0 _ 12-b04)
Java HotSpot (TM) Client VM (build 11.2-b01, mixed mode)
Indicates that the installation is successful;
Next, import the path of the program's execution file to the path environment variable,
Open dos again, go to *. java, and run the following command:
C: \ Users \ Administrator> cd E: \ Run script \ Java
C: \ Users \ Administrator> e:
E: \ Run the script \ Java>
Compile the source code *. java:
E: \ Run the script \ Java> javac Hello. java
After compilation, the *. class file is obtained and run:
E: \ Run the script \ Java> java Hello
Hello World!
Note: Java program statements
Public class Hello
{
Public static void main (String [] args)
{
System. out. println ("Hello World! ");
}
}
FAQs:
1. The. class suffix is included in the runtime.
If you try to use the following command E: \ Run the script \ Java> java Hello. class
The system will mistakenly believe that you are running a class file named class under the Hello package, and will go to the CLASSPATH of the system (usually including the current directory) to search for Hello. class. such a class does not exist, and it cannot exist because the class is a keyword and cannot be used as a class name.
2. Incorrect file name case
For systems like Windows, the Case sensitivity is not concerned during compilation. For example, when compiling Hello. java, you can also use:
E: \ Run the script \ Java> java hello. java
It can also be compiled, but the generated class file is still consistent with the source file: Hello. class.
Note the case sensitivity when running, for example, try to run the following command:
E: \ Run the script \ Java> java hello
An error similar to 1 will be reported:
E: \ Run the script \ Java> java hello
Exception in thread "main" java. lang. NoClassDefFoundError: hello (wrong name: He
Llo)