The "Package" class

Hi all,
Why the java.lang.Package class is not declared final?
Thanx,
Adrian.

I will give you an example:
During two weeks I'm trying to understand the
class-loader mechanism.
I read every possible article I could found - and
still I find that it
is a mysterious design. That's because the Java
platform (as Microsoft's platform) is an evolving
platform, and today's solutions come to repair
yesterday's mistakes.
Yet, another example is AWT/Swing.Maybe you don't understand the meaning of 'bloated' because being "mysterious" has nothing to do with being bloated. The class-loader mechanism is not mysterious to me and I don't see why Package not being final makes it mysterious. It's impossible to extend Package so making it final wouldn't have any functional effect, though, for completeness it would make sense to mark it final.

Similar Messages

  • Eclipse - how to share a package/class with 3 diff projects

    Hi all,
    I have 3 projects that are customized diffrently but one package is same for everyone (sharedClass). The problem is when I add/delete/update the SharedClass I have to do it 3 times (for each project)
    Question: How can I share the package/Class with the 3 projects? I mean, I want to change it once and the effect will take place to all 3 PROJECTS.
    Thanks
    Ppr

    This is an Eclipse question and doesn't really belong here, but:
    I would put the shared package into its own project. Then for the three projects (after removing the shared package) I would use the Project menu and choose properties. Choose Java Build Path snd select Projects. Choose Add and select the project containing the shared package.

  • How to access a class file outside the package?

    created a two java files Counter.java and TestCounter.java as shown below:
    public class Counter
         public void print()
              System.out.println("counter");
    package foo;
    public class TestCounter
         public static void main(String args[])
              Counter c = new Counter();
              c.print();
    Both these files are stored under "D:\Test". I first compiled Counter.java and got Counter.class which resides in folder "D:\Test"
    when i compile TestCounter.java i got the following error message:
    D:\Test>javac -classpath "d:\Test" -d "d:\Test" TestCounter.java
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    2 errors
    what could be the problem. Is it possible to access a class file outside the package?

    ya that's fine..if we have two java files where both resides in the same package works fine or two java files which donot have a package statement also works fine. But my doubt is, i have a Counter.class which does not reside in a package and i have a TestCounter.class which resides in a package "foo", in such a scenario, how do i tell to the compiler that "Counter.class resides in such a path, please look at that and give me TestCounter.class". i cannot use import statement to import Counter.class in TestCounter.java because i donot have a package for Counter.java.

  • How to import a class not in the package from a package

    how to import a class not in the package from a package?

    http://java.sun.com/docs/books/tutorial/java/interpack/usepkgs.html

  • Getting 'binary name' of the package of  a given class

    I needed this for a kind of dynamic class loader, where the binary name of the package of an object was required. What made it more complex is that the classpath of the object is not the local filesystem path, where the java executable was invoked (such as 'bin' in an eclipse project)
    I searched the forum, and didn't find a solution that addresses all of these problems. Finally I came up with my own solution, and I'll share it with you (also because there might be some bright minds who can tell me it can be done much simpler (which I hope))
    @SuppressWarnings("null")
    public static String getPathFromClass(Class< ? > rootClass) throws FileNotFoundException
         String rootPath;
              // These are all the possible directories where the package root
              // exists (relative to where the java executable might be invoked).
              String systemPaths[] = {"bin", "."};
              File root = null;
              for (String systemPath : systemPaths)
                   root = new File(systemPath);
                   if (root.exists())
                        break;
              if (!root.exists() || !root.isDirectory())
                   throw new FileNotFoundException("No package root found");
              rootPath = root.getAbsolutePath();
         String localPath;
         try
              localPath = new File(rootClass.getResource(".").toURI()).getPath();
         catch (URISyntaxException e)
              // Should never happen; Hack to prevent unjust error.
              localPath = "";
         if (!localPath.startsWith(rootPath))
              // What's going on ??
              throw new FileNotFoundException("Class' local path not inside package root");
         return localPath.substring(rootPath.length() + 1).replace(File.separatorChar, '.');
    }Example:
    main class is in c:\projects\test\bin\test\mj\foo\Main.class (package declaration sais "test.mj.foo".)
    java.exe is executed from c:\projects\test\
    calling this method with an instance of the Main class returns: "test.mj.foo".

    As far as I can tell it just returns the package root (such as "c:\projects\test\bin"), but because of that, it does greatly simplify the first part of my function. Thanks.
    String rootPath = new File(rootClass.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath();
    String localPath;
    ...A binary name (as mentioned in the Java Language Specification) is a representation of a fully qualified java class, such as "java.lang.String". A "binary name of a package" as I mentioned is just my way of meaning anything like "java.lang".

  • Where to place the class file of the java bean when using the packager

    I am using the activex bridge in j2se 1.5.0_06
    now i have created the jar file for my bean but where do i place the class file?
    i.e the bean..if i keep it in jdk\bin the packager gives me an error..i created a folder in my public jre jre\axbridge\bin and placed the class file there too but even this didnt work
    Kindly tell me what is the fully qualified package bean name if i have placed all my files under jdk\bin..

    D:\Java\jdk1.5.0_06\bin>packager -reg d:\java\jdk1.5.0_06\bin\PersonBean.jar Per
    son
    Processing D:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\\Person.idl
    Person.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\oaidl.idl
    oaidl.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\objidl.idl
    objidl.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\unknwn.idl
    unknwn.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\wtypes.idl
    wtypes.idl
    Registration failed:
    The packaged JavaBean is not located under the directory <jre_home>\axbridge\bin
    this is the error i get

  • To access a package, the calling class must reside in the root/parent direc

    My goal was to be able to access my package from anywhere within the
    high level root folder (d:\zJava). But it seems the invoking class MUST
    RESIDE IN THE TOP LEVEL PARENT DIRECTORY of the package. Was Java
    designed to behave this way?
    D:\zJava\zsamples\com\zswingpackage1>     <-- packages successfully compiled here
         swing_optgrp_eg1.{class/java}
              package com.zswingpackage1;
              public class swing_optgrp_eg1 extends JFrame implements ItemListener {
    D:\zJava\zsamples\com> <-- classes residing here could NOT successfully                    access the package 'com.zswingpackage1'. The third                    level subfolder is 'com'.
         package_test4.java
              /* Following import stmt. causing RUN-TIME error "Exception in thread     "main" java.lang.NoClassDefFoundError: com/zswingpackage1/swing_optgrp_eg1". */
              import com.zswingpackage1;
         Package_Test4.class          
         /* Unsuccessful remedies:
         i) D:\zJava\zsamples\com>java Package_Test4
                   -classpath .;d:\zJava\zsamples\com\zswingpackage1
                   -classpath .;d:\zJava\zsamples\com
                   -classpath .;d:\zJava\zsamples (also used in compile)
                   -classpath .;d:\zJava
         ii) ran from the root/parent directory of the package d:\zJava\zsamples),with and without classpath i.e.
              D:\zJava\zsamples>java com\Package_Test4 [-classpath .;d:\zJava\zsamples]
         iii) ran from the top level directory (d:\zJava), with and without classpath i.e.
              D:\zJava>java zsamples\com\Package_Test4 [-classpath .;d:\zJava\zsamples]
         Possible causes:
              - maybe the above behaviours are by design i.e. the calling class/program CANNOT be stored within the package hierarchy?
    D:\zJava\zsamples\net> <-- classes residing here could NOT successfully access the package 'com.zswingpackage1'. The third level subfolder is 'net'.
         package-test6.java
              /* Following import stmt. causing RUN-TIME error "Exception in thread "main" java.lang.NoClassDefFoundError: com/zswingpackage1/swing_optgrp_eg1". */
              import com.zswingpackage1;
         Package_Test6.class
         /* Unsuccessful remedies:
         i) D:\zJava\zsamples\net>java Package_Test6
                   -classpath .;d:\zJava\zsamples\com\zswingpackage1
                   -classpath .;d:\zJava\zsamples\com
                   -classpath .;d:\zJava\zsamples (also used in compile)
                   -classpath .;d:\zJava
         ii) ran from the root/parent directory of the package (d:\zJava\zsamples), with and without classpath i.e.
              D:\zJava\zsamples>java net\Package_Test6 [-classpath .;d:\zJava\zsamples]
         iii) ran from the top level directory (d:\zJava), with and without classpath i.e.
              D:\zJava>java zsamples\net\Package_Test6 [-classpath .;d:\zJava\zsamples]
         Possible causes:
              - maybe the above behaviours are by design i.e. the calling class/program MUST be stored in the parent folder of the package hierarchy?
    **D:\zJava\zsamples>     <-- classes residing here SUCCESSFULLY accessed package 'com.zswingpackage1'. NO -classpath parms. were necessary!
    D:\zJava\ <-- classes residing here could NOT successfully access the package 'com.zswingpackage1'. Similar scenarios as above.
    D:\zJavaB\ <-- classes residing here could NOT successfully access the package 'com.zswingpackage1'. I purposely created another folder with the 'B' suffix. Similar scenarios as above.
    My PC configuration:
         java version "1.4.0_01"
         Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
         Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
         JRun 4 (Build 47304)
         WinNT 4.0 SP5
         IE 5.50
         CLASSPATH=.;D:\jakarta-tomcat-3.3.1\lib\common\servlet.jar;
              C:\JRun4\servers\default\default-ear\default-war\WEB-INF\classes
         JAVA_HOME=C:\j2sdk1.4.0_01
         Path=C:\j2sdk1.4.0_01\bin;C:\WINNT\system32;C:\WINNT;
              C:\Program Files\Network Associates\PGPNT;C:\Program Files\MTS;d:\MSSQL7\BINN
    Thank you so much for your expertise.

    Hello,
    I think that you use the import-declarations incorrectly.
    Your code says:
    import com.zswingpackage1;
    ... The meaning of the above declaration is the following: Import the class "zswingpackage1" from the package "com". The compiler cannot find that class, but it is probably never asked to find it in your code, so it won't report an error.
    If you want to import the whole package use the following declaration instead:
    import com.zswingpackage1.*;
    ... That means: import all classes from from the package "com.zswingpackage1".
    You can also import just the classes needed, e.g.:
    import com.zswingpackage1.swing_optgrp_eg1;
    ... I hope that does the job.
    S&oslash;ren

  • Import the classes in the package java.util

    I haven't taken a class in two years so I have ideas but am unsure of myself, and I most likely am way off base, but is this how you import the classes in the package java.util
    import java.util.*;
    I would appreciate anyone's help. I have a lot of questions.
    Thanks,
    rp

    My assignment is below so that you will know exactly what I am asking. I am being asked to create an instance of LinkedList. I know that this is a part of the java.util. So when you create an instance of LinkedList would that be similar to instance variables? or am I misunderstanding something. I have several ideas, so I will start with the first one.
    LinkList();
    I really appreciate your taking the time to answer my questions to help me to rebuild my confidence in doing this.
    Thanks,
    // 2. import the classes in the package java.util
    public class MyProgram
         public static void main(String [] args)
              // 3. Create an instance of LinkedList
              // 4. add 5 entries to the list so that it contains
              //     Ann, Bart, Carl, Dirk, Zak
              // 5. display the list on one line using a loop and ADT list methods
              System.out.println("\n\n3. ");
              // 6. display the list using one println
              System.out.println("\n\n4. ");
              // 7. create a ListIterator object for the list
              // 8. display the list on one line using the iterator
              System.out.println("\n\n6. ");
              // 9. restore the iterator to the first item in the list
              // 10. retrieve and display the first item in the iteration,
              //      then advance the iterator to the next item
              System.out.println("\n\n8. ");
              // 11. advance the iterator to the end of the list without displaying anything;
              //      do not use the length of the list
              // 12. display the last item in the list
              System.out.println("\n\n10. ");
              // 13. move back to the beginning of the list without displaying anything;
              //      do not use the length of the list
              // 14. display the first item in the list
              System.out.println("\n\n12. ");
              // 15. advance the iterator to the end of the list without displaying anything;
              // 16. advance the iterator - what happens?
              System.out.println("\n\n14. ");
              // 17. advance the iterator within a try block; catch the exception, display a message,,
              //      and set the iterator back to the beginning of the list.
              System.out.println("\n\n15. ");
              // 18. what does nextIndex and previousIndex return?
              System.out.println("\n\n16. ");
              // 19. move the iterator to the third item in the list; if you were to
              //      execute next(), the third item would be returned and the iterator
              //      would advance to the 4th item.
              System.out.println("\n\n17. ");
              // 20. add the string "New" to the list; where is it inserted relative to
              //      the current item in the iteration?
              System.out.println("\n\n18. ");
              // 21. remove the current item; what happens?
              System.out.println("\n\n19. ");
              // 22. display the current item in the list without advancing the iteration
              //      in 2 ways, as follows:
              // 22A - using only iterator methods
              System.out.println("\n\n20A. ");
              // 22B using an iterator method and list methods
              System.out.println("\n\n20B. ");
              // 23. advance the iterator and remove the current item; which one is removed?
              System.out.println("\n\n21. ");
              // 24. move the iterator back and remove the current item; which one is removed?
              System.out.println("\n\n22. ");
              // 25. move the iterator to the first item in the list and change it to "First"
              System.out.println("\n\n23. ");
         } // end main
    } // end MyProgram

  • How to compile package which contain class outside the package

    I am writing a JDBC driver.
    I have the following package structure in the folder:
    MyDriver
        |_manager.jar
        |_com
               |_ jdbc
                       |_ HXDriver
                       |_ HXConnection
                       |_ HXResultSet
                       |_ HXStatementIn manager.jar, there is a remote object Interaface(Manager.java) which I need to use inside HXConnection.
    My question is how to compile(or/and how to set the classpath)so that I can compile the 4 classes inside jdbc package.
    I tried this:
    C:\MyDriver>javac -cp .;manager.jar com/hx/jdbc/*.java
    However, this does not work, compiler says it cannot find Manager
    Please help me.
    Cheers

    D:\380 Project\Driver>javac -cp .;manager.jar com\hx\jdbc\*.java
    com\hx\jdbc\HXConnection.java:21: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXConnection
            private Manager manager;
                    ^
    com\hx\jdbc\HXStatement.java:18: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXStatement
            private Manager manager;
                    ^
    com\hx\jdbc\HXStatement.java:20: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXStatement
            public HXStatement(Manager manager){
                               ^
    com\hx\jdbc\HXConnection.java:41: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXConnection
                            manager = (Manager)reg.lookup("manager");
                                       ^

  • Accessing a class outside the package

    Hi friends !
    Suppose I have a class called InsidePackageClass which is placed under C:\Package and other called OutsidePackageClass that is placed directly under C:
    Suppose my classpath points to C:\ and I want to declare a OutsidePackageClass member variable in the class InsidePackageClass. This leads me to an error. The compiler complains that it can't find the OutsidePackageClass class.
    What's wrong ?
    C:\
    |-Package
    | |---------InsidePackageClass
    |-OutsidePackageClass
    Thanks in advance
    Cleverson

    Like this?
    File: C:\OutsidePackageClass.java
    [code]class OutsidePackageClass {
         static String attribute = "first";
         public OutsidePackageClass() {
    }[/code]
    File: C:\Package\InsidePackageClass.java
    [code]class InsidePackageClass {
         public InsidePackageClass() {
              OutsidePackageClass o;
    }[/code]
    To compileset CLASSPATH=C:\
    cd \Package
    javac ../OutsidePackageClass.java
    javac InsidePackageClass.javaNote, javac will not run with current directory C:\

  • How to change the package name for a msg class

    Can anybody tell me how to change the package name for a message class.
    and how will it effect in the rerport?
    thanks in advance
    kp

    >>and how will it effect in the report?
    You wouldn't see any direct effect on the Report.. But if you transport the report to QA & leave the Message class in Dev, it might result in syntax issues & you will not be able to execute the report. Just ensure that both of them get transported to QA & you will be fine.
    ~Suresh

  • How to find classes in the package if package path

    in java i want to find classes,Interface,Exception names which are presant
    in the package..
    for example
    java.sql; if i give this it should return
    class name
    Date
    Time
    DrivarManager
    pls helpme in this field

    download the jdk documentation or view it here
    http://java.sun.com/j2se/1.3/docs/api/index.html
    The exact problem is i hava set the path to my application that path contains several jar's(contains classes,Interfaces) and classes with package structure,
    now my need is if i run the application ,the application
    should find out the classes and Interfaces for given package structure which are present in classpath...
    for this i have to load all the classes to memory(using classes loader) . then find out the classes which are present in memory...
    or
    any other inbuilt method is there in java when i give path structure it find and give classes which are in class path..
    for ex..
    if i set path to jdk
    then if i give the path like java.lang
    it should give me the out put as
    String (or) String.class
    Double
    Cloneable
    (classes & interface in that package)

  • Where should i add the java packages class path in the ORACLEJDeveloper 10g

    Hello friends,
    I have created a BPEL Program using java embedding activity.
    In it i have added some java code.
    I want to attach path of some java class packages.
    So can any one tell me solution for this.
    Thanks and regards.
    Ram Krishna Tripathi
    [email protected]

    Hello friends,
    I have made a Bpel program in oracle process manager 10.1.2 . using java
    embedding activity.
    (i) I have put the java class files in BPEL-INF /classes folder and
    SYSTEM/classes folder but still compiler is giving error that classes
    couldnot be found.
    I have set the class path in Project -> properties
    So please tell me what could be solution for this problem..
    (ii) Can the import package statements can be written in BPEL program in the
    java embedding activity ?
    Thanks and regards
    Ram Krishna Tripathi
    [email protected]

  • Where is the Package Name and Class Name for Android to Facebook SSO?

    Where is the Package Name and Class Name for Android to Facebook SSO?
    I am trying to fill these fields http://developers.facebook.com/docs/mobile/android/build/#ref for Facebook but i can't figure out what to place in Android Package Name and Andorid Class Name,
    same thing for the Android Key Hash, I followed this guide http://www.skoobalon.com/blog/2012/06/13/getting-the-android-key-hash-for-facebook-from-an -air-app/ but I am not sure if it is the right thing to do.
    I was thinking maybe the Pakage Name is air.com.myname.myappname (where com.myname.myappname is also the id used in the application.xml) and the Class name is  air.com.myname.myappname.MyDocumentClass ?
    Is there an official guide somewhere?
    Also do you guys know if there is somewhere a library we can use within AIR to do SSO on Facebook from Andorid?

    For what it's worth, I don't think a WiFi connection would be reliable enough. You wouldn't want your picture to freeze just because a neighbour has turned on their baby monitor. WiFi uses the same frequencies as a myriad of other devices, as well as all your neighbours' WiFi.

  • What is the package-visible class?

    I am reading JCVM2.2.1 Spec.
    I don't know what the package-visible class is?
    for example,
    Here is a sentence I could not understand.
    A public class cannot contain a public or protected field of type reference to a package-visible class.
    However, I know a general Access controls such as public, protected and private.
    Help me?
    What is the package-visible class in Java Card?

    There is something called package protected in Java. This means that an object may be accessible thru a package only. Sort of like public with limited visibility.
    Search the Java 2 Tutorial.

Maybe you are looking for

  • How can I know if a table is truncated or deleted in any moment?

    Hello, How can I know (if I can) if a table is being deleted or truncated at any moment over the time? Thanks

  • Audio Clicking and broken up when playing back from timeline

    Can anyone please give me some advice about a possible solution to a continuing audio problem I am having when using the Tascam Fireone with Final Cut Pro 5.1.4. (Fireone working well with Logic 7 on the same machine) The Symptoms are as follow: When

  • Problems with xsl transformation

    Hi, I have an XSL to transform an XML to HTML code. I want my HTML to be ACCESSIBLE. All is working ok, but the <html> tag have two or three attributtes that make de code no ACCESSIBLE. This is a part of the XSL code: <?xml version="1.0" encoding="UT

  • PLEASE HELP - how to read a crash report

    Please help! I recently wiped my mid 2010 MacBook Pro clean and rebooted from scratch. I used Time Machine to get my material back up and running and it works fine except it crashed on occasion (1-4x p/week) - I am a professional DJ and I fear it wil

  • OEM fails installing Ora10G in Red Hat ES/AS 3

    During the install of Oracle Database 10G v.1.0.3, the last version, in Red Hat Linux ES/AS 3, it fails when installing the OEM, and in the log file the next error is write : v-2004 18:04:29 oracle.sysman.emcp.EMConfig checkParameters GRAVE: Failed t