Nowadays, many friends come to learn Java together. Some friends ask how to use Java to output hello world? I will tell you in this article below. Friends who need to know more should read it. I hope it will be helpful to you.
Open the java runtime environment (the software used to write java programs), then enter the following statement, click compile and run, and then "Hello World," will be output.
public class Test{ //1 public static void main(String args[]){ //2 System.out.println("HelloWorld,"); //3 } }
This method is to directly call java's printfln function to complete the output operation.
1 is to create a "Test" class.
2 is the declaration statement of the main method.
3 is the output statement, output "HelloWold".
There are three commonly used output statements in java:
1.System.out.println(); is the most commonly used output statement , it will convert the content in brackets into a string and output it to the output window (console), and wrap the line. When the output is a basic data type, it will be automatically converted into a string. If the output is an object, it will be automatically converted into a string. Call the toString(); method of the object and output the return value to the console;
2.System.out.print(); is very similar to the first one, the difference is the previous one Line breaks will occur after output, but this command will not break lines after output;
3.System.out.printf(); This method continues the output method of C language, by formatting text and parameter list output.
The above is the detailed content of How to type java hello word. For more information, please follow other related articles on the PHP Chinese website!