Not allowed to import classes without package names?

Hi,
I have a few questions on Packages and importing?
1. Is the following true that it is illegal to import classes in the same package as the current class, will this cause a comilation error? If this is the case where in the Java Language specification is this actually written as I could not find it?
2. This has probably been answered by question 1 but if I have 2 classes in the same package and if I import 1 of the classes into the other class, is it illegal to import it by just using the class name and not the package name as well, ie
if the package name is ie.tcd
and the 2 class names are exp1.class and exp2.class, can I do this in class 2
package ie.tcd;
import exp1;
public class exp2 {
3. Is it illegal to import classes that are not explicitly part of any package or must a class be part of a package to be imported. I read somewhere that while this was always illegal it is only after jdk 1.4.2 that this is being enforced? If this is the case where in the Java Language specification is this actually written as I could not find it either?
Thanks very much for any help,
John

Was just also wondering, 1 other thing, I am looking
at someone elses code they have 2 classes (Class A
and Class B) in the same package (pkg). The person
imports class A into B:
package pkg;
import A;
public class B {
Is this legal code (or was it ever)?Not if A is really in pkg.A. If there is an A in the unnamed package it was legal, or at least it was understood by the compiler, and now it isn't (to both).
Can you import or is there a point in importing a class in the same
package?Only by naming the package in the import statement. If the current and the import statement are in the same package the import is redundant.
If there is a point would you import just be
using the class name (this would be illegal after jdk
1.4) or should you use the whole package name even
though it is in the package anyways?As I understand it you must always use the whole package name in imports.

Similar Messages

  • Import class without package

    hellow, i have a web aplication named test , and i have a class named conexion
    when i import a package "pack" with the class conexion, not problem (test/WEB-INF/classes/pack/conexion.class) <% import="pack.* " %> but when i have only the class conexion WITHOUT package (test/WEB-INF/classes/conexion.class) and i import <%import ="conexion" %> i have problem ("The import conexion cannot be resolved") and when i not import the class i have problem (conexion cannot be resolved to a type) , my question is:
    how to i import a class without package in JSP , and if the test/WEB-INF/classes is in the classpath when compile the servlet , why the tomcat not found the class conexion?
    (tomcat 5.5.20 , jdk 1.5.09 , vim)
    thank
    (Sorry my english , i'm from Chile)

    Hi I am hosting my JSP application with Resin 2.17 which uses classes directly in JSP code (not packages). To make this work I had to specify the classpath in Resin.conf and it worked.
    My problem is getting this to work with TomCat or any other application server that will allow me to debug my project in Eclipse or NetBeans IDE. (I have yet to find an IDE that Supports debugging JSP/Java code running on Resin - so I want to switch my application server but I am not sure how to configure my classpath for the application servers to look for java classes in the specified directory just like I did with Resin.

  • I want to integrate bookmarks from all my computers. I'm apparently not allowed to import bookmarks without a warning that already collected bookmarks will be deleted. What to do?

    I try to integrate bookmarks from all my computers running firefox. I'm apparently not allowed to import new bookmarks in addition to the old ones since a warning tells my that already collected bookmarks will be deleted. What to do?

    You could export the bookmarks to an HTML file and import that file onto the other computers. Importing HTML files adds the bookmarks to the existing ones. This can result in duplicate bookmarks.
    See [[Exporting bookmarks to an HTML file]] and [[Importing Bookmarks from an HTML File]]
    If you want to keep the computers in sync, you may want to consider the [https://addons.mozilla.org/en-US/firefox/addon/10868/ Firefox Sync] add-on may be of interest to you.

  • 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));
    }

  • Classes without packages not accepted by ejbc compilation ?

    Hey guys ...
    I noticed something which I found unusual...I mite be missing something out here
    When ejbc generates the Bean IMPL class , it does not put any import statements
    in the generated java file but references all the classes in the Bean with their
    absolute path ...
    Now ..I have a 3rd-party jar which does not have certain classes in packages...and
    I reference these classes within my Session Bean...the session bean compiles properly
    ..but when ejbc happens and the Impl class gets generated with the absolute path
    and no imports...the compiler expects to find all these 3rd-party classes without
    packages within the current session bean package itself which it will not..and
    hence throws all sorts of "cannot resolve symbol" errors...
    Does this mean that within my EJB beans I can never reference classes without
    packages or is there something I am missing..?
    Thanx,
    Krish

