Hello World introduction for beginners in Java

Source: Internet
Author: User
Hello World introduction for beginners in Java

14:21:00/personal classification: Java

There are too many people asking helloworld questions, and they often start with "Ask the simplest question. In fact, I have come from this stage and said "hello". Is it really the simplest problem ?... // Think: Let's say "helloworld! "In Java...

First, assume that our platform is Windows + JDK (LinuxEnvironment ). This environment is quite common, basic, and entry-level. Confirm that JDK has been correctly installed. The next step is to carefully import a certain version.TutorialOn the helloworld source code, save the disk, and then compile, javac... the problem is:

* Error 1:

'Javac' is not an internal or external command, or a program or batch file that can be run.
(Javac: Command not found)

The cause is that the environment variable path is not set. In Win98. in bat, add Path = % PATH %; C:/jdk1.2/bin. in Win2000, choose Control Panel> system> advanced> environment variable> system variable... see? Double-click path and add C:/jdk1.2/bin to it. Of course, let's assume that JDK is installed in the C:/jdk1.2 directory (a little monk ?)... It seems that you have to restart the system to make it work... (// you know! // Tomato) Good, try again! Javac helloworld.

* Error 2:

Helloworld is an invalid option or argument.

Please give us some professionalism. The JAVA source program must be saved as a. Java file, and must be fully written during compilation. java.
OK, javac helloworld. Java (should this always happen ?)

* Error 3:

Helloworld. Java: 1: Public class helloworld must be defined in a file called
"Helloworld. Java ".
Public class helloworld {
^
This is because the name of your class is different from that of the file. (Who said it, it clearly shows that people have such () OK. To be precise, a Java source program can define multiple classes. However, only one class with the public attribute can be created and must be consistent with the file name. Also, the main method must be placed in this public class so that Java (run) can be used. In addition, the Java language is case-sensitive and must be noted for beginners. As in the above example, helloworld and helloworld are considered different, so... oh... okay, you have changed it... javac helloworld. java... (Sorry, why is there nothing ?) // Faint. This is the compilation passed! Check if there is another helloworld. Class? (Hehe .. according to the instructions in the book :) Java helloworld (!! I know this, not Java helloworld. Class yo)

* Error 4:

Exception in thread "Main" Java. Lang. noclassdeffounderror: helloworld

Well, this is the famous classpath problem. In fact, the class path is a concept in Java involved in the compilation process. Classpath is the class used to specify where to find it, which is so simple. Because our helloworld does not use other (non-java. lang Package) classes, this problem is not encountered during compilation. During running, you must specify where your class is. To solve this problem, run the following command:

Java-classpath. helloworld "." indicates the current directory. Of course, this is a little troublesome (it's too troublesome "!), We can set the default classpath in the environment variable. The method is as follows. Set classpath:
Classpath =.; C:/jdk1.2/lib/dt. jar; C:/jdk1.2/lib/tools. jar.
For future development. Java-classpath. helloworld (I will not learn Java again)

* Error 5:

Exception in thread "Main" Java. Lang. nosuchmethoderror: Main

(// Stick to it. Look at your code. The problem lies in the definition of the main method. Is it correct,
Is it written like this:

Public static void main (string ARGs []) {// do not make any difference in a word. Do not ask why...

Yes, including case sensitivity!

Java-classpath. helloworld !)
Hello world!
(Faint! Finally ...)

Welcome to the Java World! Therefore, the failure to run helloworld is really not a "simplest problem ".

Appendix: helloworld. Java

// Helloworld. Java
Public class helloworld
{
Public static void main (string ARGs [])
{
System. Out. println ("Hello world! ")
}
}

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.