First, write the Java program
Write a Java program, output a line of text message: "Hello World", select Editor Eclipse, open and then write the program
1 Public class hello{23publicstaticvoid main (string[] args) { 4 System.out.println ("Hello World"); 5 }6 }
View Code
Line 1: Start declaring a class, the class name Hello,class is a java keyword, used to define the class, public is the access description
Line 3: A method that a Java application must contain, called an ingress method: The program must be run from here to execute, in the form of:
public static void Main (string[] args) or
static public void Main (string[] args)
In the above statement, only the name of the args and the string array can be modified.
Static indicates that the method can be loaded directly to run.
Void is a method return type, and each method must have a return type (in addition to the constructor method).
Main is the name of the method and is the method by which the program's entry is invoked.
String[] is a parameter of a method and must be of type string array.
Line 2, 4: blank line, used to increase the readability of the program.
Line 5:system.out.println ("Hello World");
is the output string, the string in double quotes is output in the console.
Line 6: "}" indicates the end of the method
Line 7: Indicates the end of the class
After writing, save the Hello.java file name to the specified directory.
Second, configure the environment and compile
Using the CMD and CD commands in the console to compile the file Hello.java that you just saved, you will generate a. class file that corresponds to the class name: Hello.class
You can output the text message "Hello World" by running the file hello.class you just generated using the Javac command in the console.
Note: When you run, you cannot add the file extension. class
class { public static void main (string[] args) { System.out.println ("Hello World"); } }
---restore content ends---
---restore content ends---
Beginner to write Java programs