posted 20 years ago
There are two issues here: one is how the compiler resolves names, and the other is how classes are loaded.
First, class loading: generally, with the standard class loader the first class that is found is the one that is loaded. If several instances of class foo.bar.MyClass appear on the classpath, then the one that appears earliest will be loaded first.
Note, however, that the java.* classes aren't loaded by the normal application class loader; they're loaded by the boot class loader which has a different class path, set by using the -Xbootclasspath option. If you defined your own java.awt.Button, it would not be used unless you modified the boot class path to point to it. If you did this, however, then yes, you can replace system classes.
The other issue is compilation. Javac doesn't care about boot class loaders or such. It simply compiles what you give it. You do have to be careful in that if you import like-named classes from two different packages and then use one, the compiler will complain that it doesn't know which class to use. This is generally not too hard to sort out by modifying your import statements and/or using fully qualified class names.