Implemenet/Extend interface/class in default package

Filename: DeaultInterface.java
public interface DefaultInterface {
    // Abstract Methods...
Filename: ConcreteClass.java
package com.company;
import DefaultInterface;
public class ConcreteClass implements DefaultInterface {
    // Implementation of Abstract Methods...
}When I compile above java code it gives error "cannot find symbol. symbol: class DefaultInterface".
Can anyone explain why can't we implement the interface/extend the class in default package(no package)?
Edited by: 974531 on Dec 2, 2012 11:07 PM

>
When I compile above java code it gives error "cannot find symbol. symbol: class DefaultInterface".
Can anyone explain why can't we implement the interface/extend the class in default package(no package)?
>
You CAN implement the interface defined in the default package.
What you CANNOT do is import it. And that is because the Java Language Specification specifies that named types can only be referenced by their simple name if they are imported and must otherwise be referenced by their fully qualified name.
See the 7.5 Import Declarations in the Java Language Specification - http://docs.oracle.com/javase/specs/jls/se7/html/jls-7.html
>
An import declaration allows a named type or a static member to be referred to by a simple name (§6.2) that consists of a single identifier.
Without the use of an appropriate import declaration, the only way to refer to a type declared in another package, or a static member of another type, is to use a fully qualified name (§6.7).
A type in an unnamed package (§7.4.2) has no canonical name, so the requirement for a canonical name in every kind of import declaration implies that (a) types in an unnamed package cannot be imported, and (b) static members of types in an unnamed package cannot be imported. As such, §7.5.1, §7.5.2, §7.5.3, and §7.5.4 all require a compile-time error on any attempt to import a type (or static member thereof) in an unnamed package.
>
So you can't reference that type by importing it because you can't import a type that doesn't have a canonical nmae. And you can't just use the simple name because, as the first statement above says you have to import it to use the simple name.
When you use the simple name of that type without an import the simple name would refer to a class IN your 'com.company' named package.

Similar Messages

  • Access Class in Default Package

    Make long story short, I have to have some class in the "(default package)", related to JNI, and I will need to pass data back and forth from and to these classes from some packaged classes. I am using Java 1.4. As I know since Java 1.4, it's not possible to access classes in default package from packaged classes directly. Is there a work around? please help...

    I DON'T have the C/C++ codeSo you have to do with the "old" classes in the default package.
    Then use jschell's suggestion to devise proxying code that allow bridging between the packages.
    since Java 1.4, I can't call the java class in the default package from packaged class any moreIf I understand jschell's post, this restriction is enforced by the Java compiler , not by the Java interpreter (JVM). Indeed this is specified in the JLS (Java Language Specifications, http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.5), not the JVM specifications (I have not verified that latter point).
    So if you get an older JDK (before 1.4 they would accept the construct), you can try writing proxy classes within a named package, proxying to the old classes in the unnamed package. Once they are compiled, and jarred together for convenience, you can switch back to the current compiler (let's says 1.6) to compile the rest of your application classes, which only use the classes in the named package, using the jar as a library.
    When executing the program, the JVM will execute everything without complaining, since it supports execution of compiled code that has been compiled with former versions.

  • Trying to page import directive in a JSP  access a class in default package

    I am trying to import a class the is in my default package directory for Tomcat 4.1.18 (context-root\web-inf\classes\*.java). I am getting the following error
    This is error using Tomcat 4.1.18
    org.apache.jasper.JasperException:Unable to compile class for JSP
    C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:9: '.' expected
    import Product;
    C:\Program Files\Tomcat4.1\work\Standalone\localhost\csc297\HTML\SearchByName_jsp.java:10: '.' expected
    import Category;
    This is error using Tomcat 4.0.6
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:5: Class Product not found in import.
    import Product;
    ^
    C:\forte4j\tomcat401\work\localhost\C_3A_5Cforte4j_5Ctomcat401_5Cwebapps_5Ccsc297\HTML\SearchByName$jsp.java:6: Class Category not found in import.
    import Category;
    Here is snippet of code from my JSP:
    <%@ page import= "java.util.*"%>
    <%@ page import= "java.text.DecimalFormat"%>
    <%@ page import="Product"%>
    <%@ page import="Category"%>
    Remember these classes are in my default package of my context-root
    Any ideas would greatly appreciated

    Weird error. Never seen this one before.
    Try packaging your classes eg:package myClasses;and import them:<%@page import="myClasses.*"%>Should fix the problem.
    Anthony

  • Importing class from default package of a JAR

    I want to create objects of a class contained in a JAR. The JAR has many classes in numerous packages, however the class that I want to use is in the default package. I'm using eclipse and have added the JAR to the build path, but eclipse complains that the class name cannot be resolved. Is there some way to specify an import statement to look in the default package of a particular JAR? Any advice is appreciated.

    jg2009 wrote:
    I was under the impression that classes without a defined package were technically considered to be part of the so-called default package. But, in answer to your question, yes this class does not appear to part of any package.
    Just to provide so additional information, the class that I want to instantiate is an Applet, so it is designed to be called from an html object tag, and have access to all of the other classes in its JAR. There is a system that provides access to underlying data via the following components: html form <-> javascript <-> applet <-> serverlets <-> data
    I want to automate certain data operations, but the only way to access the underlying data is via the applet. Am I out of luck, or is there some way that I can instantiate the applet?All jverd said is right, assuming it is your code and you can change it: basically move everything to a package. But I think your problem is that the jar is a 3rd party jar and you cannot change it. If this is the case, you can use the 'default package' (the terminology is correct) by having your own class(es) in the default package or by using reflection (last time I tried reflection would work). Both are rather bad solutions, but if you really, really want...
    Note: Java actively discourages the use of the 'default package' and more so recently, this is why I am not even sure that reflection would still work.

  • Importing classes from default package

    hey all,
    I've just started a new job, and find myself having to use a library that is written in the default package. At the moment, this is forcing me to put my classes in the default package whenever I want to use this library.
    using a line like:
    import RowBean;
    I get the following compiler error:
        [javac] C:\work\coyote\src\java\com\sok\coyote\Grievance\GrievanceActionServlet.java:8: '.' expected
        [javac] import RowBean;I've tried classic,modern and jikes - all with the same error.
    Eclipse seems to compile this happily, but I've been unable to find what it does to compile it.
    any ideas?
    cheers
    dim

    This works for me in 1.3.1_07
    DefaultPackage
    public class UseMe
         public static final String test = "Yes";
    }Package = fun
    package fun;
    import UseMe;
    public class Fun
         public static void main( String[] args )
              System.out.println( UseMe.test );
    }

  • How to extend a class in same package

    I have a class called LoginBean.java which extends the class ConnectDB.java
    this both files have a statement both the classes are under the directory pmtools.
    and both are included in package pmtools.
    (they both have statement "package pmtools; " at top)
    when i am trying to compile LoginBean.java, it is giving me following error,
    LoginBean.java:7: cannot resolve symbol
    symbol : class ConnectDB
    location: class pmtools.LoginBean
    public class LoginBean extends ConnectDB
    ^
    LoginBean.java:59: cannot resolve symbol
    symbol : variable dbConn
    location: class pmtools.LoginBean
    stmt = dbConn.createStatement();
    ^
    2 errors

    did you compile the other class already? donnow if ithahahaha!!!!!
    ok include the import statement
    import pmtools.ConnectDB;
    in the second class and than compile..

  • How to extend a class from super package?

    Say I have a dir a\
    in dir a\ there is a dir b\
    in b\ there is a class called DerivedClass
    in a\ there is a class called ExtendedClass
    how do I extend ExtendedClass from DerivedClass?

    package a.b;
    import a.ExtendedClass;
    public class DerivedClass extends ExtendedClass{
        //define class members
    This is interesting. But the question is, how does java know where is package b??     By the classpath variable - the classpath is set to one directory above 'a'. When you say
         a.ExtendedClass, since the classpath is set to the immediate parent of a, it searches the child directories
         for a directory called 'a' and upon finding it, searches for a .class file 'ExtendedClass'.
         Similarly when you say a.b.DerivedClass, the search begins in the parent directory for a directory called a and then
         a directory 'b' inside it on finding which it searches for DerivedClass.class
    Alternatively you could have defined DerivedClass to be in package 'b'.     
         package b; //note the difference. Its b and not a.b
         import a.ExtendedClass;
         public class DerivedClass extends ExtendedClass{
             //define class members
         }in which case, you should set the classpath to
    1. a's parent directory
    2. a itself
    The parent directory cp is still required to locate a.ExtendedClass
    The fully qualified name of DerivedClass is b.DerivedClass
    Thus if #1 alone were present, since 'b' is not directly inside the parent directory,
    b.DerivedClass would never be found
    Hence the #2 is required-the search should start from the directory 'a' (as directory 'b' is inside 'a').
    therefore, a package is a directory.No, package is a very java specific thing and though logically package names should match directory names, they
    arent the same.
    cheers,
    ram.

  • Access default package

    Is it posible to access a class in default package from the some package called
    MyPackage
    if its not possible means why?
    thanx in advance

    why its not allowing to access?, is there practical
    problem to find the current folder while loading the
    classI guess it's to discourage from usage of the default package.
    You can't import the default package. It's not something that would be hard to implement. Classes in the default package were actually accessible in the first versions of Java.
    Kaj

  • Accessing Class not in the package by the Class in the Package.

    Hi All,
    I am using window my java application are located at
    c:\javaProg\completeReferance\......
    my Class path is set to c:\....
    Iexecute java application using
    java javaProg.completeReferance.MyProgramThe problem is when I wanted to use some other class which is not in any package I get the following error.(say class Car).
    C:\Users\pravin>javac c:\javaProg\completeReferance\SystemDemo2.java
    c:\javaProg\completeReferance\SystemDemo2.java:7: cannot find symbol
    symbol  : class Car
    location: class javaProg.completeReferance.SystemDemo2
                    Car object = new Car();
                    ^
    c:\javaProg\completeReferance\SystemDemo2.java:7: cannot find symbol
    symbol  : class Car
    location: class javaProg.completeReferance.SystemDemo2
                    Car object = new Car();
                                     ^
    2 errorsThis is my program ...package javaProg.completeReferance;
    public class SystemDemo2
         public static void main(String [] args)
              Car object = new Car();
    }Where should it place the class file for Car class.Can some one explains who to make the class from one package compitable with classes in default package or any other package.I hope this problem may be faced by lots of newbies.
    Appreciate your concern!
    Message was edited by:
    confused_in_java

    There's nothing wrong with it per se... but it has a
    number of pitfalls. Basically it's a hell of a lot
    more likely to go wring at runtime than the good ole
    "just put the class in a package and import the
    sucker properly" solution.Alredy implemented this now.
    That's what makes me shudder to see it in the
    (forgive me) shakey hands of a newbie... it's a bit
    like watching a tree year old trying to open a box of
    matches... if you've got any brains you push the
    rubber ducky in his hands and quietly secrete the
    matches in the cupboard above the fridge... and get
    yourself another beer whilste you're there.
    Christians don't drink on Sunday. So there's more for
    me.Thanks I wil remember this.
    I am about to put a new Thread I thought insted so putting a new thread I will ask it here.
    This Question is a bit wiered so please excuse me if you think this is foolish.
    I was just wonder that if we can put our package, which include classes offcourse at some web location, then this will be available to us from anywhere and can be shared all accross.
    So I am tring to dumb the package in a jarfile and place it at my webspace http://pravin.biz.ly/ how ever somehow i have problem doing it can any one help.
    Regards!!
    Pravin Dubey.
    Message was edited by:
    confused_in_java

  • Compiling java package class referring a default package class.

    I am trying to compile a java class having a package defination referring a java class with a default package.
    The code for the default package class is .
    public class Test{.
    public static void main(String[] args){
    System.out.println("Hello World!");
    This class compiles fine.
    I have another class called PackJava, whose code is :
    package test;
    import Test;
    public class PackJava{
    public static void main(String[] args){
    Test test = new Test();
    System.out.println("Hello World!");
    I have Test file in the windows path
    D:\development\packagetest\example
    and the PackJava java file in the path
    D:\development\packagetest\example\test
    I have set the CLASSPATH environment varibale as
    D:\development\packagetest\example;.
    When I try to compile the PackJava from the
    D:\development\packagetest\example path giving the command as
    javac -classpath . test\PackJava.java
    or
    javac -classpath %CLASSPATH% test\PackJava.java
    it gives me error,
    Do any of you have an idea of the parameter i should pass
    to the -classpath option
    Thanks

    There is a way around all this. The classes in the default packages need to implement an interface with the methods require. The interface can be in any package you want ie. com.work.around.interf.MyInterface1. Next, make this interface available in a Singleton. - The only catch here is that, the main method must reside in default package as well. And o, on start of main, instantiate the class you want and put it in the singleton. There after, you may refer to it from the singleton.
    Enjoy.

  • Using classes outside of the default package in OATS 12.3.0.1.0

    Hello,
    OpenScript - Version: 12.3.0.1 Build 376.
    The test fails when I use classes that are not in the default package.
    Here is a simple example:
    TempClass - in the default package, I can create new objects and use it's methods without any errors.
    AlienClass - in another package (which name is anotherPackage) of the same project, I import that package into the script.java but I get an exception while creating new class object:
    "An unexpected exception occurred in the script. Script section: Unspecified. Caused by: ClassNotFoundException occured. anotherPackage.AlienClass "
    import anotherPackage.*;
    public void run() throws Exception {
      TempClass tmp = new TempClass(); // no errors while creating
      info(tmp.generateMessage());           // this method works correctly
      AlienClass al = new AlienClass();
      /* here I've got error
      *An unexpected exception occurred in the script.
      * Script section: Unspecified.
      * Caused by: ClassNotFoundException occured. anotherPackage.AlienClass 
    There are no such problems in OpenScript Version: 12.2.0.1 Build 223.
    Could you help me, please?
    Best regards,
    Natalie

    Hi, Sri!
    It was not necessary to name the root package "lib" in previous versions of OpenScript (12.2.0.1, 9.X.X).
    Except the default package, my work project in 12.2.0.1 included one main user package named by the testing application (let's call it "myApp"). And other packages and classes were located there.
    For example:
    D:\Development\TestProject\myApp\core\DB.java
    D:\Development\TestProject\myApp\test\Test1.java
    D:\Development\TestProject\myApp\test\Test2.java
    D:\Development\TestProject\myApp\web\common\Authorization.java
    etc.
    Project with such structure worked in OpenScript 12.2.0.1 but doesn't work in 12.3.0.1.
    According to your advice I created a new package - D:\Development\TestProject\lib, moved "myApp" with all included packages and classes into that package and corrected import statements (like lib.myApp.core.* instead of myApp.core.*).
    And then no errors appeared! So thank you very much! But it's interesting, why behaviour of OpenScript concerning package's name has changed?
    As for example from the first message,  import statement was in the same place where OpenScript added others packages during creating a new project. I've just tried to save some space in the message
    The full script.java is:
    import oracle.oats.scripting.modules.basic.api.*;
    import oracle.oats.scripting.modules.browser.api.*;
    import oracle.oats.scripting.modules.functionalTest.api.*;
    import oracle.oats.scripting.modules.utilities.api.*;
    import oracle.oats.scripting.modules.utilities.api.sql.*;
    import oracle.oats.scripting.modules.utilities.api.xml.*;
    import oracle.oats.scripting.modules.utilities.api.file.*;
    import oracle.oats.scripting.modules.webdom.api.*;
    import oracle.oats.scripting.modules.adf.api.*;
    import anotherPackage.*;
    public class script extends IteratingVUserScript {
      @ScriptService oracle.oats.scripting.modules.utilities.api.UtilitiesService utilities;
      @ScriptService oracle.oats.scripting.modules.browser.api.BrowserService browser;
      @ScriptService oracle.oats.scripting.modules.functionalTest.api.FunctionalTestService ft;
      @ScriptService oracle.oats.scripting.modules.webdom.api.WebDomService web;
      @ScriptService oracle.oats.scripting.modules.adf.api.ADFService adf;
      public void initialize() throws Exception {
      public void run() throws Exception {
      TempClass tmp = new TempClass(); // no errors
      info(tmp.generateMessage());     // this method works correctly
      AlienClass al = new AlienClass();
      /* here I've got error
      *An unexpected exception occurred in the script.
      * Script section: Unspecified.
      * Caused by: ClassNotFoundException occured. anotherPackage.AlienClass 
      public void finish() throws Exception {

  • How to save library symbols' class files in packages that are not the default package?

    Hi,
    I perform the following in Flash CS5 with Flash Builder 4
    1) Create a new library symbol.
    2) Do a RightClick->Properties on the new symbol
    3) Check the options for "Export for ActionScript" and "Export in frame 1".
    4) I write a new name for my class "Class1" and click on the pencil icon "edit class definition" to edit the class.
    At this point my FlashBuilder 4 takes over and opens the "New ActionScript" dialog.
    4) I then click on Package-Browse to select a package e.g. com.mycompany.myfiles as the new class destination.
    The as file is created as com.mycompany.myfiles/Class1.as as everything seems just fine.
    5) I close the ActionScript file and back in Flash CS5 I RightClick on the symbol and select "Edit Class".
    At this time, FB4 suggests again to create the file, ignoring the fact that I already created it before.
    Do you know of a way I can make Flash CS5 remember where I created the file?
    Thanks.

    Hi,
    I didn't remove the project or delete any of the files.
    All I did was create the class file under a package that is not the default package. Then when I clicked on the Flash symbol's "Edit Class" It asked me again to create the same class file.
    Only if I create the class in the default package, it won't ask me to recreate it again.
    Bye,
      RaamEE-IL

  • Not  able to access default package classes in own package

    I created a class called Constant.java in default package(no package ).
    I have Connection.java in util package.
    I am trying to use the Constant.java in my Connection.java like below..
    public class Constant
         public static final String NEW = "01";
    package util;
    import Constant;
    public class Connection
    I am unable to compile the class Connection. My question here is Won't I able to access default package in my util package.. ?

    java_guy04 wrote:
    Djaunl , I understand.
    but, Will I able to access default package in my util package.. ? is this correct.No, you won't be able to use classes out of the "default" package.
    Because, AFAIK, if you use a classname that you haven't imported, Java automatically attempts to locate this class in the same package as the current class. It does not check the "default" package (unless that is also the current package), and since the "default" package does not have a package name, you can't import those classes either.

  • Default Table Interface Class - 0TPL_BAP_MASTER

    Hi there
    We are trying to determine which table interface class is used on the default 0TPL_BAP_MASTER web template.
    We have created our own web template, but one of the pieces of functionality delivered with the standard template is the sort (ascending/descending) functionality which is included as arrows on the table column headings. We would very much like to use this on our custom template, and believe it to be implemented in the table interface class, but are not sure what that class is.
    Anybody know the name of the class?
    Cheers,
    Andrew

    Hi Deepu,
         How are you?
    I got a error about 0TPL_BAP_MASTER, when we are exicuting webtemplates in my portal. Can you please tell me what may be the error and how to overcome with this error.
    Thanks,
    Surendra.

  • Work on FB4.5 and Flash5.5 simultanoiusly - lack of code hints and default package classes.

    Hi!
    I setup Flash Professional CS5.5 and FB4.5 to work together. I just followed this tutorial: http://www.adobe.com/content/dotcom/en/devnet/flash-builder/articles/sharing-projects-flas hbuilder-flash.html and almost all looks good, but unfortunately working in Flash Builder adding new Classes I do not have default package Classes accessible. This way I can not even declare Sprite, Array class and so on. In code hints I only gets my current package classes.
    I set the .fla project inside Flash CS5.5 with some folders as the package for my classes. It is for examle:
    com.myDomain.testProject where DocClass exists. By adding this path as the document for FlashCS5.5 all works great, I can easily run, debug movie in the Flash environment.
    Setting this project by 'Import'->'FlashBuilder-FlashBuilderProject'->'ProjectFolder' pointing to the .fla file it seems that the thing goes well. The project is set and even I had some problems with Document Class's name (it seems that Flash Builder need to have Document Class with the same name as the .fla flie) and renaming it I can run or debug it and it works.
    But if I try to add new class to the directory I end up with no code hints, and in fact no default package classes support. That means I get errors trying to create instance of any common class etc. In code hints I am only getting my package hints (look picture)
    Maybe I misunderstand of some package basics and did something wrong, but generally I don't want to put all my classes to the .fla location but to sort them up in specific folders cause I assume that the project is quite large.
    If you can help me, thanks in advance. You know messing up with the code is a part of the programmer nature, and when one finds the answer he feels like a king. When to deal with environments like that, there is never joy and hapiness, but in most occasions couple uncensural words in the end, and a glimpse on the watch - agrrrhh I lost so much time :/
    cheers

    upss, It seems the Flex sdk wasn't added automatically what I didn't noticed. Looked for errors in some other areas (as always)
    Thanks anyway:)

Maybe you are looking for

  • Finder and Spotlight no longer working

    Hi guys, Following the latest 10.4.3 update both Spotlight and Finder are refusing to work - no results are being returned, even having re-installed the 10.4.3 Common update. I have followed instructions to restart the Spotlight index/database, howev

  • Supress Selection of PNP LDB

    Hi experts,   How to supress the whole selection screen of PNP logical database with custom selection screen in report? Thanks&Regards, Karthi

  • Error in opening custom form

    Hi, I am getting this following error when I am trying to open a custom form which was developed by someone else. FRM 10102: Cannot attach PL/SQL library <library name i.e. .pll>. This library attachment will be lost if the module is saved. This .pll

  • My 10.5.8 won't update adobe flash.

    I have a macbook 105.8 and have no idea what is wrong, all the sudden my adobe is out of date and I can't view any videos on any of my browsers. I attempted to download the updated versions of adobeflash many times, but it won't download/ work. I don

  • Can Apple TV be used in Cayman Islands?

    Hi, I want to purchase Apple TV but before I do, I want to know if the subscriptions such as Netflix and HBO are available to users in Cayman Islands. Thanks!