There are two simple programs, they are placed in the same directory: 1.// filename: test.javaimport show; public class test {public static void main (String [] args) {show sungo = new show (); sungo.myname ();}} 2 .// filename: show.javapublic class show {public void myname () {system.out.println ("My Name IS HelloWorld!");}} After Show.java, then compile TEST. Java appears under the wrong prompt -------- Javac ----------test.java: 3: '.' Expectedimport Show; ^ 1 Error
Output completion (time consumption 1 second) - Normal termination ----------------------------- Import show in Test.java files After the statement comment, it will be compiled, and Java Test.class, ---------- Java ---------- My name is helloworld!
Output completion (time consumption 0 seconds) - Normal termination -------------------------- Java compile time search classpath. Setting in ClassPath. ";" "The current directory. The editor automatically looks for classes contained in the current directory. If there is execution, it has joined the import show; it is more than one, before this, there is no problem, and there is no book to explain this problem. Through the above test, don't do it, don't do it, it is not good. The above problem is found in a so-called authority book, nor does it know if the author makes a test, or he uses another Planet JDK version. Another Package and Import simple instances create a new Dir folder, and put the show.java into the folder. //Filename: Test.show; public class test {public static void main (String [] args) {show sungo = new show (); sungo.myname ();}} // filename: show.javaPackage DIR ; // Added part of the public class show {public void myname () {system.out.println ("My Name is HelloWorld!");}} Execute result -------- Java --- ------- my name is helloworld!
Output completion (time consumption 0 seconds) - Normal termination --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------