    Rob ,
    I agree with u that giving classes without package is not a good practise..but
    Itz got a history which believe it or not stems from another weblogic problem(related
    to webservices..)
    anywayz..that is another issue alltogether...
    I don't think this bug is fixed...coz I checked a WLS70 Impl and it is still generating
    the IMPL without the imports...
    But can u clarify..what u wud mean by "fixing the bug" ..does it mean that the
    Impl would start putting the imports..?
    Thanx,
    Krish
    Rob Woollen <[email protected]> wrote:
    I recall this bug being reported before. You might try the latest
    service pack and see if it's been fixed already. Otherwise, you'll have
    to contact [email protected]
    FWIW, it's quite disturbing that a 3rd party would give you a jar
    without a package.
    -- Rob
    Krishnan Venkataraman wrote:
    Hey guys ...
    I noticed something which I found unusual...I mite be missing
    something out here
    When ejbc generates the Bean IMPL class , it does not put any import
    statements
    in the generated java file but references all the classes in the Bean
    with their
    absolute path ...
    Now ..I have a 3rd-party jar which does not have certain classes in
    packages...and
    I reference these classes within my Session Bean...the session bean
    compiles properly
    ..but when ejbc happens and the Impl class gets generated with the
    absolute path
    and no imports...the compiler expects to find all these 3rd-party
    classes without
    packages within the current session bean package itself which it will
    not..and
    hence throws all sorts of "cannot resolve symbol" errors...
    Does this mean that within my EJB beans I can never reference classes
    without
    packages or is there something I am missing..?
    Thanx,
    Krish

  • Why does Apple not allow me to Change "Siri's" name on the I5?

    Why does Apple not allow me to Change "Siri's" name on the I5 (NOT how, but WHY)?

    No one here can address a question as to "why" Apple does anything.

  • Undefined variable, class, or package name

