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.

Similar Messages

  • Class name and package names

    I read a passage from some Java Book (sorry don't have the reference handy) that
    "It is illegal for a package and a class to have the same name, so there can be no ambiguity."
    Yet I have created a class named pkgclass within a package with the very same name.
    i.e.
    package pkgclass;
    public class pkgclass {
    This compiles just fine. Have I misinterpreted the statement from the book? What is it trying to say?
    Thanks in advance.

    Here's a quote from the Java language spec:
    "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."
    So your book was not quite correct, or maybe you just misremembered it (clearly you are typing from memory there). It isn't illegal for a package to have the same name as a class, as in your example. But it is illegal for a package to contain a subpackage and a class with the same name.

  • Conflit in class name and package name

    I have a small doubt. If the class name and the package name are the same in a folder, is there will be any conflict between these while using it. That means suppose a folder named 'animator' contain a package 'a' and a class name 'a'. I got any error in the 'Eclipse' tool that "a collides with a package". Is this can be solved my any change of setting in Eclipse? If then where can i change.? Can anybody help me to solve this issue??

    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.

  • Class and package names

    I'm novice in Java, but not novice in programming. So, it is not a problem to understand and to write simple samples, but it is still hard to create a good package structure and give good names for classes.
    For example now, I started writing simple standalone application, which will be run by cron and will communicate with 2 webservices. I will receive data(reports) from one webservice, and will send this data to another one. From the very beggining, I have a poblem about structure of roject and naming. Is it ok, to make only one class, with name for example ReportApp? Or better create one class for communicating with first service, another - with second, and main class will call methods of this classes? Also package name... I think it is good, when from package you see, that i is service, or xml.util etc. How can I show in package name that it is batch standalone application? Can somebody explain what names for classes and packages he'll use for such task, please.

    Descriptive names are nice....
    For packages, a standard method is a domain name for your company or organization:
    com.widgetsRus.service.
    com.widgetsRus.ui.
    com.widgetsRus.util.
    As for class names, just descripe what the class is for. ReportServer, ReportClient, Report (interface), AbstractReport (implements Report), StatusReport (extends AbstractReport), etc...
    As for creating a class for this and that, or separate classes, that's a design issue, but typically, it's easier to maintain things if they are kept in smaller classes with related functionality.

  • Testing class and package name legality

    Hi all. Does the API provide a way of testing if a given class and package name is correct? I have to model a UML diagram tool. Right now, I'm doing it like this:
         public boolean canHaveAsNameStrict(String name){
              return(!name.startsWith("([0-9])+") && name.matches("([a-zA-Z_0-9])+"));
         }for a package, but this may be incmoplete etc. Also, are the brackets ([...]) and the + sign delimeters or part of the match? (I copied this code from an exercise solution, in which they were not mandatory to the solution)

    Beware - the JLS allows non-ASCII class and package names. You can have a class named "�owyn", for instance.
    class CheckPackage {
        public static void main(String[] args) {
            String pat = "([A-Za-z_$][A-Za-z0-9_$]*\\.)*[A-Za-z_$][A-Za-z0-9_$]*";
            System.out.println (args[0].matches (pat));
    }

  • How to fetch what are all the tables used in this TR no and Package name of

    Hi Friends,
    I have input of Transport Request no (E070-TRKORR).
    How to fetch what are all the tables used in this TR no and Package name of this Table.

    HI,
    FYI
    SELECT E071OBJECT_NAME, E070MDEVCLASS
    FROM E071, E070M
    WHERE TRKORR = YOU REQUEST NO.

  • How to get the class name and field name dynamically

    Hi
    I have a class (ex: Contract) the fields (ex : a,b,c) .i need to get the class name and field name dynamically
    ex
    if( validation file for the field Contract.a){
    return contract.a;
    }else if(validation file for the field Contract.b){
    return contract.b;
    how to pass the field name and object dynamically
    Please help me .............
    Thanks in Advance..
    Edited by: 849614 on Aug 11, 2011 6:49 AM

    YoungWinston wrote:
    maheshguruswamy wrote:
    Agreed, but IMO, i still feel its best if there is no tie in between consumer class level details and the database it talks to. A service layer is needed in between them.Sounds like you've done a bit of this before. Me, I've either been a modeller/DBA, doling out data, or a nuts and bolts programmer (and actually more toolmaker than apps, but did a bit of that too).
    Do you know of a good book about the "middle ground" (ie, these service layers)? I understand it empirically, but haven't had a lot of exposure to it.
    Winston
    Edited by: YoungWinston on Aug 11, 2011 10:34 PM
    PS: Apologies. Edited my previous post, presumably while you were composing your reply, when I finally realized what '.filed' meant.Most of my work is in web development, never been a DBA :) . The biggest 'concern' in my shop is 'separation of concerns'. The UI group reports up to a different IT head, the DB group reports up to a different IT head and so on. The looser the coupling between these systems, the lesser the project costs (Integration, QA etc) are. Martin Fowler's books contain good information about separation of concerns in an enterprise environment. The two books which i recommend are
    [url http://www.amazon.com/Patterns-Enterprise-Application-Architecture-Martin/dp/0321127420]Enterprise Application Architecture and
    [url http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683/ref=pd_sim_b_1]Enterprise Integration Patterns

  • How to know database name and schema name by providing package name?

    Hi,
    Could someonw will help me to get database name and schema name by providing package name ?
    I have used the query : select * from all_objects where object_name='Package_name'; but it simply returns schema name where as i need DB name and username.
    --Prajakta

    but it simply returns schema name where as i need DB name and username.
    i want to retrive the DB name for package name
    Based on your questions, I wonder if you are used to working in SQL Server? (The server, database, and schema are part of the 4-part  name of an object, independent of any user.)
    In SQL Server, schema and username are two separate physical concepts.  "Schema" is purely logical in Oracle: a user which owns objects is often called a "schema".
    In Oracle, "database" is roughly equivalent to the SQL Server concept  "server" (what you log in to).  It is not part of the naming path to a specific object  (unless there is a database link involved, but there is no indication that's what you have here).  In Oracle you connect to an Instance (or Service) and people often call this the "database", but there is a fine semantic distinction there (separate topic). 
    Once connected in Oracle, you fully-qualify an object by only a 2-part owner and object name (possibly 3-part if a database link is involved user.object@link).
    12c added another wrinkle to all of this, but I'll assume this question was more basic than that, because you likely would have mentioned if this was a 12c question.

  • Getting the user name and computer name

    I've been trying to find out how to do this, but can't seem to get it.
    I have an AIR application that needs to get the user's login name, and computer name for verification.  I can't find anywhere to do this.  Is AIR able to get this information? Is there work arounds if there isn't?
    It won't ever be a web app, just an AIR app.

    What I did in Air 2 to accomplish that is the following:
                   public function getHostName():void {
                        if(NativeProcess.isSupported) {
                             var OS:String = Capabilities.os.toLocaleLowerCase();
                             var file:File;
                             if (OS.indexOf('win') > -1) {
                                  //Executable in windows
                                  file = new File('C:\\Windows\\System32\\hostname.exe');
                             } else if (OS.indexOf('mac') > -1 ) {
                                  //Executable in mac
                             } else if (OS.indexOf('linux')) {
                                  //Executable in linux
                             var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                             nativeProcessStartupInfo.executable = file;
                             var process:NativeProcess = new NativeProcess();
                                  process.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
                                  process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutput);
                                  process.start(nativeProcessStartupInfo);
                                  process.closeInput();
                   import utls.StringHelper;
                   public function onOutput(event:ProgressEvent):void {
                        var strHelper:StringHelper = new StringHelper();
                        var output:String = event.target.standardOutput.readUTFBytes(event.target.standardOutput.bytesAvailable);
                             output = strHelper.trimBack(output, "\n");
                             output = strHelper.trimBack(output, "\r");
                        trace('"'+output+'"');
    The package that I used is from the manual:
    package utls
         public class StringHelper
              public function StringHelper()
              public function replace(str:String, oldSubStr:String, newSubStr:String):String {
                   return str.split(oldSubStr).join(newSubStr);
              public function trim(str:String, char:String):String {
                   return trimBack(trimFront(str, char), char);
              public function trimFront(str:String, char:String):String {
                   char = stringToCharacter(char);
                   if (str.charAt(0) == char) {
                        str = trimFront(str.substring(1), char);
                   return str;
              public function trimBack(str:String, char:String):String {
                   char = stringToCharacter(char);
                   if (str.charAt(str.length - 1) == char) {
                        str = trimBack(str.substring(0, str.length - 1), char);
                   return str;
              public function stringToCharacter(str:String):String {
                   if (str.length == 1) {
                        return str;
                   return str.slice(0, 1);
    And sorry for the miss topic I just realized that it is on flex topic, but I post it either way it may be useful for anyone

  • Passing table name and columns name as parameters to procedure

    i need a procedure that take table name and column names as parameters .
    it should display all values in those columns
    like
    if i execute procedure p ( t1,c1,c2)
    it should display c1,c2 values in t1 table
    if i execute procedure p ( t1, c1,c2,c3)
    it should display c1,c2,c3 values in t1 tables
    no of column parameters changes

    See if this helps...
    First, read the manual on collections.
    Second, define your expected results. You want to output the results to the screen? You cannot perform a 'select' in PL/SQL. You will have to select your output into another collection, then loop through that.
    Finally, I am curious why this is necessary versus performing a regular query.
    Take a look at this incomplete code.
    create or replace
    package dave_pac
    IS
    TYPE col_name_list IS VARRAY(20) OF VARCHAR2(30);
    PROCEDURE SFA_TAB_COL1
    (p_tname  IN    VARCHAR2
    ,p_cnames IN    col_name_list);
    END;
    create or replace
    package  body dave_pac
    IS
    PROCEDURE SFA_TAB_COL1
    (P_tname  IN varchar2
    ,p_cnames in col_name_list)
    IS
    l_stmt long;
    l_rc number;
    begin
    l_stmt :='select '||p_cnames(1);
    for i in 2..p_cnames.count
    loop
    l_stmt :=l_stmt||' , '||p_cnames(i);
    end loop;
    l_stmt:= l_stmt||' from '|| p_tname ;
    execute immediate l_stmt;
    end ;
    END dave_pac;

  • Get the font names and image names in QXD

    Hi,
    How to get the font names and image name in Quarkxpress document file using java?.
    Is any third party packages for getting font n image names in QXD?
    thanks,
    nithya

    rtuck,
    I believe this may solve it:
    Open System Preferences and go to Accessibility. Next, select Display from the source list along the left, then check the box labelled Reduce transparency.
    It was first presented in this post #15 by TheUlser:
    https://forums.adobe.com/message/6854594#6854594

  • Is there a list of table name and object name? (oCompany.GetBusinessObject)

    Hi,
    How do I find the objects regarding the tables in SBO?
    Example Item Master, I use following statement:
    SAPbobsCOM.Items oItem;
    oItem = ( SAPbobsCOM.Items ) oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
    I like to find the object for SPP1.
    Is there a list of table name and object name?
    Thank you,
    Rune

    Thank you, Owen,
    Yes, I found the table name and method name in SDK Help Center:
    On your P/C, click START. Select All programs , SAP  Business One > SDK > SDK Help Center. Then select  DI API, then DI API Reference. If you scroll down this window you will find all existing classes. You will then find the SpecialPrices and the SpecialPricesDataAreas. All the information required to code is in there.

  • HT1451 Why do the song names and cd name not show up on the IPod Shuffle?

    Why do the song names and cd name not show up on the Shuffle?

    MysticChyk wrote:
    Why do the song names and cd name not show up on the Shuffle?
    Err this is no longer April 1st you know.
    The iPod Shuffle has never had a 'display' on which track names can be shown. See http://www.apple.com/ipod-shuffle/ if you want an iPod which does have a display on which you can see the tracks names and even the album cover art then look instead at the bigger and more expensive iPod Nano http://www.apple.com/ipod-nano/ or iPod Touch http://www.apple.com/ipod-touch/
    PS. The current iPod Shuffle even though it has no display on which it can show the track names can read them out loud to you using a voice-synthesiser this is the VoiceOver feature described on the iPod Shuffle product page I listed above.

  • SharePoint 2010 Web Analytics showing user Display Name and Account Name from the same user

    Hi!
    Since July, 16th 2012 the Web Analytics Daily Unique Visitors reports started to show almost the double of visitors we used to have on our Web Application. Here are some of the data (I intentionally deleted the weekend data):
    10/7/2012 2.497
    11/7/2012 2.723
    12/7/2012 2.722
    13/7/2012 2.699
    16/7/2012 5.055
    17/7/2012 4.963
    18/7/2012 4.954
    19/7/2012 4.998
    20/7/2012 4.965
    23/7/2012 5.117
    24/7/2012 5.012
    25/7/2012 5.071
    As you may notice the data jumped from around 2.700 unique visitors to around 5.000 unique visitors. As the number of permissioned users remains constant it is pretty odd. I also checked the Number of Page Views report and see no change on its behavior.
    The number of page views remained constant.
    So I went to look the Top Visitors report and understand why the visitors number almost doubled. The analytics started to count the users Display Name and Account name as two different visitors with a different number of page views. Let me show you an example
    from yesterday (July, 25th) Top Visitors report:
    #     Visitor                  Page Views    %
    1    Cinthia XXXXXXXXXX    359        0,55%
    5    Giselle XXXXXXXXXX     143        0,22%
    7    Aline XXXXXXXXXX       138        0,21%
    15  nt\cmazevedo              111        0,17%
    60  nt\gbsantana                 69        0,11%
    73  nt\aglsiqueira                 65        0,10%
    "Cinthia" and the account "nt\cmazevedo" are the same person. The same is applied to "Giselle" / "nt\gbsantana" and "Aline" / "nt\aglsiqueira".
    As I stated this is an example from July, 25th. If I checked the same report from a period before July, 16th I can only see the users Display Name as "Visitors". No account name is displayed or counted as a different visitor.
    About the environment:
    We have two SharePoint 2010 farms: a "corporate" and a "enterprise". The corporate farm contains four web servers and a central administration servers with publishing services. The enterprise farm contains two servers running User Profile Services, Search
    Services and some others. Our main version is the SP1 with June/2011 Cumulative Update with a few more hotfixes applied.
    This behavior on analytics is affecting all web applications (we have more than 20) installed on this farm and my company Support team said that no change were made on SharePoint on the weekend the problem started.
    Does anyone have any tip about what is going on?
    Thanks in advance!

    Hi, Manas!
    First of all thanks for your interest on this issue but I don't think it is related to the User Profile or the Active Directory.
    I checked both records and there was no change on the Display Names. All the users have "full names" as display names (first + middle + last name) and not logins as SharePoint is displaying on this report.
    But I did a test yesterday and checked the results today confirming that just the access been made using a specific server are causing this. Explaining it better:
    I have four web servers on my farm named from P01 to P04. Then I created this test script:
    Step 1: Change local HOSTS file to point the web application on the server P01.
    Step 2: Access site "A"
    Step 3: Access site "B"
    Step 4: Close the browser.
    Step 1: Change local HOSTS file to point the web application on the server P02.
    Step 2: Access site "C"
    Step 3: Access site "D"
    Step 4: Close the browser.
    Step 1: Change local HOSTS file to point the web application on the server P03.
    Step 2: Access site "E"
    Step 3: Access site "F"
    Step 4: Close the browser.
    Step 1: Change local HOSTS file to point the web application on the server P04.
    Step 2: Access site "G"
    Step 3: Access site "H"
    Step 4: Close the browser.
    I asked three users to execute that script. The results: All access to the sites "C" and "D" were registered on Web Analytics with the user account name such as "nt\cmazevedo". All the other sites registered the user Display Name correctly such as "Cinthia
    XXXXXXXXXX".
    With this test we could isolate the problem just on the server P02. It doesn't occur on the others. Now my support team is trying to find any configuration difference between this server and the other three that could point for the root cause.
    I am also looking for some information regarding the service responsible for this task ("transform the account name into a display name") to understand why it doesn't work on one server and works on the others.
    Thanks!

  • Field names and table names

    Hi Experts,
    What r the table names and field names for
    FLSA Description
    Stock Option Eligible
    Career Level
    Full time/Part time

    > Full time/Part time--> T503T-PSERK
    ~Suresh

Maybe you are looking for