First, download the tool:
I suggest using Editplus + JDK for beginners. I think it is easier to use Editplus + JDK for beginners, such as JB, Eclipse, and JCreator, but it does not know how to configure environment variables for beginners, in this way, it is difficult to reach the point of knowing and knowing why.
You can download it at the following address:
Editplus (the latest version is v2.11): http://count.skycn.com/softdown.php? Id = 3641 & url = http://sc-http.skycn.net/down/epp211a_cn.exe JDK (the latest version is Java2sdk1_4_2): http://count.skycn.com/softdown.php? Id = 3116 & url = http://sc-http.skycn.net/down/j2sdk-1_4_2-windows-i586.exe (this is For Windows)
Then install JDK. I installed it under the c: JDK directory.
Then the CLASSPATH is set:
Just as the operating system uses PATH to search for executable programs, the Java Runtime Environment will traverse CLASSPATH to find classes. Even a simple program like HelloWorld, JVM will traverse every PATH defined by CLASSPATH, until the corresponding file is found.
I believe that if your system is not 2 K or XP, you should set the Path as follows:
My computer-> properties-> advanced-> Environment Variables
Then append the following Path to the environment variable: C: JDKbin;.; C: JDKlib
You can also configure C: JDKbin;.; C: JDKlibdt. jar; C: JDKlibtools. jar
★Remember: In the environment variables, remember not to be less. It indicates the current path. If there are fewer errors, you will say it!
Dt. jar is a class library about the runtime environment, and tools. jar is a class library about some tools.
If C: JDKbin is not configured, "javac" is not an internal or external command, or a program or batch file that can be run ." This error occurs.
Let's write an example program:
Open Editplus and create a new Java file. Follow the input below to keep it case sensitive:
Public class HelloWorld {
Public static void main (String [] args ){
System. out. println ("Hello, World! ");
}
}
Then save the file (ctrl + s) to HelloWorld. java. Java is case sensitive, so the case must be distinguished, that is, HelloWorld. java is not helloworld. java or other.
Run: Start-> Run-> cmd
Switch the directory to the current directory in the console:
Javac HelloWorld. java
Java HelloWorld
You will see the output Hello, World on the console!
Javac is a compilation command that compiles HelloWorld. java into HelloWorld. class.
Java is the command to explain. JVM will explain and execute HelloWorld. class.
At this time:
1. If Exception in thread "main" java. lang. NoClassDefFoundError: HelloWorld
That is, you didn't add that. (dot) to the environment variable)
2. If Exception in thread "main" java. lang. NoSuchMethodError: main
Or HelloWorld. java: 1: Public class helloworld must be defined in a file called
"HelloWorld. java ".
That is, you did not write this HelloWorld case-insensitive, or you did not save it as HelloWorld. java. This name must be the same as the public class name.
Let's talk about the problem of environment variables. Next, let's talk about how to compile and run the environment variables in Editplus, and choose Tools> parameter settings> Configure user Tools.
1. Add a tool (add an Application)
Menu text: Compile Java Program
Program: C: JDKbinjavac.exe
Parameter: File Name
Initial Directory: file directory
2. Add a tool (add an Application)
Menu text: Run Java Program
Program: C: JDKbinjava.exe
Parameter: File Name (excluding the extension)
Initial Directory: file directory
You can add a tool group name as needed, such as Debug Java Program.
Then, in the drop-down menu of Tools, you will see the Compile Java Program and Run Java Program options. Then you can use ctrl + 1 to Compile and ctrl + 2 to Run the Program.
The following describes the Servlet runtime environment:
To run Servlet, JSP/Servlet container is required. We recommend that you use Tomcat for beginners.
Tomcat (Latest Version 5.0): http://cvs.apache.org/builds/jakarta-tomcat-5/nightly/jakarta-tomcat-5-bin-20030725.zip
Decompress the package:
C: Tomcat
Then configure the environment variables. Add three system variables:
JAVA_HOME: C: JDK
TOMCAT_HOME: C: Tomcat
CLASSPATH: % JAVA_HOME % lib; % TOMCAT_HOME % lib
The environment variables of Tomcat are configured. Check whether Tomcat can run as follows:
In the console, go to the C: Tomcatbin directory and run startup. Then, a window appears, which means that the Server is running.
Enter http: // localhost: 8080 in the browser. If the welcome page appears, it means Tomcat is okay. Write your first Servlet as above.
Import java. io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class HelloWorld extends HttpServlet
{
Public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Response. setContentType ("text/html ");
PrintWriter out = response. getWriter ();
Out. println ("");
Out. println ("
Hello, World!
");
Out. println ("");
}
}
Then use javac HelloWorld. java to compile the file. If the file cannot be imported javax. servlet .*
Then we should copy the servlet. jar file in C: Tomcatcommonlib to C: JDKjrelibext and compile it again!
Then, in the Tomcat directory C: tomcatweb‑root, follow the following file structure:
ROOTindex.html
ROOTwelcom. jsp
ROOTWEB-INFlibMyServlet.jar (If your servlet. class is typed into a. jar file, put it under lib)
ROOTWEB-INFclassesHelloWorld.class (put the HelloWorld. class file generated above in it)
Then, enter http: // localhost: 8080/servlet/HelloWorld in the browser. The Error 404 -- Not Found is returned by the Server.
What's going on?
Servlet must use the web. xml file under the directory C: tomcatwebjavasrootweb-INF for registration. Use EP to open the web. xml file and add it to it:
HelloWorld
HelloWorld
HelloWorld
/Servlet/helloworld
Such a structure
HelloWorld
HelloWorld
Indicates the included servlet class. The following structure:
HelloWorld
/Servlet/HelloWorld
Specifies the URL mode to which HelloServlet maps.