The Java program helloWorld

  • 2020-04-01 01:23:16
  • OfStack

Now that you have installed the Java JDK configured, write your first Java program, hello World, to output "hello World" on the console. First, let's use the primitive method of writing code in a text editor. In any one of the disk character, to D root directory as an example, in this directory to create a TXT text, named HelloWorld, and then the suffix changed to Java, namely helloworld.java.

    < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201301/2013010309425026.png ">

Then open the edit code as follows:


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

After editing, save, and then open the console with the DOS command into the D disk, type the compiler command "javac", by typing "javac" JDK began to compile the Java source file helloworld.java, and then generate. Class file.

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201301/2013010309425027.png ">

    < img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201301/2013010309425028.png ">

Finally, to output "HelloWorld," to compile the.class file, type "Java HelloWorld" into the console. As shown in figure:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201301/2013010309425029.png ">

This completes the first Java program, which is simple. In fact, in order to facilitate learning, we had better create a special file under a disk to write Java programs, for example, under the D disk to create a directory called "Java", and then write programs in this directory. It is best to start with writing programs in text rather than in an integrated development environment, such as eclipse, because this exercises the ability to write code specifications.


Related articles: