Java getting started tutorial series-the first program "hello, world"

Source: Internet
Author: User

Original Java getting started tutorial series-the first program "hello, world"

Posted on May 25, 2012 by Johnny

"Hello, World" means to output "Hello, World!" on the computer screen !" ("World, hello !") The computer program of this line of string. In general, this is the most basic and simple program in every computer programming language, and is usually the first program written by beginners. It can also be used to determine whether the language's compiler, program development environment, and runtime environment has been installed properly.

Following this tradition, the first Java program is "hello, world ". That is, to write a Java program, when the program runs, it will output a piece of text-"hello, word" in the command line ".

In the previous lecture, We have installed the Java Development Environment. Now we can directly access the d: \ deve \ eclipsedirectory and double-click eclipse.exe to start the eclipsedevelopment environment (of course, you can also create a desktop shortcut for the eclipse.exe program for future use ). First, you should see the Eclipse startup surface.

Next, Eclipse will prompt you to select the workpace directory (for what is workspace, I will not explain it here). In our entire tutorial, we will use the same workspace, therefore, you only need to set the workspace directory to d: \ projects \ java_basic in the same way. Remember to check "Use this as the default and do not ask again ", in this way, the next time you start Eclipse, you will not be prompted.

 

 

Click "OK" to display the Eclipse welcome window (this window is only displayed once). You can directly select to enter the workspace.

 

After entering the workspace, you will see that the entire window is divided into basic parts, such

As a beginner, you do not need to memorize the names and functions of each functional area, because you will naturally become familiar with it when you use it more. Now you only need to know that this series of tutorials mainly uses three areas:

1. code editing area: All code writing is completed here, and it will be the most used area.

2. Menu Bar: Use the corresponding menu options to complete the operation. In fact, you often use two or three menus throughout the tutorial.

3. Package browsing area: here we organize the source code of our program.

Next, we start formal programming. First, we select the "File" menu and then select the "New" menu item, then select the "Java Project" option (in the future, I will abbreviated it as File-> New-> Java Project. You will gradually get used to this method)

After "Java Project" is selected, Eclipse will open a pop-up window,

Enter the Project Name in Project Name. Here is "HelloWord ". Project is the basic unit for organizing Java programs in Eclipse. Now you don't need to pay too much attention to this concept. You only need to know that in Eclipse, all the code you write must be put in the Project to run. Click "Finish.

Next, you can see the new project in the package browsing area,

 

Click the project and select File> New> Class from the menu. You will see the following pop-up window.

Enter "com. golearning. training. java" in "Package" and "HelloWorld" in "Name" (Note that there cannot be spaces between the two words ). Click "Finish. You will see

As shown in: There is a basic project structure in the package browsing area. The source code to be written is placed under the src node (another statement is the src directory ), then we enter the package name, which is the HelloWorld class we created in the package. The code editor has automatically opened the HelloWorld class. You can directly edit the program.

 

Next, enter lines 5-7 in the following code in the code area. (beginners must not be lazy. instead of copying data from the webpage)

 

 
 
  1. package com.golearning.training.java.basic;
  2.  
  3. public class HelloWorld {
  4.  
  5. public static void main(String args[]) {
  6. System.out.println("hello, world");
  7. }
  8. }

 

The Code area after editing should be as shown in (remember to press Ctrl + S to Save after editing, or select File> Save to Save the menu)

Pay attention to the section indicated by the red arrow in the figure to see if you can find some contact information? (Summary and thinking after class)

Well, our programming is over. Next we will run this simplest program. Select "Run-> Run as-> Java Application" from the menu ",

Then you will see the window as shown in Figure

You notice that there is another view named "Console" in the tool view, which prints "hello, world", which is the output of the program we just wrote. (In this course, all program running results can be viewed from the Console view ).

 

Well, we have finished writing the first program. You may think that we haven't talked about any Java-related knowledge. That's right, I haven't talked about any Java language knowledge yet, I think that for beginners, the theory is not the first priority. You must first learn basic operations (based on Huludao). This capability is very important for beginners and must not be lazy. As for the knowledge of the Java language, I will talk about it in the next section, with the help of the Hello World Program.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.