A common problem for beginners isThe source file cannot be compiled successfully after the package statement is added.;
Generally, there are two ways to deal with this situation ,;
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 case is to directly place the source file hello. Java in the main directory, you need to use
Javac-D. Hello. Java
After running this command, the org/xiazdong directory is automatically created, and hello. Class is placed in org \ xiazdong;
Use it in the main directory
Java org. xiazdong. Hello
To run.
The second case is to put hello. Java in $ {basedir} \ org \ xiazdong, you only need to use it in the org/xiazdong directory
Javac hello. Java
Then use
Java org. xiazdong. Hello
Run;
All the compiled class files are in $ {Basedir} \ org \ xiazdong \ hello. Class