One
Two files in the same directory
T.java
Console.bat
T.java:
Package T;public class T{public static void Main (string[] args) {System.out.println ("Hello world!");}}
Console.bat:
@ECHO OFFSET Javahome=d:\java\jdk-8u91-1.8.0_91set path=%path%;%javahome%\bin;%javahome%\lib\dt.jar;%javahome%\ Bin\tools.jar;.; Cmd
(console configures the path here)
Open Console.bat, where you compile and run T.java, with the following results:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/83/3D/wKioL1dtdCDitREEAAAUHcD1LUU504.png "title=" QQ picture 20160625015518.png "alt=" Wkiol1dtdcditreeaaauhcd1luu504.png "/>
If Java finds Java class files by environment variables, then Java T is supposed to be operational (because the current directory is already contained in the environment variable, see CONSOLE.BAT)
Two
If you put the package T in T.java, you can run it by commenting it out. This is the same as we usually create a new Java file directly, code after the direct command line run is the same. This can be used classpath to explain how T.class was found. If you remove the current path, you will be prompted not to find the main class. Therefore, it can be inferred that the main class was found through a path in the paths. But how does this explain the first case?
Three
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/3D/wKioL1dtd1jiVbgCAAA8IONlhdQ287.png "title=" QQ picture 20160625020852.png "alt=" Wkiol1dtd1jivbgcaaa8ionlhdq287.png "/>
, the T1 folder also has a T1.java file, which differs from T0.java in that it has a package T1;
The two operations are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/3E/wKiom1dteFDyybT0AAA4bZlUsWc712.png "title=" QQ picture 20160625021318.png "alt=" Wkiom1dtefdyybt0aaa4bzluswc712.png "/>
For T0.java, one is t0.class==classpath/t0/t0; one is classpath+=t0,t0.class==classpath/t0. T1.java similar. According to the above, that is, if the class file after the Java command does not contain the parent directory, then the source file itself does not have a package statement, and vice versa. So, Java not only relies on the path path to find the class file, but it also through the two ways to check the package, so that the "Java file itself declaration of the packet and the actual package does not match" case.
Conclusion: Java X/x/x/aclass can run means aclass in the package x.x.x.
These are all inferences.
This article is from the "doerthous" blog, make sure to keep this source http://doerthous.blog.51cto.com/11762533/1792771
Java cannot find the main class to raise the inquiry