java - Accessing Classes from another class -
Considering that I am not using any IDE to create / run my Java code. But using Notepad and Command Prompt is compiling and running.
Can I safely assume: unless I keep my class files in the same folder, they always without informing the package Be able to "see" each other?
I came from another link with the same question title: But this is a different asking thing and the answer is in the context of the IDE, and use the CLASSPATH to use the IDE .
I intend to find out here which is JVM's behavior without an IDE
QUE: Can I safely assume that classes Can always "put each other" by putting them in the same folder?
There is something to eat here for your thoughts: -)
Suppose We have two versions of the same file
version 1
package mypack; Public Class Mayclass {public static zero major (string [] args) {System.out.println (1); }}
version 2
package mypack; Public class micro {public static zero main (string [] args) {System.out.println (2); }}
Compile version 2 like this
[leoks @ x ~] $ javac mypack / MyClass.java [leoks @ x ~] $ Java mypack .myClass 2
Then create a jar with version 1 and save it as "myjar.jar"
Try now
[leoks @ x ~] $ java -cp myjar.jar:. Mypack.MyClass 1 [leoks @ x ~] $ java -cp: Myjar.jar mypack.MyClass 2
As you can see, Classloader does not care. It only takes first class and ignores the other.
It is therefore not a matter of folders . This is about the package related to the JVM package, which can be inside the directory organization or within the jar.
Comments
Post a Comment