A. To edit a Java file using Notepad:
1. Open Notepad, rename filename, File extension ". java". (Required for the system to recognize Java files)
2. Write a simple Java code:
public class HelloWorld{
public static void main(String[] args){
System.out.println("HelloWorld");
}
}
also: The Notepad file name should be the same as the class name "HelloWorld" after class, otherwise it will not compile.
3. Open command prompt, Windows key +r key, enter cmd, open command prompt
Enter the Javac class name (file name). Java " Note: There is a space between the Javac and the class name. Java
After successful operation, the system compiles automatically and generates a file with a. class extension in the current file sibling, which is the resulting file after compilation.
4. Enter "Java class name", also Java has a space after the last System.out.println ("HelloWorld"); HelloWorld output in
Results after the run is complete:
Two. Java Program Structure
1. Writing a procedural framework
Public class helloworld{}
HelloWorld is the name of the class, which is exactly the same as the name of the program file, with public (common) and Class (class) two modifiers before the name,
Their order can not be changed, the middle of the space is separated. The class name is followed by a pair of curly braces, and all code that belongs to the class is placed in "{" and "}".
2. Framework for writing the main () method
Public static void Main (string[] args) {}
The program requires a fixed position to begin execution, which in the program is called "Portal". The main () method is the Java application Portal, which is the starting point for Java applications.
Without the main () method, the computer does not know where to start executing the program.
3. Writing code
System.out.println ("HelloWorld");
The purpose of this line of code is to output to the console output "HelloWorld". Print means "printing," and Ln can be seen as a line abbreviation, and println can be interpreted as printing a line.
In addition, the following statements can also be printed out. System.out.print ("HelloWorld");
three. Notes for Java programs
1. Single-line Comment: If you have less descriptive text, you can use a single line of comments in one line. A single-line comment usually begins with "//" and the text after "//" in each line is considered a comment.
A single-line comment is typically used between lines of code, or after a line of code.
The diagram is a single line comment
2. Multiline Comment: The multiline comment starts with "/*" and ends with "*/", and the contents between "/*" and "/*" are considered as comments. Multiple lines of comment are available when you want to describe more text and need to occupy multiple rows
The graph is a multiline comment
Java Basics-The first Notepad code and Java annotations