How do I run a Java program written in notepad

  • 2020-04-01 02:14:06
  • OfStack

Today with notepad wrote a Java program, the test can run, now it is broken down into several steps, for everyone to understand:

1. Create a new notepad with the suffix   . Java  ; Then write a piece of Java code inside, as shown:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260919258.jpg ">

2. Drop the written Java file into the D disk, which is the class file given in the first step;

3. Open the DOS interface and start -> run -> cmd->. This is the command line mode.

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/201308260919259.jpg ">

4. After selecting disk D, type "javac filename. Java" at the command prompt. At this point you will notice that javac is not an internal file. Next comes the question of setting Java environment variables;

5. Download a JDK to perform the default installation. For example, the version of JDK I am running is: JDK -6u10-rc2-bin-b32-windows-i586-p-12_sep_2008.exe;

6. Configure the environment: right click on the properties of my computer, go in and click advanced to see the environment variables. Click in to set your system variables, as shown:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/2013082609192510.jpg ">

6-1. Variable name: classpath      Variable value :(.; C: \ Program Files \ Java \ jdk1.6.0 _10 \ lib) The ". "sign indicates the current path, and the". "sign indicates the current path. ";" If you already have a classpath environment variable on your system, you don't need to create a new one. Instead, just add "; ". Sign, add a new value after); As shown in the picture:

                              < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/2013082609192511.jpg ">

6-2. Variable name: path        Variable value: (C:\Program Files\Java\jdk1.6.0_10\bin;) And inside the brackets is "&";       (usually the system already has the PATH environment variable, so you simply add the PATH to the PATH variable; Since Windows searches for executable programs by the PATH specified by the PATH environment variable for external commands, the PATH where Java and javac reside should be added to the PATH in order to execute commands such as Java and javac. As shown in the picture:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/2013082609192512.jpg ">

7. Once the environment is set, we can go back to our fourth step. At the command prompt, type "javac filename.java." my file name is Java, so type javac java.java and press enter, waiting for compilation.

Appears as shown in the figure, indicating that the compilation passed:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/2013082609192513.jpg ">                         8. Then we can view our D disk with one more java.class file, as shown in the figure:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/2013082609192514.jpg ">

9. Next, type java  on the command line; File name (if mine is also Java, the naming may be a little bit of a problem), as shown in the figure, our program can run!

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201308/2013082609192515.jpg ">


Related articles: