Java package names

Hello,
I was wondering if anyone can explain to me why when creating packages, they should be named in reverse.
I understand the concept of name classes etc, but why don't we use for example sun.com.myPackage instade of com.sun.myPackage?
What's the point in that?

The dotted parts of package and class names form a sort of hierarchy. That is foo.bar in some sense "includes" foo.bar.baz and foo.bar.EgClass. But we shouldn't read too much into this: as far as access rights go there is no special relationship between foo.bar.EgClass and the classes in foo.bar.baz. The common ancestry - foo.bar - doesn't count for much.
The Java Language Specification remarks: "The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (7.6) declared in that package. There is no special access relationship between a package named oliver and another package named oliver.twist, or between packages named evelyn.wood and evelyn.waugh. For example, the code in a package named oliver.twist has no better access to the types declared within package oliver than code in any other package".
That said the names, at least, form a hierarchy and the dotted form is intended to run from the most extensive to the most specific. (The part of the class name that we write with a capital letter is the most specific and so is placed last) A convention arose quite early in Java's life of inverting common "host" parts of urls. So if you use servers like www.mycompany.co.nz or ftp.mycompany.co.nz then you could form a unique name for your packages by taking all but the first part. Eg mycompany.co.nz.
But to run from most extensive to most specific this would have to be inverted: nz.co.mycompany
It is just a convention though and you're free to name your packages whatever you like. The important thing is to give them unique names.

