For beginners, often encountered a problem is to add a package statement after the source file can not compile successfully ;
There are generally two ways to deal with this situation, as shown in the figure;
Here we assume package org.xiazdong;
Hello.java
Package Org.xiazdong;
public class hello{public
static void Main (String args[]) {
System.out.println ("Hello world!!!");
}
The first scenario is to place the Hello.java source files directly in the home directory, and you need to use the
Javac-d. Hello.java
When this command is run, the Org/xiazdong directory is created automatically and the Hello.class is placed in Org\xiazdong;
Use in the home directory again
Java Org.xiazdong.Hello
can be run.
The second scenario is to place the Hello.java in the ${basedir}\org\xiazdong, which only needs to be used under the directory Org/xiazdong
Javac Hello.java
And then use it in the home directory.
Java Org.xiazdong.Hello
Run
The last compiled class file is in ${basedir}\org\xiazdong\hello.class