Java Beginner: First Java program

Source: Internet
Author: User

Last time we briefly introduced Java, this time, we have a preliminary experience of Java programs, I think, even if you have not learned Java, you have heard the famous "Hello World", for this to greet the whole word, I always feel like an authentic otaku, Stay at home eating instant noodles shout out, so we change the next, uh ... , "Hello Baby".

If you haven't learned to program at all, I think you should think I'm babbling. In fact, I mean, let's write a simple Java program that lets the computer's output device (commonly known as a display) display the phrase "Hello baby". So, how do you do it?

First of all, we need to write Java programs, so what to write? Keyboard, mouse, computer, with operating system, Java-enabled computer. Here, I'm using windowns 7. Okay, then what? Then we create a text file, I set up in the D disk, give an English name, such as called Test.java, note that the text file default suffix is. txt, not. Java, we need to manually change to. java. :

Also, the name of the Windows file suffix is not displayed by default, so you may not be able to change, if you encounter this situation, please set your own, the suffix name is displayed, this is not discussed in this article.

And then what? Then we right-click Test.java, select Edit, and then write the following in the text:

Save exit and then go to command line mode: Press and hold Windows+r, and in the run, enter CMD:

Enter, get to the path where your Test.java is located (I am in the D packing directory), and then use Javac Test.java to compile your program, using Java Test to run your program:

You see, Hello Baby is out, isn't it? Yes, I came out here, but I think, a lot of beginners, certainly did not come out, not only did not come out, but also out a lot of errors, your computer does not know what you are doing, always prompt you wrong. Why is it?

Because there is no Java on your computer, or there is no Java running environment, or you are not setting up the Java environment. In fact, it is very reasonable, you do not have Java, you let the computer run Java program, this is not nonsense it? As if to say, I very much want to play PS3 game with my daughter, but only two points hinder: 1, I do not have PS3 game machine, 2, I have no daughter.

So, how do we set up the Java environment? Don't worry, we have to download Java before, to Google or Baidu, find keywords: java JDK, find and download, according to your system number of bits, if you are 64-bit, please download 64-bit, if you are 32-bit, please download 32-bit, I suggest players, ah no, Programmers in the future, download 32-bit, this is more compatible. If not, please change the keyword, for example, Java JDK 1.6 official download, what, I do not teach it. After the download is installed, it is recommended to install in the default directory, that is, the system disk, usually C drive, and then you think you installed Java, you put the above steps to try again .... Instantly want to smash computer: you such a stupid computer, I already install the Java for you, why do you donot work? Yes, you are installed, but you did not tell the computer, your Javac Test.java, Javac is what, and javac this command, not command line under the command, so the computer does not know Ah, do not know the words, it can not operate.

So how do you get the computer to know? We started to set up the Java environment, for this, we want to find out where the Java installation, if you listen to my words, the installation of Java is the default settings, then your Java should be in the C drive, find the bin folder inside the path, my:

Then copy this path, my following: C:\Program Files (x86) \java\jdk1.6.0_20\bin, you may be different from me oh. Then we go back to the desktop, right click on My Computer-Properties-〉 advanced system settings-〉 environment variable, in the system variable there, find path, click Edit:

Then, is there a variable value there? After the original, add a semicolon (in English mode), and then paste the path you just had in the bin, as shown in, I have pasted in. Then click OK and exit. And then we go back to the command line, just in case, let's see if the command line recognizes our Java command.

Well, if you hit javac under any path, all of the above results show that your Java environment is already recognized by the system. And then we can finally do the steps we started with this article and get the Hello baby under the command line.

Normally, you should show Hello Baby, but you should have a lot of questions, why? What did I just do? Why is it showing up? What are those settings for? What do you mean by the short Java file I wrote? Why use Javac Test.java? Why use Java Test? What is this?

How to say it .... , gee, I have something else to talk about next time, this time you remember, anyway, just do it. Also have to remember, learn a programming, not easy AH.

Java Beginner: First Java 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.