|
Hi Sudha, <snip> The code is similar to Browser() called BrowseControl() and I removed all the package declarations & jar to call from command line (I still don't understand why it would find the class from jar when the classpath refers to jar). I get browser not found or cannot be opened error now. </snip> I think we may need to move this thread over to the JAVA400 list, as we've gone way off-topic. But, before we go... Understanding paths, classpaths, and how classes are located seems to cause more confusion than anything else java-related. It must be a case of; "Once you get classpaths, then the rest of java is a breeze!". Probably akin to; "You don't understand unix until you understand the find command!". Anyway, here's a very basic overview... 1) To load a class you must specify it's location with a fully qualified path - that is, the path must start from the root directory. When you create a class in the default package (no package declaration at the top of your source) you MUST have the directory in which the class is located placed within your classpath. This is the only way the class can be located. Now, to ensure you don't have two classes from two vendors with the same name, the package declaration was created. This allows the vandors to "qualify" their class with something akin to a namespace. To ensure the two vendors do not accidentally use the same package name, convention states that you use your domain name (reversed) at the beginning of your package name. As domain names MUST be unique, the packages are unique. For example, if you worked on a utilily package within your MIS department - and you work for a company with the domain name http://ReallyBigCompany.com then you would create a package with a name similar to com.reallybigcompany.mis.util. This is guaranteed unique! The thing to note is that, to include a class within the package you must do two things: You must include the package statement in the source and you must also place the class within a directory tree that maps to the package name. You then set your classpath to point to the directory that contains your "com" directory. So, if you have a class within the directory C:\myclasses\com\reallybigcompany\mis\util you would set your classpath to C:\myclasses. The package declaration will implicitly declare the rest of the file path. To make life easier to distribute packages you can "wrap" the constituent classes up together in a java archive file (jar file). This file will contain your package within the "com\reallybigcompany\mis\util" directory tree. They are zipped up just like a standard zip file. All you need to do to access these classes is to set your classpath to point to the jar file. The java runtime will navigate through the jar file, locate the class, unzip and load it. This is part of java support - just like java, javac, javadoc. I believe it's part of the SDK definition. Finally, when you declare a java member (method or variable) without any access modifier (public, private, protected) then you are implicitly declaring it to be package protected. This means that only other classes within the same package can access them. By removing all of the package information from your BrowseControl class you may run into some problems - as your class no longer has package access to some of the package class members. Cheers Larry Ducie
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.