I write my first Java program flow:
1. Create a new text document: Right-click-----> select New-----> select text document from anywhere on your computer;
2, modify the document name and suffix name: "Right click" New Text Document------> select "Rename"-----> Rename "Sample01.java", this will pop up "warning box below", select "Yes", such as;
Note: If there is no pop-up warning box, it means that your modified file is not a Java file, but also a TXT file, just called "Sample01.java.txt" only, but the suffix ". txt" is hidden;
How do I get the file to show "suffix name" (take Windows7 for example)?
For:
- In the Computer window, locate and click the Organize button (typically in the upper-left corner)------> select folder and search options, such as:
- Popup "Folder Options" box, in the order of operations, find the "hide the extension of the file type" option, remove the hook, press "OK" to complete;
3. Open the "Sample01.java" file with "notepad" open, and enter the following:
1 Public class sample01{ 2public staticvoid main (string[] args) { 3 System.out.println ("Welcome to the Spreading blog"); 4 }5 }
Knowledge Point Analysis:
- The first line of code above: "Public class sample01{" means declaring a "class" (which will be mentioned later, remember first), and the class name is: SAMPLE01 (note: The class name is the same as the file name);
- The second line of code: "public static void Main (string[] args) {" Fixed notation that represents a Main method (method name: "Main"), which is the entry for the running of the program;
- The third line of code: "System.out.println (" Welcome to the spreading blog); " Indicates that when the program runs, the console output "Welcome to the spread of the blog," is an output statement;
- The four and five lines of code: "}" indicate the end of the main method (with the preceding {forming the closing parenthesis) and the end of the class;
4, then "Save" (Save shortcut: Ctrl + s) and exit the "edit window" (directly in the upper right corner of the red X), so that the first Java program is written;
Second, compile and run the first Java program
1. Know two instructions:
- Javac source file (with suffix) starts the Java compiler and compiles the source files;
- Java bytecode file (without suffix) launches the Java Virtual machine and interprets the running bytecode file;
2. Compile and run the Java program flow:
- Open a console (command line Prompt window) and switch to the path where the Java source files (files ending in. java) are located, such as:
- Enter "Javac Sample01.java" press ENTER to compile the source file and generate a byte-code file with the same file name,
- Enter "Java Sample01" (do not add suffix) press ENTER to start the Java Virtual machine and explain how to run the bytecode file, such as:
- This is my first Java program;
Section three: My first Java program