Java entry Raiders Hello World

xiaoxiao2021-03-06  73

Ask the people who have a HelloWorld issue is too much, and often start with "ask a simple question". In fact, I will think that I am also coming from this stage, saying "Hello", is it a simplest question? ... // Think is good, the words retired, let's say "HelloWorld!" in java ...

First of all, we have to assume that our platform is Windows JDK (the Linux environment is almost almost). This environment is quite common, foundation, and entry. Determine that JDK has been installed correctly, the next step is to be carefully knocked into the HelloWorld source code on a tutorial, store, then compile, Javac ... The problem is coming:

* Error 1:

'Javac' is not internal or external commands, nor is it runable or batch files.

(Javac: Command Not Found)

The reason is that no environment variable path is set. Add Path =% Path% under AutoExce.bat; C: /JDK1.2/bin, then Under Control Panel -> System -> Advanced -> Environment Variables -> System Variables ... See? Double click on Path, add C: /JDK1.2/bin in the back. Of course, we assume that JDK is installed in a c: /jdk1.2 directory (a little Tang Yan?) ... It seems to restart the system to work ... (// Know! // Tomato)

Ok, try again! Javac HelloWorld

* Error 2:

HelloWorld Is An Invalid Option OR Argument.

Please, give a professional spirit, Java's source program is necessary to store .java file, and write all. Java.

OK, Javac HelloWorld.java (this time should I become?)

* Error 3:

HelloWorld.java: 1: Public Class HelloWorld Must Be Defined in a File Called

"HelloWorld.java".

Public class helloworld {

^

This problem is because your name is inconsistent with the name of the file. (Who said, clearly seeing that people have such a writable) OK, accurately, can define multiple classes in a Java source program, but the classes with public attributes can have one, and they are related to the file name Consistent. Also, the main method must be placed in this public class, so that Java can be enabled. Another point is that the Java language is strictly sized, and beginners should pay attention. Like the above case, helloWorld and HelloWorld think are different, so ...

Oh ... ok, change it, 嘻嘻 ... javac helloworld.java

... (咦, what is there?) // Faint This is compiled! See if you have a HelloWorld.class?

(HEHE .. Take the book :) Java HelloWorld (!! I know, not java helloworld.class

Yo)

* Error 4:

Exception in thread "main" java.lang.noclassdefounderror: helloWorld huh, this is the famous classpath problem. In fact, class paths are the concepts in Java involved in the compilation process. ClassPath is to specify where to find the class, it is as simple as it is. Since our HelloWorld is not used in other (non-java.lang package) classes, there is no encounter when compiling. When running, you have to indicate where your class is. Workaround, you can run with the following command:

Java-ClassPath. HelloWorld

"." Represents the current directory. Of course, this is a bit trouble (it is "too much trouble"!), We can set the default classpath in the environment variable. Methods are set by the above settings. Set ClassPath to:

ClassPath = .; c: /jdk1.2/lib/dt.jar; C: /jdk1.2/lib/tools.jar The two suggestions behind will also be used in the future.

Java-ClassPath. HelloWorld (I don't want to learn Java again.)

* Error 5:

Exception in thread "main" java.lang.nosuchmethoderror: main

(// 咣) Don't, stick to it. Look at your code, the problem is in the definition of the main method, is it written to the place, is it written?

Public static void main (string args []) {// one word should not be poor, don't ask why ...

Yes, including case yours!

Java-ClassPath. HelloWorld (Listen to the heavens!)

Hello World!

(Faint! Finally ...)

Welcome to the Java world! Therefore, it is not a "simplest problem" that cannot be running helloworld is really a "simplest problem".

Attached: HelloWorld.java

// HelloWorld.java

Public class helloworld {

Public static void main (string args []) {

System.out.println ("Hello World!");

}

}

转载请注明原文地址:https://www.9cbs.com/read-120558.html

New Post(0)