I am very new to JAVA. I have written simple program (in Linux -VIM editor), compiled and executed it, everything is fine.
Now,I have moved that file to a different directory and am trying to compile(javac Myfile.java) it, but it throws an error message as javac-not found.
Can somebody explain what is the problem?
Your original question was not totally clear (since it did not contain the complete error message).
From your comment:
So, javac did not find your file example java.
Normally, you should not have to set the CLASSPATH (use
export CLASSPATH=in bash), and javac would search the source in the current directory. Is yourExample1.javain the current directory? (Typelsand look at the output.)If not, you should give the path to this file to javac as a parameter … but it really is better so simply move to the right directory with
cd.If you are using packages, position your shell to the directory on top of the package directory hierarchy, and call the compiler with the relative filename from there.
Edit, since I see the next questions coming:
-dparameter (or the current directory, if not given), by their package structure, so make sure you search them there later (when invoking the program).If the compiler needs other classes to compiler the files indicated in the command line, it searches class files in the classpath (given by the
-classpathor-cpoption, or by theCLASSPATHenvironment variable, or the current directory) and source files in the sourcepath (given by the-sourcepathoption or the classpath if no sourcepath is set). If for a needed both exist and the source file is newer, it is recompiled too. (They are searched according to the package-structure, too.)So in this case you should make sure to pass the
-sourcepathoption so the compiler can find your other source files.