-- Start
Today, when IDE (integrated development environment) is widely used, many programmers forget the original Java development method. This article will give you a brief review.
1. Compile the helloworld class
In Start, Run, enter notepad to open notepad, enter the following content, save it under c: \ applications, and name it helloworld. Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("HelloWorld");
}
}
2. Compile and run helloworld
In start and run, Enter cmd to open the DOS command window and run the following commands in sequence:
1. Compile helloworld with a suffix. Why do we need to compile this step? Java is a cross-platform language. How does one implement cross-platform? Java introduces the concept of virtual machines to translate our programs into machine codes suitable for the target platform. We can see that the implementation of virtual machines on different platforms is different.
cd C:\Applications
javac HelloWorld.java
or javac C:\Applications\HelloWorld.java
2. Set the classpath environment variable. Why do we need to set the classpath environment variable? When we run Java helloworld, the Java command searches for helloworld in the path specified by classpath. class file, otherwise the virtual machine will tell us that the class cannot be found. maybe you think we are in helloworld. you can execute Java helloworld in the directory where the class is located,... (You know ).
set CLASSPATH=%%CLASSPATH%%;C:\Applications
3. Start the Java Virtual Machine to run helloworld. Note that there is no suffix.
java HelloWorld
4. You can specify the-classpath option instead of setting the classpath environment variable.
java -classpath C:\Applications HelloWorld
---For more information, see:Java
--Shengming: reprinted, please indicate the source
-- Last updated on 2012-05-17
-- Written by shangbo on 2012-04-20
-- End