Similar Messages

  • JSC2 Support for Traditional Java Package Names

    We have been looking for some encouraging words in the JSC2 documentation concerning the use of traditional java package organization for our creator projects but have been unable to find any. JSC2 appears to use a new project directory structure for its own purposes. However, there is no mention of package naming improvements in response to past requests from JSC1 users. We still very much want to organize our project content in the familiar java "com.company.ourproject.ourfeature" style. Is it the intention of the Creator developers to provide improvement in support for custom package names in JSC2 that is beyond what was possible in JSC1? Any insightful comments would be greatly appreciated.

    Hi,
    Please go through the following thread which discusses about the package structure:
    http://swforum.sun.com/jive/thread.jspa?threadID=53439&tstart=0
    Hope this heps
    Cheers
    Giri :-)
    Creator Team

  • Package name in stubs

    What is the "right way" to define package names
    to idl files so, that java stubs contains a valid java package name like: com.firm.software.unit?
    Am I right that module definition in idl can contain only
    one "level" name e.g. nameOfModule not com.firm.software.nameOfModule
    -m

    You can nest module statements to create the typical multi-part package names. Something like this:module com{
    module firm{
    module software{
         interface unit(in SomeType SomeVar);
    };This will create an interface unit in the package com.firm.software. Using nested modules makes it more difficult to use structures and interfaces defined in other modules, but this can also be done- just take a look at any CORBA book or something similar.

  • Package name when the doman name contains "-"

    Recently I'm working for a project for a company whose domain name like www.my-donkey.com. By convention, the Java package name should start with com.my-donkey.xxx, unfortunately the hypen is not allowed in the package name.
    What is the standard Java convention to address this?

    Remember that the package naming convention is exactly that: a convention. It isn't a rule, nothing checks them and you don't have to follow it. It was just an idea that someone came up with to make it less likely that package names from different organisations would collide. Go with Kaj's idea, package names don't have any legal ramifications or anything

  • The package name in the java files are modified

    Hey All,
    After creating a Portal Web Project, I imported the existing web applications to Weblogic Workshop. Then I found that the package names in the Java source codes are modified. The <folder name>. is added to the existing package name.
    For example,
    package com.symphonia.script.engine;
    is changed into
    package ScriptingEngine.com.symphonia.script.engine;
    because ScriptingEngine is the folder name.
    The package name of some other Java codes are doubled.
    For example,
    package symphonia.util;
    is changed into
    package syms-util.com.symphonia.util;
    Are there any ways to avoid this package rewriting when importing web applications to the Workshop?
    Thanks!
    Jeff

    To avoid path modifications add all 'base' paths(paths form which you will store the source code) to 'source paths' to Tools-->Project Properties-->Selected-project
    Then you add files/directories to one of the source-paths.
    They should not have any package modifications.
    HTH,
    Raj

  • Deploy java stored proc. publishes java class names without package name

    Hi to All,
    Using JDevStudio 10132 I've created a 'Loadjava and Java Stored Procedure' deployment profile for my project. I've added my static method to the deplyment profile, but it generates script without java packege name, only pure class name.
    For example it executes: ...
    CREATE OR REPLACE PROCEDURE Procedure1(p1 IN VARCHAR2) AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'CryptoHelper.Procedure1(java.lang.String)';
    instead of
    CREATE OR REPLACE PROCEDURE Procedure1(p1 IN VARCHAR2) AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'mypackege.xxx.yyy.CryptoHelper.Procedure1(java.lang.String)';
    The CryproHelper class is definitely in mypackage.xxx.yyy package and JDeveloper Application Navigator shows correctly it.
    Any ideas?
    thx fo answers

    Hi,
    I've just been doing this on 10133 and found exactly the same thing. It's an easy fix to edit the package body - but it's rather annoying to have to manually do something that should just work.
    Steve
    *Hand editing the .deploy file to add in the package name works.
    Message was edited by:
    spilgrim

  • Prohibited package name: java.sql

    hi,
    i am trying to push a java application onto a JRun 3.1 server connecting to a oracle 8 database. in my servlet initialization, i use a connection pool to gain a connection to the database.
    Class.forName("oracle.jdbc.OracleDriver");
    outConn = DriverManager.getConnection(outUrl, outUsername, outPassword);
    //throws error at the above line
    this will throw an error:
    java.lang.SecurityException: Prohibited package name: java.sql
    this error is most peculiar because it runs fine locally on my developers version of JRun 3.1. but when i push it to a licensed version on a different server it gives this error. any hints?

    I believe that class name for the Oracle JDBC driver is oracle.jdbc.driver.OracleDriver. The one you posted is incorrect.

  • Package name ending with .java

    Hi,
    I have some trouble with a package name ending with "fragments.java". When I use 'packagenames' javadoc complains when it reaches that package.
    I'm guessing javadoc thinks it's a source file and tries to parse it as such.
    I have found a workaround by using 'subpackages' instead of 'packagenames' but I want it work with ant, which doesn't support the subpackages flag.
    Is there a way to get around this?
    - Henrik

    Not at all.
    Assume that there is a package called something.smthing.java
    Then this won't work:
    <javadoc sourcepath="${src_dir}" destdir="${doc_dir}"
    packagenames="something.*"/>
    It will give the following error message because it thinks it is a source file:
    [javadoc] Loading source file something.smthing.java...
    [javadoc] error: cannot read: something.smthing.java
    So, you can get around that by doing like this instead:
    <javadoc sourcepath="${src_dir}" destdir="${doc_dir}"
    packagenames="something"
    additionalparam="-subpackages something"/>
    Which gives the -subpackages option to javadoc.

  • IOException: Prohibited package name: java.lang

    Hi!
    I have problems when trying to call a method that throws an exception over RMI-iiop. Instead of the exceptions that should be thrown I get an IOException and a stackTrace is printed out in the console(even if the exception is caught) The server is WL8.1 SP3 with java 1.4.2 and the client runs under java 1.3.1_09-b03.
    It works when the client runs under java 1.4.2. I also wrote a small testapplication outside of WL and it works fine too(using RMI-iiop, tnameserv and suns ORB, server under java 1.4.2 and client under java 1.3.1_09-b03).
    But when trying to call the method in WL i get the exception below instead of the one that is thrown.
    java.io.IOException: Prohibited package name: java.lang
         at com.sun.corba.se.internal.io.IIOPInputStream.throwExceptionType(Native Method)
         at com.sun.corba.se.internal.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:272)
         at com.sun.corba.se.internal.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:245)     at com.sun.corba.se.internal.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:207)
         at com.sun.corba.se.internal.iiop.CDRInputStream.read_value(CDRInputStream.java:1058)
    I have also tried to use suns ORB in WL but still get the same problem. Everything works fine except when an exception is thrown by the remote method.
    Any ideas what the problem could be?

    Hi, thank you for the answer.
    But I still think it can be a WL-problem. I can get an application outside of WL to work between java 1.4.2 and java 1.3.1. Even when sending a new exception created and compiled under 1.4.2 and sent to the 1.3.1-JVM, it is recieved correctly by the 1.3.1-JVM and thrown.
    I also tried to change WL to use SUNs ORB which I use in my test but still get the same problem so it feels like the problem is with WL's JNDI..
    /Jonas
    Jonas Mohlin <[email protected]> writes:
    Well the problem is because of the change in format
    java.lang.Throwable in
    J2SE 1.4. There are known bugs in the Sun 1.3.1 ORBs
    that prevent this
    working with a vanilla 1.3.1 client - and we can only
    support a WLS IIOP
    client running with 1.3.1 in this scenario (e.g. WLS
    7.0).
    andy
    Hi!
    I have problems when trying to call a method thatthrows an exception over RMI-iiop. Instead of the
    exceptions that should be thrown I get an IOException
    and a stackTrace is printed out in the console(even
    if the exception is caught) The server is WL8.1 SP3
    with java 1.4.2 and the client runs under java
    1.3.1_09-b03.
    It works when the client runs under java 1.4.2. Ialso wrote a small testapplication outside of WL and
    it works fine too(using RMI-iiop, tnameserv and suns
    ORB, server under java 1.4.2 and client under java
    1.3.1_09-b03).
    But when trying to call the method in WL i get theexception below instead of the one that is thrown.
    java.io.IOException: Prohibited package name:java.lang
         atcom.sun.corba.se.internal.io.IIOPInputStream.throwExce
    ptionType(Native Method)
         atcom.sun.corba.se.internal.io.IIOPInputStream.simpleRea
    dObject(IIOPInputStream.java:272)
         atcom.sun.corba.se.internal.io.ValueHandlerImpl.readValu
    eInternal(ValueHandlerImpl.java:245)     at
    com.sun.corba.se.internal.io.ValueHandlerImpl.readValu
    e(ValueHandlerImpl.java:207)
         atcom.sun.corba.se.internal.iiop.CDRInputStream.read_val
    ue(CDRInputStream.java:1058)
    I have also tried to use suns ORB in WL but stillget the same problem. Everything works fine except
    when an exception is thrown by the remote method.
    Any ideas what the problem could be?--

  • Bad package name of main-class, javafx 1.3, java 7u15

    Hello,
    I'm facing the same problem as what I read in this previous thread from someone else:
    Bad package name of main-class
    I originally tried to hijack it and rip ownership of that thread away for my own issue but a kind forum moderator has split my post away to let it stand on its own, as I should have done to begin with.
    My question is ...
    ... and I don't have any solution. I am using a javaFX app (1.3) which works perfectly with jre 1.6_11 and 1.7_11, but not with 1.7_15. The exception "Bad package name of main-class" is logged in the console.
    I read on the Internet that fixes in java 1.7_13 cause problems to all self-signed applet. So I signed mine with a trusted certificate delivered by my company, and I checked what pmgrundy said 2 posts before, but it didn't solve the problem.
    My jnlp file is corresponding to the example given in the official tutorial for applet deployment (http://docs.oracle.com/javafx/1.3/tutorials/deploy-applet/#configure), so the main targeted class is "com.sun.javafx.runtime.adapter.Applet".
    Do you have information that can help me in solving this problem ?
    Thanks in advance,
    Sébastien.

    Some additional information to the problem, if it can help :
    With JRE 6u43 : the applet is initialized and working properly. So the problem might not be due to the security fixes, as this version is including them.
    With JRE 7u15 & 7u17 : I tried to run the applet with the runtime v1.3.0_b412, then v1.3.1_b101a, but the problem is the same.
    When tracing is enabled through the Java Control Panel, the following lines are displayed at the end of the log :
    basic: passing security checks; secureArgs:true, allSigned:false
    basic: continuing launch in this VM
    preloader: Delivering: DownloadEvent[type=verify,loaded=1, total=1, percent=100]
    preloader: Start progressCheck thread
    basic: exception: Bad package name of main-class.
    ExitException[ 3]java.lang.SecurityException: Bad package name of main-class
         at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    preloader: Delivering: ErrorEvent[url=null label=Bad package name of main-class cause=Bad package name of main-class
    preloader: Stop progressCheck thread
    ui: Show default error panel
    security: Reset deny session certificate storeI think that the lines preceding those lines are about the validation of the different jars included, using the certificates. When the certificates are not installed on the user workstation, 2 dialog boxes are displayed during the applet validation, so as to ask the users if the applet should be run (and the JavaFX runtime). The certificates are well displayed as trusted. Then, after acceptance, the error occurs.
    Edited by: sebadavi on Mar 13, 2013 5:07 AM

  • Java package concept in ABAP Objects

    Hi, just a question on grouping of classes in ABAP Objects.
    In Java, you can group classes by "package" to avoid
    namespace collision, my question, in ABAP Objects, how
    do you group classes to avoid namespace collision?
    I know that there is package concept in SAP/ABAP but it
    is different concept in Java.
    Thanks in advanced for your reply.

    Hello One and Lonley,
    the package concept in ABAP and Java is quite different. In java the package name is part of the development object in ABAP not. So any class pool name is global unique. In combination with the restriction on 30 chars this leads often to somehow cryptic names.
    The only way to escape this somehow is the excessive use of local classes. That mean classes defined within main programs. If you are on 7.00 you may check FuGr SAPLSAUNIT_TREE_CTRL_LISTENER for this technique.
    Best Regards
      klaus

  • I need to remove "air." from package name. I'm get a Layout xml error when repackaging android app..

    So, i'm doing this on my own app. I made an update for an older app that was build using Native Android. But this time, i used Adobe AIR... The catch is Adobe likes to append a "air." to the front of your package name without asking you. So basically I can't upload my update because it has a new package name is now "air.com.mycompany.myapp" rather than the original "com.mycompany.myapp"
    Basically I'm going through this guide..
    http://helpx.adobe.com/air/kb/opt-out-air-application-analytics.html
    I followed all the steps, made all the adjustments to the androidmanifest.xml like it asks.
    But after going along with the above guide, with no issues when i get to the step that says
    "Run the following command to create the resource file for the updated AndroidManifest.xml:"
    I run this..
        "/Users/brybam/Documents/eclipse/android-sdk-mac_x86/platform-tools/aapt" package -f -M AndroidManifest.xml -F resources.arsc -I "/Users/brybam/Documents/eclipse/android-sdk-mac_x86/platforms/android-8/android.jar" -S ./res
    But I keep getting the same error regarding the xml files in res/layout
        ./res/layout/expandable_chooser_row.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/expandable_multiple_chooser_row.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/main.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/multiple_file_selection_panel.xml:1: error: Error parsing XML: not well-formed (invalid token)
        ./res/layout/ssl_certificate_warning.xml:1: error: Error parsing XML: not well-formed (invalid token)
    The guide doesn't say anything about these xml files, and im not sure what to do with these or how to handle them.
    If i go into the res/layout folder, and just delete these (i know they're necessary. But i just deleted them as a test, to get through the rest of the guide...)
    I was able to get through the rest of the steps in the guide fine, make an apk, and put it on my phone...only to find out the app will crash the moment you try to run it. Probably because i deleted the layout xml files...But i cant get the command i need to run above to accept them!
    So, earlier in the guide they have me use thing thing called the "AXMLPrinter2.jar" to make the AndroidManifest.xml readable so i can edit it.
    I run something like this:
        java -jar "/Users/brybam/Desktop/repackage/AXMLPrinter2.jar" AndroidManifest.xml > AndroidManifest.xml.bk
    This makes a new file "AndroidManifest.xml.bk" and i can edit that.
    So, I was thinking with all of these layout xml files, maybe I could run this "AXMLPrinter2.jar" on them and then edit them. Because right now if you open them they're not human readable, and its hard for me to work on them if they're not...
    I tried this thinking i could do the same thing...
        java -jar "/Users/brybam/Desktop/repackage/AXMLPrinter2.jar" main.xml > main.xml.bk
    Just get a blank file and a console erorr when trying to use the AXMLPrinter2.jar on the layout xml files...
        java.lang.ArrayIndexOutOfBoundsException: 67
                  at android.content.res.StringBlock.getShort(StringBlock.java:231)
                  at android.content.res.StringBlock.getString(StringBlock.java:91)
                  at android.content.res.AXmlResourceParser.getName(AXmlResourceParser.java:140)
                  at test.AXMLPrinter.main(AXMLPrinter.java:56)
    So, I think my whole issue is based around these XML files not being converted to human readable before i try and re-package....
    EDIT:::
    Ok, so I found a site that talks about the error I'm getting but it's in chinese, and even after translating the page...I'm still not well versed with terminal and this stuff to get it.
    It reads:
    "Error.
    Final conclusion:
    In minSdkVersion <= 7, AXMLPrinter2.jar can normally decompile xml file
    Greater than 7 can not be normal decompile xml file (AndroidManifest.xml except)
    Give way to share a batch decompile xml file:
    First, create a *. Txt file
    Stresses inside the content authoring
    for / r layout%% a in (*. xml) do @ java-jar AXMLPrinter2.jar "%% a" >> "%% a". txt
    Then this txt file extension into bat form, and this BAT the file and AXMLPrinter2.jar on the same directory will be decompiled xml into the layout directory
    Decompilation results can be generated by executing the bat file multiple xml files."
    - http://hi.baidu.com/ghcghc/item/ecbaa1ce997cb225a0b50ac2
    Maybe someone with more know-how could explain what they're explaining? I get that he's saying the issue im seeing appears when you're using minSdK <=7 but I need to use minSdk 8. Does anyone understand this work around? And how I might go about it on a Mac with terminal?
    I wish adobe would make it easy to remove the "air." from the package name. If they want to convert old Native devs to AIR devs...the transition needs to be seamless. But now I'm about to have to go back to Native because I can't update an app I already have out on the market with an air app.

    Hello~
         I also tried to remove "air." package name in air application. And i encounter the same problem.
         I do not find any solution to decode the xml inside res folder by AXMLPrinter2.jar. And those xml inside is compressed which is unreadable.
         However, what you can do is copying the structure of res folder. And go to your air sdk file path -  adobeair-sdk-folder/lib/android/lib/resources/
         Replace those file exists in your res folder. And copy "values" folder to your res folder.
         Hope this solve your problem~

  • Class name and package name clashing

    When i have a class and a package with the same name, I cannot access classes in the package. For example I have 3 classes and 1 package as below
    - Test.java
    - PackageName.java
    + PackageName // this is a directory
    - MyClass.java
    Below are the codes of .java files
    Test.java
    =======
    public class Test { PackageName.MyClass a = new PackageName.MyClass ();}
    PackageName.java
    ===============
    public class PackageName{ }
    MyClass.java
    ==========
    package PackageName; public class MyClass { }
    I can compile PackageName.java and MyClass.java but not Test.java. It says
    cannot resolve symbol
    symbol : class MyClass
    location: class PackageName
    PackageName.MyClass a = new PackageName.MyClass ();
    But if I remove the PackageName.java, I can compile Test.java perfectly. I think when I use PackageName.MyClass, java thinks that I try to access an inner class MyClass of PackageName class, and that does not exists. Is there any way to solve this ambiguation, other than making the package name and class name different? Thank you very much.

    This works fine: just add an import to Test.java.
    import PackageName.MyClass;
    public class Test
        public static void main(String [] args)
            MyClass a = new MyClass();
    public class PackageName {}
    package PackageName;
    public class MyClass {}It's a pretty wacky, useless example, but it works.
    Plus I thought inner classes would have a dollar sign in their .class file names. When I compile this:
    public class OuterClass
        public static void main(String [] args)
            OuterClass outer = new OuterClass();
            System.out.println(outer);
        public String toString() { return "I'm an OuterClass"; }
        class InnerClass
            public String toString() { return "I'm an InnerClass"; }
    }I see two .class files: OuterClass.class and OuterClass$InnerClass.class
    Why make up examples like this? It's hard enough writing code, and it's easy to disambiguate for the compiler.

  • How to change the package name of Managed Bean class

    Hi: Gurus, when ever I create a new JSP page the Creator creates a code behind file with a package name untitled. Is there any way to change this package name? Can't the Creator gives us an option before genereating manged bean page to choose a package name? And then create the Java source directory structure on the basis of the pakcage name?
    Regards,
    Rashid.

    In the Project Navigator (default location is middle right), go to Java Sources, and you can rename the package ("untitled") to something else by right-clicking it or by left-clicking (just like Windows Explorer).
    I agree, though, that giving the developer an option during creation of the JSP page would be nice.

  • Difficult to get good package names with ojspc in automated build

    If I understand the documentation for "ojspc" correctly, there is an aspect of its functionality that makes it difficult to have a convenient automated build which can also get good package names for the generated Java source files.
    If you don't specify the "-packageName" option, ojspc will build a package name relative to the current directory, including sub-directories. However, specifying "-packageName" will ONLY use that package, and will not create sub-packages associated with sub-directories.
    If you don't use the "-packageName" option, then you have to run the build from the root directory of your JSP files. When you're running an automated build with ANT, it's not convenient to do this.
    The likely result of this is that I would have to make sure that all of my JSP files are named differently, even if they're in different directories, and use the "-packageName" option to specify a particular package name for all of the generated source files.

    After more careful reading, I realized that using the "-appRoot" option (without using "-packageName") makes it possible for an ANT build to generate good package names (with directories).
    The following note, however, in the ojspc documentation is kind of odd:
    "It is advisable that you run ojspc once for each directory of your JSP application, so files in different directories can be given different package names, as appropriate."
    I assume this is referring to using the "-packageName" option. If you don't need to use "-packageName", especially if you have multiple directories of JSP pages, it is much easier to just let ojspc pick the package names.

Maybe you are looking for

  • Can't scan to email

    All functions on my photosmart 7520 work, except the scan to email function. I have tried everything. Please help.

  • I can help with a buffering problem in a video-based eLearning..

    Hello, I hope I can give a little back here for once.  : )   I have a video-based eLearning that is hosted on a LMS that has been giving the users with low bandwidth a lot of problems.  I was doing some testing with Chrome Dev Tools today, and I thin

  • AirDrop. Has anyone had a problem with getting this program to run consistently?

    I have had numerous case openings with this product. I love it when it works, but for some reason, my mac and mac book pro can no longer see each other when the application is opened. Both are running the current 10.8.2 upgrade and both are between 2

  • Tracking load on Hyperion Planning

    We need to come up with a management level report showing the usage of Hyperion Planning in the company.<BR><BR>We need metrics like :<BR>Peak number of users<BR>Average number of users (polling every 30 minutes)<BR><BR>Is there anything within Hyper

  • Changing the EVB3 speed control

    How do I change the rotary speed control number on the EVB3 to accept controller change #82, which is what my Nord Electro is sending? I'm using the Electro as a MIDI controller for Mainstage, and I've got all three pedal jacks plugged in, but i don'