Write a Java program that runs the simplest--write Java programs using Notepad

Source: Internet
Author: User


First Java program--use Notepad to edit


After the last article of the Java environment to build a successful small partners can write their own Java program on their own computer yo~ has not set up the environment variables of the small partner please transfer to the previous essay to complete the building.



Connection Address: http://www.cnblogs.com/hysum/p/7084380.html



Now we can edit our first Java applet by using Notepad.


First step, use Notepad to edit program code


Notepad is written in the Java source code files, the code is what we usually learn Java code. The resulting file suffix is a. java file, which cannot be executed directly, and must be processed by subsequent compilation to become an executable program.


Step two, compile the source code file with the Javac command


Javac is a self-brought compiler, its role is to compile the source code files, compiling the popular word is to parse the source code files into a computer can read the process of the file (the computer is unable to directly read the high-level language such as Java).


The third step, compiled into a byte-code file


With the above steps, the source file has been successfully compiled into a bytecode file, which ends with a. Class. Bytecode files are independent of the operating system, which is the same for the last compiled bytecode files, both in Windows and Linux. (Note: Java's cross-platform performance is simply due to the existence of bytecode files)


Fourth step, using the interpreter to run the file


The final step is to run the bytecode file using the Java Command Launcher based on different platform systems, and eventually we will see the results on the screen.



The above steps can be used to clearly indicate:









Then we have a practical walkthrough (hey, Exaggerated):



First look at the first step, I create a new text file on the desktop, renamed to Myprogram.java. (Note that the file name is the same as the type, otherwise error!) )



Edit the contents of the file as follows, a very classic Hello World program:


 
public class myProgram
{ public static void main (String[] args){
System.out.println("Hello World!!");
}
}



After saving, the desktop will have a Myprogram.java source file.









We then complete the second step by using the Javac command to compile the source file.



Open cmd and switch to the root directory of the source code (I was built on the desktop, so my root directory is C:\Users\acer\Desktop)






After entering the root directory, compile the Myprogram.java file with the Javac command






No error message occurs after compilation, and the Myprogram.class file will be generated in the root directory









Note: If you execute the Myprogram.java file directly with the Java command, you will get an error



   



Finally we use the Java command to execute the Myprogram.class file






Note: If you add a suffix to the. Class later, you will not be able to find or fail to load the main class error, here we have to remember the Java command can not be followed by the file suffix!! Remember!!



Note: Casing is not a mistake (because Java is case-sensitive).



Because Javac is the operating system compiled source files, Java is the JVM running, running classes ~ not files, so you can not take the. class, directly use the class name.






To the above example of the supplement: if the file name or path has a space, directly with the file name or path will be error, the space is not recognized as: Is you sure.java in cmd is only recognized as Sure.java, because the Java class name does not allow spaces, so the way to name the file is wrong. The space problem in the path can be resolved by adding "" double quotes to the path, as shown in:



case where the file name has a space (error, class name does not allow spaces)






case where the path has a space (can be resolved by double quotation marks)






Good, such a simple Java program with Notepad can be directly edited and run, I heard that Daniel is directly programmed with Notepad, of course, this article is just a Notepad programming understanding, like me small white on the honest use of eclipse and other compilers.


















Write a Java program that runs the simplest--write Java programs using Notepad


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.