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.

Similar Messages

  • How to import a class from a package at the same level

    Hello friends,
    i have a class as Plaf.java
    as
    package org.vaibhav.swing.plaf;
    import java.awt.*;
    import javax.swing.*;
    public class Plaf {
    other code
    }as you see, this is in org.vaibhav.swing.plaf package.
    I have one more class as
    package org.vaibhav.swing.frames;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class StartFrame extends JFrame implements ActionListener {
    other code
    }and this class is in package org.vaibhav.swing.frames
    Please hlp me how to use the class Plaf in StartFrame.java. Rather what import statement should i use in StartFrame.java.
    please help.
    thank you
    Message was edited by:
    vaibhavpingle

    but it then gives me this error
    StartFrame.java:11: package org.vaibhav.swing.plaf
    does not exist
    import org.vaibhav.swing.plaf.*;
    Have you first compiled Plaf.java and saved it in this directory strucuture
    /org/vaibhav/swing/plaf/
    And also have you set your classpath to the parent directory of org folder.
    Message was edited by:
    qUesT_foR_knOwLeDge

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

  • Question about access non-public class from other package.

    Hi, everyone!
    Suppose class A and class B are in the same java file of package pkg1
    -- A.java. So, A is a public class and B is a non-public class.
    If I want to access class B from another class class C and class
    C is in package pkg2. When compiling, an error occurs indicating
    that class B is not visible to class C.
    So, If I defined serveral classes in one java file and I want to
    access every class from other package. How should I do?
    (I think in one java file, there should be only one public class and
    only the public class can be accessed from other package.)
    Thanks in advance,
    George

    So, If I defined serveral classes in one java file and
    I want to
    access every class from other package. How should I
    do? As you already seem to know, there is at most one public class allowed per source file (at least, with javac and most popular compilers). So if you want more than one public class, you will need to use more than one file...

  • Anyone know how to find available classes in a package?

    Anyone know how to find available classes in a package?
    Given a String like "java.io" I would like to write a method to extract the available classes in this package. I can't seem to find a method for this anywhere in the docs. The package class does not seem to have a method like this.

    Here is some code I tried.
    I'm not very familiar with manipulating JARs The code below is what I tried, but how do I access the packages like "java.io" in the JarFile? and then get the available classes?
    import java.io.*;
    import java.util.*;
    import java.util.jar.*;
    class Tester
         public static void main(String args[])
              try {
                   JarFile jf = new JarFile("c:/jdk1.3/lib/dt.jar");/* usually rt.jar (and 1.4)*/
                   Enumeration e = jf.entries();
                        while (e.hasMoreElements())
                             Object current = e.nextElement();
                             System.out.println(current.toString() + "class:"+current.getClass());
                             try {
                                  Thread.sleep(300);
                             } catch (InterruptedException ie) {}
              } catch (IOException ioe) {System.out.println(ioe.toString());}
                   /*also tried      ClassLoader cl = ClassLoader.getSystemClassLoader();
              try {
                   Enumeration e = cl.getResources("c:/jdk1.3/lib/dt.jar");
                   System.out.println(e.nextElement());
                   while (e.hasMoreElements())
                   System.out.println(e.nextElement());
              } catch (IOException ioe) {System.out.println(ioe.toString());}

  • How to load java class from jsp page?

    hi all!
    Does anyone know how to load java class from jsp page?
    I try to load java class from jsp page.
    Is it possible to load java class fom jsp page?
    thanks and have a good day!

    What I mean is How to load/open java class file from jsp page?
    I think we can open Applet from jsp page by using
    <applet code=helloApplet.class width=100 height=100>
    </applet>
    but, how to open java class which is an application made by Frame?
    thanks and have a good day

  • How to call Java class from Forms 6i?

    Hi friends,
    I need to call a Java class from my Forms 6i application.
    (It runs under WIndows XP. It's a client/server application and I have only the client and the Form builder installed on my PC)
    I don't know almost anything about Java's world so your help would be very useful for me.
    Could you tell me exactly what i have to do?
    I've read in metalink several Notes, but they supposed that the Java architecture is already installed in the computer.... I only have the default installation of Developer 6i... so I would need to know:
    - How to install/configure the neccesary to execute Java classes without problem
    - How to invoke the .class from Forms 6i.
    Thanks a lot
    Jose.

    And also this one:
    Problem Description
    Installed Forms 6i Rel 2 on a MS Windows machine. When trying to Import the Java
    Classes getting the errors
    PDE-UJI0001 Failed to create the JVM
    Solution Description
    You need to to install JDK 1.2.2 to run the Java Importer. And set the PATH's
    and classpath's correctly.
    Explanation
    1. Download and install the JDK 1.2.2.
    Possibly available at: http://java.sun.com/products/archive/
    2. Assuming the JDK 1.2.2 is installed in c:\jdk1.2.2 directory and the JRE in
    C:\PROGRA~1\JAVASOFT\JRE\1.2 directory; ORACLE_HOME=C:\Dev6iR2.
    Set the PATH to
    set PATH=c:\jdk1.2.2\bin;C:\PROGRA~1\JAVASOFT\JRE\1.2\bin;C:\PROGRA~1\JAVASOFT\JRE\1.2\bin\classic;%PATH%
    ( If you are using ias9i then the JDK 1.2.2 comes with the ias installtion ,
    in this case please set the PATH to
    D:\ias9i\Apache\jdk\bin;D:\ias9i\Apache\jdk\jre\bin;D:\ias9i\Apache\jdk\jre\bin\classic;%PATH% )
    3. Set the CLASSPATH to set CLASSPATH=%CLASSPATH%;C:\Dev6iR2\TOOLS\COMMON60\JAVA\IMPORTER.JAR;.
    (If you do not set the CLASSPATH correctly you will get the error
    PDE-UJI002 Unable to find the required java importer classes)
    4. Now run the Forms Builder by using the command.
    C:\Dev6iR2\bin\ifbld60.exe
    Now the Java Importer Should Run fine.
    Francois

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

  • How do I move objects from other package to a newly created one?

    How do I move objects from other package to a newly created one?
    Thanks!

    Dear Anthony Pham ,
    for changing objects from one package to another package
    open that object for example Report
    open the report and than click GOTO select OBJECT DIRECTIORY ENTRY
    than it will open a popup in that popup click the change and give the new package
    Thanks
    Surendra

  • How to instantiate a class from a different package?

    I am trying to instatiate a class in a package: a.b.c from another class in a different package: d.e.f
    How could I do so?
    I've already been trying many things but didn't manage to get it to work...

    Did you include both jar files in your classpath? Use
    the -cp option of the java interpreter to specify your
    classpath.Well, I tried adding the jar file to the classpath, without any success...
    String path = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
                   String finpath = "";
                   for(int i=6;i<path.length();i++)
                        finpath = finpath+path.charAt(i);
                   System.setProperty("java.class.path",System.getProperty("java.class.path")+";"+finpath+"mm.mysql-2.0.14-bin.jar/");That's what I did and it didn't work...
    If you "unpack" the jars see if there is the correct
    packages-folders symmetry...Yes, the classes are in the package-folders they should be in..

  • How to return a list of class from a package

    Hi,
    I'm trying to create a RPG game with 50 characters. There will be a superclass, and each character is a subclass that extends from the superclass. Each will have unique abilities that will be functions. These classes will be thrown into a package.
    I would like to know the code for returning the list of classes in that package. That way, I can present them as a list for the player to choose just a handful of characters to start out with.
    Thanks in advance         

    Hi u can use the this class
    flash.utils.describeType;
    Regards
    Sumit Agrawal

  • How to refer to root class from a package in Java 1.4

    Hi
    I have written a class at root level and it is being called be a different class which is defined in a package, when I am trying to import base class it is giving compilation error in Java 1.4.0 and Java 1.4.1 version but code work fine with java 1.2.2
    For you reference here is sample code
    First class AddNumbers defined at root
    public class AddNumbers{
         int iResult=0;
         public AddNumbers(int a, int b){
              iResult= a+b;
         public int getSum(){
              return iResult;
    second class PlayNumbers is defined in package TreeTest
    package TreeTest;
    import AddNumbers;
    public class PlayNumbers{
         int iNum1 =5;
         int iNum2 = 10;
         int iRes;
         public PlayNumbers(){
              AddNumbers ad = new AddNumbers(iNum1,iNum2);
              iRes = ad.getSum();
              System.out.println("Result is ="+iRes);
    public static void main(String [] arg){
              new PlayNumbers();
    Could anyone suggest how to invoke AddNumbers class in JDK1.4.1
    Thanks
    AKM

    The root package should never have been automatically included for compilation purposes.
    In order to access a class in the root package import it as you should for any other class.
    import AddNumbers;
    is the proper way to do this.
    The only time you don't need to use an import statement is if the class you wish to reference is in the same package as the class that refers to it. Again, you should really import such classes as it makes things explicitly clear which classes you are referring to.

  • How to run a java class from its package directory

    Hi,
    I hope someone can help me on the following ....
    Let say I have a Test.java class with the package definition: "package com.ams.eai.mq.fileAdapter;". I compiled the class into the directory c:\myJava\client\com\ams\eai\mq\fileAdapter. I have c:\myJava\client specified in my classPath and Path. Why is it when I go to the mentioned directory and enter at the prompt >java Test, I get java.lang.NoClassDefFoundError: test (wrong name: com/ams/eai/mq/fileAdapter/test).
    What directory am I supposed to be in to run my Test class ? Is there some other path that I need to specify but didn't ?
    Thanks for any help.

    You have to type out the fully qualified class name:
    java com.ams.eai.mq.fileAdapter.Test
    Even if you had the entire dir structure, "c:\myJava\client\com\ams\eai\mq\fileAdapter" in your classpath you'd still have to fully qualify the name of the "Test" class. What if there was another class named "Test" in a different package in your CP? The VM would have no way of knowing which "Test.class" you'd want to run.

  • How do I find classes in a package

    Hi,
    I am working on an automation tool which is to be used for testing public API's in our product. The tool is supposed to work this way:
    1. A developer of the API adds a new java file containing the test code for the API in a particular package (which the tool defines). Then he compiles and places the stuff in a jar. There is also a driver class in this same package path defined by the test tool. E.g.
    driver class: com.aaa.bbb.DriverClass
    new API test file: com.aaa.bbb.TestFile
    Now the driver file's job is to find out all the other classes in this particular package and then do some processing. When I tried doing the getPackage() on this driver class to find out about the package I got back a null.
    Question 1: How can I get the package for a particular class (An ugly way to do this would be to strip it out from the classname)
    Question 2: How can I find out what other classes are there in a package?
    Thanks in advance on this.
    Nikhil Singhal
    You can also send me mails at
    [email protected]

    hai
    i have the same problem to finding the classes in package...
    in my case i know the jars name and i have loaded
    classes using code
    ResourceBundle bundle = ResourceBundle.getBundle("source\\ClasssPath");
    StringTokenizer stToke = new StringTokenizer(bundle.getString("ClassPath"),";");
    String temp;
    ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    while(stToke.hasMoreTokens())
         temp = stToke.nextToken().trim();
    if(temp.endsWith(".jar"))
    JarFile jar = new JarFile(new File(temp));
         Enumeration en = jar.entries();
         String pathStr;
         while(en.hasMoreElements())
         pathStr = en.nextElement().toString();
         System.out.println("pathStr ="+pathStr);
         if(pathStr.endsWith(".class"))
              System.out.println( classLoader.getResource(pathStr));
              System.out.println(classLoader.loadClass(pathStr.substring(0,pathStr.indexOf(".class")).replace('/','.').trim()));
         else classLoader.loadClass(temp);
    here i am getting the classes in that package using code
         String[] filLis = new File("//it//sella//converter//ptlf//startup//").list();
         int length = filLis.length;
         while(length-- >0)
         System.out.println(">"+filLis[length]);
    but its returnign the class when this classes in locale folder(i.e)its not getting the classes in loaded memory...
    so how to retrieve the class files names using package structure name...
    (i am having more then 20 jars files, inthat inside the jar samepackage structue may appear in more then one jars )
    pls help me in this field..
    Thanx

  • How to Access a class outside a package which is friendly to the package

    Hi All,
    i hav a class which has friendly scope in package X. how do i access it from a class in package Y without declaring it as public.
    Rgds,

    Hmm. If it is friendly in X, you can access it only from X. There is no way you can access it from Y.

Maybe you are looking for