Paul Clapham wrote:
henry leu wrote:I'm running Windows command prompt and IntelliJ IDE all on the same Windows system. Why do they show different result?
Why not? You're probably the first person to care about that for the last 25 years. I'm not entirely joking... when Windows 95 was released, command-line programs became obsolete.
Jj Roberts wrote:It may be worth mentioning that javac does search the classpath for other classes which your class depends on:
javac docs wrote:The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file, but that provide information through inheritance.
When the compiler needs type information, it searches for a source file or class file that defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the CLASSPATH environment variable or by using the -classpath option
Say I have two classes
From the '.' directory I can compile them like this (it might be better to use -sourcepath instead of -cp for clarity):
To run I have to have all of the classes on the classpath:
Jj Roberts wrote:It doesn't seem to be explicitly stated in the docs but javac expects the file path for the source files you are compiling. As Knute noticed, putting the source file's directory on the classpath doesn't work. Campbell's second and third examples won't work because of that. The java command expects <package>.<mainclass> as the argument, though, so we have to use -cp to run it from another directory.
you would have to do
and if you want to use set CLASSPATH you would still have to pass javac the path of your .java file
henry leu wrote:When sub class inherits from super class, it automatically inherits super class's method.
I try to test it out the "this" functionality. I try to print out the super class object information from the sub class. Why doesn't "this" refer to SuperClass object, but it refers to SubClass object?