    The following code in the jsp is supposed to display the correct 'Securities' link based on the app_main_frames URL. I am getting an error. Can anyone help?
    <% if (parent.app_main_frame.location == ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) { %>
    Securities
    <% } else { %>
    <a href="/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none
    target="app_main_frame">Securities</a>
    <% } %>
    I am getting the following error:
    Generated servlet error:
    /opt/JBoss-2.4.4_Tomcat-4.0.1/catalina/work/localhost/cgi-java/common/jsp/NavigationMenu$jsp.java:173:
    Undefined variable, class, or package name: parent
    if (parent.app_main_frame.location ==
    ^
    ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) {

    If app_main_frame is a frame in a frameset then you cannot
    simply refer to it in a Java scriptlet.
    You can refer to it in a JavaScript script, like this:
    <script>
    if (parent.app_main_frame.location == "http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")
       document.write("<a href=\"javascript:submit_Form('none')\"target=\"app_main_frame\">Securities</a>");
    else
       document.write("<a href=\"/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none\"target=\"app_main_frame">Securities</a>");
    </script>

  • 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

  • Import vs full package name

    So, I decided to fumble a bit with JavaFX. After having gotten myself a sh*tload of stress doing stuff in Flash and Actionscript, I'm ready for something that is intended as "code" from the ground up. One thing I ran into is this: AFAIK I have two identical custom nodes, the only difference is that one uses full package names and the other uses imports. The components just show an image.
    Full package version:
    public class SfeerNode extends javafx.scene.CustomNode
        public var sfeerimage : javafx.scene.image.Image;
        override function create() : javafx.scene.Node
            return javafx.scene.Group
                content:
                [     javafx.scene.image.ImageView
                          image: sfeerimage
    }And the import version:
    import javafx.scene.*;
    import javafx.scene.image.*;
    import javafx.scene.paint.*;
    import javafx.scene.shape.*;
    public class SfeerNode2 extends CustomNode
        public var sfeerimage : Image;
        override function create() : Node
            return Group
                content:
                [     ImageView
                          image: sfeerimage
    }Usage is very straight forward, just like ImageView, and I can toggle between the two by simply adding or removing "2" after "SfeerNode" in the main code.
    The problem: the full package version does NOT show the image, the import version does.
    Why?

    It is definitely a bug.
    It is possible to extend only CustomNode class to make the first sample work .
    import javafx.scene.CustomNode;
    public class A extends CustomNode {
        public var sfeerimage : javafx.scene.image.Image;
        override function create(): javafx.scene.Node{
            return javafx.scene.Group {
                content:[ javafx.scene.image.ImageView {
                          image: sfeerimage
    }

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

  • Import classes or packages

    import java.util.*;
    import java.util.ArrayList,java.uitl.HashMap;
    What difference it makes to the performance of a class
    file when we import a specific class or an entire package

    For a great Q & A on this very question:
    http://www.javaworld.com/javaworld/javaqa/2001-04/01-qa-0406-import.html?
    Here is the quoted information:
    "Q. Does importing an entire package cause any runtime or compile time overhead? For example, does:
    import java.util.*
    compared with:
    import java.util.Vector
    cause any added overhead?
    A. In answering your questions a few definitions are helpful:
    Imports of the type java.util.Vector; are referred to as single type import
    Imports of the form java.util.*; are referred to as import on demand
    Both import on demand and single type import are passive mechanisms. As passive mechanisms, import loads information about the package and types only when it is needed. Indeed, the compiler will load this information only when a type is actually used, not when it is simply imported. The import simply tells the compiler where to look when it actually needs a type.
    So no, importing an entire package produces no more overhead than importing a specific type.
    That being said, it is generally regarded as bad practice to import an entire package using import on demand. Sometimes the number of imports may be large. However, you can quickly look at the list and know what classes the importing class uses. Such a list of imports can provide important documentation to someone unfamiliar with the code. "

  • Not able to import/export or package the application

    Not able to package and deploy/import the application.
    Currently we have organized our application under a folder  i.e., we kept all our schema, delivery templates, web forms etc. under these folders. We are facing the below challenges.
    We are able to package our total application but not able to import it Sandbox in a same folder structure used in Training Server.
    If a schema is linked with other schemas, we are not able to export the data.
    Even if its showing import is completed 100% but showing error at least one element is required by the package but missing from the instance.  As a result the import is failing.

    Thanks for your reply Linda.
    We have created our application under a certain folder structure. At root we have the application folder. Then we are keeping say all delivery templates under Delivery Templates, all web forms under Web application folder etc. That is how we have organized the application.
    Application folder
                    Delivery Templates
                    Web application
                    Workflows
                    Offers
    We have created a package definition and added our component there. With that package, we are exporting our application. Export is successful.
    But when we are importing the package, all components are getting scattered and not coming in the same folder structure we used when creating the application.

  • When trying to make purchase I am asked to improve apple security by setting up 3 questions.  I have tried many times with out success.  Apple always returns an error without identifying what the error is.  Will not allow me to advance without setting up

    Apple is requiring the establishment of 3 security question (increase online security), but coninuously gives an error without identifying the error.  I am not allow to proceed or bypass and cannot use any apple store features.

    Exactly when does this error occur?  What is the exact wording?

  • Need Hex Encoder Class and Package Name

    Hi,
    I have a requirement in which I need to convert an xml (input) into a Hex format (output). I know that there is a class called as BASE64Encoder when you want to encode a data into base64Binary format and this one is present in the sun.misc.BASE64Encoder package. Now my question is do we have some class called as HexEncoder included under some standard package (like sun.misc.HexEncoder)?
    Please provide pointers on how to solve this.
    Thanks,
    Abhishek.

    Hi,
    You get most of the encorders from here http://www.koders.com/java/fid1DEA9207865756960D16FBA292EE6534A47D3BAD.aspx
    Regards
    Ayyapparaj

  • Value types not allowed in Collections classes?

    When I tried to instantiate a TreeMap< int, Object >, I received a compile error. I searched the Collections documentation but didn't see any explanation of why this sort of thing isn't allowed. I realize I can use an Integer object, but it just seems inefficient to have to construct a new Integer every time I want to search the container (which will be extremely frequent in this particular situation).

    For collections, int doesn't define methods like compareTo or hashCode, so each combination of primitives would have to be implemented as a special case. I just found a library that seems to do this: http://fastutil.dsi.unimi.it/.
    Got it. And by the way, the fastutil library looks to be exactly what I need. Thanks for the link.
    BTW, if you have Java 1.5 or later (i think) it has a feature called autoboxing which automagically converts primitives to their wrapper class and back again.That's what I'm currently using, but I just wanted to avoid the overhead of repeatedly creating an Integer object (in porting the application from C++ to Java I've noticed some degradation in speed, and so I'm cutting corners wherever possible).

Maybe you are looking for

  • OS 10.8.5 won't let me open mail on thumb drive

    Lots of people have posted at various times in the discussion groups that they have had problems accessing their mail, getting the message "You can't use this version of the application 'Mail' with this version of OS X.'" I have mail from my old Mac

  • Ora-01031 error: insufficient Priviliges

    hi experts, im was completely enervated by a simple error for which im hanging out for plenty of hours. kindly advice me what to do to eradicate it. i have a Redhat Linux AS 4 server and 9.2.0.4 database version. The problem is, when im trying to con

  • Changing the value of the field in message

    hi i have a input message to XI like this <records>        <data_records> 1 to unbound             field1             field2             field3 the target structure is as below <records>        <data_records> 1 to unbound             field0          

  • ISE machine authentication timeout

    Hi all, We have a ISE infrastructure and we have enabled user and machine authentication through EAP-TLS. Everything is working fine except that every 1 hour user must log off and login again because machine authentication has, I think, expired! As y

  • How can I get certain devices to play one of the audio streams I uploaded?

    I uploaded my Music On Hold Audio Source. I restarted Media services. Then I went to one of my devices and select the audio stream needed for User Hold MOH Audio Source and Network Hold MOH Audio Source.  I hear dead air.