This is a sophomore self-taught Java when the notes, the noon review of the impression of the note when the accident to see this article. When I saw the words written years ago, I remembered the mengmengdongdong of Java, and every night in the library I followed the sample code in the book, and I racked my brains for a Chinese semicolon, and I was excited to print the pattern on the command prompt. By now I still feel that a person who has never had programming experience to print on the screen Hello World
, he really felt that a new world said "Hello, I came."
Although it is now very simple and even foolish to look at the problems that have been encountered at the moment, I am still grateful to the original library for writing code. It is this little bit of simple stupid accumulation of today's programming ability, and now I can develop a website backstage, which in my opinion at that time is absolutely unbelievable.
Therefore, I also hope that the new contact with the programming of friends to say, if you want to learn programming, not ambitious, only need to start from a little bit, accumulated problems (if there is energy should also be written blog), adhere to write code, one day you will be grateful to the original insisted. Because most of the time the most important thing is not exactly what you did, but whether you did it, insisted on doing one thing, and worked for it, this is the method of success (narrow).
You don't have to consider package issues when compiling Java files with eclipse, but how do I run a Java file after adding a package from a command prompt?
Package test;
Import Test. B
public class A {
public static void main(String[] args) { B b=new B(); b.print(); }
}
Package test;
public class B {
void print () {
System.out.println ("ok!");
}
public static void Main (string[] args) {
}
}
I have two. java files A.java and B.java in the D:\workspace\test\src\test directory, so how do I compile these two files? At this point, the JAVAC statement is compiled with the command prompt A.java an error is displayed
We called the method in B in a, so just compiling a, a, is not going to be compiled. To resolve this issue you need to compile both A and B. And A and B are the same as the test package, so we find the directory where test D:\workspace\test\src, execute command java in cmd. \test*.java. At this point A and b two files were compiled at the same time.
Then use the Java command to execute a, and find that running directly with Java A will cause an error. Switching to the D:/workspace/test/src/test directory where A is located will still cause an error. Since our previous compilation was in the directory where the package was located, I executed the a file under test.
Execute Java test under the D:\WORKSPACE\TEST\SRC directory. A, run successfully.
How to compile a Java file containing a package from a command prompt