Re: Novice linux java coder needs help getting progs to run
boltar2...@yahoo.co.uk wrote:
"javac hello.java" -ie with the .java extension - is the only way that
Class names should begin with an upper-case letter.
works otherwise:
tantallon$ javac hello
error: Class names, 'hello', are only accepted if annotation processing is explicitly requested
1 error
So it works in the opposite way to the java runtime command line unless you
presumably specify some option.
The two commands have very different purposes; there isn't an
"opposite" way here. The purpose of the "javac" command is to
manipulate files; the purpose of the "java" command is to manipulate
classes.
So when you specify "javac Hello" you are telling the compiler to
compile a file named "hello". It doesn't make sense to specify
classes to the compiler because it's the compiler's job to convert
files into bytecode.
When you specify "java Hello" you are telling the JVM to execute the
standard 'main()' method in a class called 'Hello' in the default
package. It doesn't make sense to tell the runtime to execute a file
because its job is to run a method in a class. That the class
bytecode lives in a file is an implementation detail and not central
to the purpose.
There are no options to subvert the purposes of these utilities. The
point of the CLASSPATH envar and the command-line "-classpath" ("-cp")
options is to inform the "java" tool where to find classes.
It's a little tricky, and it gave me pause when I started out in Java
myself. I found it useful to remember that "javac" manipulates files
and "java" manipulates classes.
When you start using packages, which you should as soon as possible,
that means that "javac" looks at files in directories, e.g., "javac
package/Foo.java", and "java" looks at classes in packages, "java
package.Foo".
This is covered in the tutorials and other Java learning materials.
--
Lew