Same class name, different packages

Let's say I have two classes called Team, and each are in their own package. I go to import a.Team and b.Team, what do I have to do to make this work?

Import them both if you need them both. When you go to use them, refer to them by their fully qualified name.a.Team aTeam = new a.Team();
bTeam bTeam = new b.Team();You don't really need the import statements from a programatic point of view, but it helps make your code more legible to other developers.

Similar Messages

  • Same class in different package

    I am facing a design decision, I have a set of classes which defined the values of all variables. However, I realized that I need to prepare
    separate set of these classes for different countries (as they may vary), i.e
    my.package.us
         PriceList.java
    my.package.ca
         PriceList.java
    PriceList.java
    ===============
    Public class PriceList {
    public final static Price directFlightPrice = new Price(13500,2); // where 0 is the decimal places
    public final static Price connectFlightPrice = new Price(11000,2); // where 0 is the decimal places
    I am not sure how I can achieve this, would you guys please help? Thank you!

    Isn't this more what you need? You don't want to create a new class, you should create a new instance of a class.
    class PriceList {
        private Price directFlightPrice;
        private Price connectFlightPrice;
        private String country;
        public PriceList(String country, Price directPrice, Price connectPrice) {
            this.country = country;
            directFlightPrice = directPrice;
            connectFlightPrice = connectPrice;
        ... methods to use pricelist variables
    class PriceListTest {
        public static void main(String[] args) {
            Map<String, PriceList> pricesPerCountry = new HashMap<String, PriceList>();
            // This is where you could load data from file and put it into a PriceList object...
            PriceList plUK = new PriceList("UK", new Price(...), new Price(...));
            PriceList plAu = new PriceList("Australia", new Price(...), new Price(...));
            pricesPerCountry.put(plUK.getCountry(), plUK);
            pricesPerCountry.put(plAu.getCountry(), plAu);
            // Use pricelist UK
            PriceList list = pricesPerCountry.get("UK");
    }

  • RMIClassloader same class name different versions

    I am writting a system so that I can have a task server send tasks off to a computing node and return the results. The plan is to set these clients up on a bunch of unused pcs around my university. Something that I am starting to wonder about though is if I run a distributed application once, then change parts of that application, will the RMIClassloader on the client know to redownload the applicable jar or will it try to use the old jar file which (I assume) it has cached or loaded already? The reason is, is that I I am in a development stage and my codebase might be changing although once the client and server are built I don't plan on making many changes to it after it is degugged.
    Thanks,
    RDL

    The same JVM will use the same downloaded class, but a new JVM will do a new download. There is no caching between JVM invocations. You do need to consider the effect of local HTTP proxy caches as well if there are any in the network.
    EJP

  • 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.

  • Accessing a dll from classes in different packages

    Hello java community,
    I am new to Java and especially the jni so your help is greatly appreciated.
    I am having trouble accessing a Windows native dll from classes in different packages. I placed the .dll in my ClassPath. I am able to loadLibrary successfully from class X in my 'common' package. However, when I try to access the same .dll from another class Y in package 'notsocommon'. I get an unsatisfied link error. I changed the X.h file to include common in the function definition (eg. Java_common_X_functionName) and I did the same to the Y.h file (Java_notsocommon_Y_functionName). I am able to work with the dll from the X class but not the Y class. I don't know what I am doing wrong. I am very new to Java, so any help is appreciated.
    Thank you.

    I apologize to everyone for posting this. I figured out my mistake, it was in the dll and not in the java. Also using
    javah -jni notsocommon.Y
    creates the correct header file.

  • 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.

  • Create Classes In Different Packages With Error-free Importing

    Hello,
    I'd like to create a class which inherits from another class from some other package. So I use "import" keyword to involve the class to build my new class on. However, I hope my new class can be in its own package which is different with one the base class is in. To make it clear, please see the example below:
    There are two folders, with name c08 and c09 respectively, in C:\Java which I created for this case. I set the environment variable as C:\Java. There is no problem. Then I saved file "Inter.java" in C:\Java\c08. It's source code is as below:
    package c08;
    public interface Inter {
         void play ();
         void action ();
    And another "Test.java" is saved in C:\Java\c09. Source code as below:
    package c09;
    import c08.*;
    public class Test {
    protected class PC implements Inter {
              public void play () {
                   System.out.println("Play()");
              public void action () {
                   System.out.println("Action()");
    It was successfully compiled for "Inter.java". But when comes to "Test.java", it failed with error message of something like "Cannot find the interface Inter". I tried some other ways and I didn't get any results.
    I hope to create a class using classes from some other packages while keeping the new one in a different package. How can this be done? (I am currently doing this in J2SE 1.4.01 under Windows XP Home Edition)
    Thank you!
    Best Regards
    Felix

    I copied and pasted your code as well as made c08 and c09 directories. I had no errors compiling. I am using NT, but it appears that your problem is Classpath related. You can try to CD to the C:\Java directory and compile using "javac c09\Test.java" That's the command I used.

  • 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

  • Moving Bean-class to different package

    Hi,
    For deployment reasons i need the Bean-class in a different package, seperated from package where the Remote and Home are located. I'm not sure how to do this in VisualAge 3.5p2. Simply moving doesn't work.
    Hope someone can help,
    Maarten

    It sounds a little bit strange. Do you want them in packages with different names, like you have bean-class in com.mycompany.project1.mybeanclasses and have the Remote and Home classes in com.mycompany.project2.myremotehomeclasses? It seems possible if you right-click the class you want to move and select 'move', you can move it to a new package. This will be able to separate them.
    Just curious, I think VAJ is very powerful concerning deploying EJBs already so what kind situation makes you want to separate the bean-class and interfaces?
    PC

  • 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.

  • Moving Model Class to different package

    Hi,
    How can i move the model class to a different package in CE 7.1
    Regards,
    Senthil

    Hi Senthil
    I thinks this should be possible to realize on the file system level.
    - Find the folder where your model as well as the model classes are located.
    - Search for all files (.) that contain the model class name. Typically it'll find (*.wdmodel and *.wdmodellclass). Change manually the package name within/near the found lines.
    But why do you need to change the model class package separately from the model package?
    BR, Siarhei

  • 2 Jars with same class name. NoSuchMethod. Can't change classpath

    I have overloaded a method in a class that came with an openSource package.
    Things were fine until I implemented my components in a new version of the Server application; when I discovered that the it uses the same openSource package bundled in its classpath.
    This results into a NoSuchMethod exception since I have overloaded the method with new argument types.
    1. I cannot remove or shuffle this JAR from the Server's classpath, since that would stop something else.
    2. I cannot change my code since it is implemented in a lot of places.
    Has anyone called a specific method of a jar? like E.g. "someJar.jar".SomeClass.someMethod (arg);
    If yes how?
    The above code is not possible syntactically, but I have put it for ease in interpreting the problem.
    Any input will be appreciated.
    NOTE: I cannot disclose the names of products for company policy issues.

    Just some ideas...
    1. I cannot remove or shuffle this JAR from the
    Server's classpath, since that would stop something
    else.Some servers allow for multiple classpaths - i.e. you can separately specify the classpath that the server itself uses from the one that your hosted applications will be using.
    Also, if your changes to the openSource code are only the addition of an overloaded method, why couldn't you just substitute your jar for the one the server is using, why would that break the server?
    2. I cannot change my code since it is implemented in
    a lot of places.That sounds lame. You can't do a global replace? How about just changing the package name?
    Has anyone called a specific method of a jar? like
    E.g. "someJar.jar".SomeClass.someMethod (arg);
    If yes how?Yes, but it's not as simple as your pseudo-code...
    You can use URLClassLoader to load a specific class from a specific jar file URL, and then use reflection to get the method you want from it, and then call it.
    good luck
    j

  • Same file name - Different extension - Viewing problem

    I know this has been written about quite a bit and I have searched through the posts but I cannot find a solution to my problem. I shoot RAW, import then into Lightroom, make changes, import into CS3 & make more changes, save as a .psd file; no problem so far. I use Neat Image on some files that need the noise reduction so in CS3 I save the .psd as a .tif, run it through Neat Image and save it to the same directory where the RAW and .psd files are. Go back to Lightroom and no .tif file. If you "find" the file in Lightroom it shows up but shows as the .psd file. I have tried unstacking and everything else I can think of but I cannot make the .tif file display. I can go back to CS3 and locate the file through it but if in a few months or however long it takes me to forget that the .tif is there, the .tif will be lost in never never land. Bottom line, how do I get Lightroom to show ALL files, no matter name, extension, etc?
    I am using Version 1.3.1 on Windows XP, 2Gigs ram, 3.4 Gig P4 processor

    This issue was argued down to skeletal remains in beta and after. Adobe finally rlented somewhat and allowed the importation of files with same name and the RAW and jpeg extensions, because for one good reason some cameras produce both and some shooters utilize both for differring purposes.
    Jao,
    I will disagree with your reading of what is standard. That MS's stupid explorer or anything else won't show extensions is immaterial. First, anyone wanting to work at any speed and efficiency will be using something like Total Commander instead of Explorer, and it and virtually every other app I own shows extensions and treats files with the same name but differing extensions as unique files unto themselves--as it should be.
    After all it is digital data in the file that is unique. The extension is a tag to tell you and the computor how to deal with that data. The content is not identical, and therefore it ought not be treated as if it were by any application.
    Anyone with an interest in wasting several hours can trace the arduous wailing at the LR team to treat the extension as part of a unique name. As I said bdefore, they did make some concessions. Hopefully, they will go the whole distance soon.

  • Question (JDev-Extension): Retreive class name with package info

    To JDev Development team:
    I'm developing an JDev 10.1.3 EA1 Addin. I have access to an oracle.ide.model.Node (the currently selected java code file from the Application Navigator / System Navigator).
    Is there a way (inside the Extension API to convert this node to String representation of a qualified java class pointer (package.classname)? Or do I have to use extensive String manipulation on the filename with path?
    Example:
    If the file in the tree is:
    casthouse
      + panel
        + casting
          + CastingPanel.java
        I want to translate this to casthouse.panel.casting.CastingPanel without having to use the Node objects URL.getFile() and manipulate the String object retreived from this, by removing path down to top-level package name and replacing all '/' with '.'.
    I'm sure your API has functions to do this. Either in the JoT packages or in the navigator itself... I've looked, but I cannot find any answers to this in the Extension API javadoc. (ref. post no.4 in Question: Adding extension preferences panels as subnodes in the tree
    Message was edited by:
    Øystein Amundsen

    If you have the Project in which the Node resides, then you can use Jot to get the information that you are looking for. If you don't already have it, you can probably get the project from the Context of the View.
    For example;
    Project prj = ... // Maybe use Context.getProject() to get this value.
    Node node = ...
    JavaManager jMgr = JavaManager.getJavaManager(prj);
    SourceFile srcFile = jMgr.getSourceFile(node.getURL());
    SourceClass srcClass = srcFile.getSourcePrimaryClass();
    String clsName = srcClass.getQualifiedName();

  • Extract class names from package

    I would like to be able to have te names of some classes. So I will be able to add new classes without changing other classes. I'm writing an application where I explain different kinds of sorting algorithms. I would like to be able to make a list of algorithms that are implemented. And also it should be no problem to add new algoritms. Each algorithm is in another class with a name that's related to their original name. It would be easy that when someone adds a new algorithm, he/she only have to implement a new class without looking at the other classes.
    If it is not clear what I mean, just ask.
    Greetz

    I would like to be able to have te names of some
    classes. So I will be able to add new classes
    without changing other classes.Huh? What keeps you from simply doing it?
    I'm writing an
    application where I explain different kinds of
    sorting algorithms. I would like to be able to make
    a list of algorithms that are implemented. And also
    it should be no problem to add new algoritms. Each
    algorithm is in another class with a name that's
    related to their original name. It would be easy
    that when someone adds a new algorithm, he/she only
    have to implement a new class without looking at the
    other classes.That's what abstract classes are for.

Maybe you are looking for

  • Need help in creating multiple signature forms?

    need help in creating multiple signature forms that can be digitally signed in adobe reader

  • Error in chart legend totals when there is a negative number involved

    Post Author: dawnyanne CA Forum: Charts and Graphs Hi if anyone can help me I would be extremely grateful! I have a pie chart with a legend. There are just two values that are showing but one of the values is a negative value and the total of the leg

  • BPC 5.1 Performance and Dashboards

    Hi: I have BPC 5.1 Installation and cannot find the Performance feature installed. I have seen this in Demo VMware which is located at http://<<server>>/osoft/performance/default.aspx. I could not find this and when I checked my server installation I

  • Sql Server Agent last run duration in minutes

    Hello Forum Members, Can you please advise me on this: There are 5 sqlagent jobs and they run many times in a day ranging from 10 seconds to 1 hour. I would like to know the duration of run in minutes during their last run. Kind Regards, Sqlquery9

  • Issue in Proxy service call

    Hi, The proxy service is getting called twice for invalid input.Its working fine for valid input.The logic i used is,checking the input file and calling an raise error action in case of validation fails.I gave retry count to 0.Is it possible to stop