Java source code needs to be compiled to execute, and execution requires the Java Runtime Environment, but the advantage is that as long as there is a running environment, you can execute on any platform, just compile once, so versatility is good.
The following is an example of a windos system.
Environment preparation
The Java environment is divided into two types, JDK (Java Development Kit) and JRE (Java Runtime Environment). The JRE is small and provides only the operating environment. If you do development requires JDK (official website download), after downloading the JDK installed.
Project creation and code writing
Create a new directory anywhere and save the project. Java has the concept of a package, the package is a bit similar to the directory, is to be large in the project, convenient multi-file management. Create a new subdirectory in test, create a new subdirectory first in test, and then create a new Java source program file, named First.java (note case), with Notepad, and enter the code:
1 Package Test.first; 2 3 Public class First {4 5 Public Static void Main (string[] args) {6 SYSTEM.OUT.PRINTLN ("Java test"); 7 }89 }
Once you have saved the file, you can test it.
Compiling and running
Open Start-run, enter CMD, open the command handler, and switch to the project directory you just created.
First compile the Java source program, enter:
"D:\Program Files\java\jdk1. 8. 0_91\bin\javac "Test\first\first.java
Bin\javac Front is the JDK's installation directory, adapted to your own installation directory.
If there is no hint, the compilation is successful, look at the project directory in the \test\first will be more than a first.class, this is compiled generated Java program.
The way to run this is to enter:
"D:\Program Files\java\jdk1. 8. 0_91\bin\java "Test.first.First
Here Test.first is the package name, the Java Runtime Environment will go to the corresponding directory to find the class file.
If normal, the console will output Java test.
Getting Started with Java