Accessing a Class in a Package[in a dir]  via Different Directory

Hi,
I am trying to access a class belonging to a package in a directory via another class in a different directory.
However, there are problems.
Here is what I do:
I created a source file ProtectedTest2.java
package com.java.MyLesson.ch8;
public class ProtectedTest2
private int iN1, iN2;
public ProtectedTest2(){ }
public ProtectedTest2(int iA, int iB)
iN1 = iA;
iN2 = iB;
public String getNumbers()
return "Numbers are: "+iN1 +" and "+ iN2;
} After that, I compiled this file with javac -d C:\\MyUserClasses ProtectedTest2.java. There was no problem.
I then, created another source file TestPro2.java and imported ProtectedTest2 in TestPro
import javax.swing.JOptionPane;
import com.java.MyLesson.ch8.ProtectedTest2;
public class TestPro2 extends ProtectedTest2
public TestPro2()
ProtectedTest2 pro = new ProtectedTest2(8,12);
JOptionPane.showMessageDialog(null, p.getNumbers() );
public static void main(String args[])
new TestPro2();
System.exit(0);
} Then, I continue to compile TestPro2.java like this:
javac -classpath C:\\MyUserClasses TestPro2.java -- there was no problem, but when I try to execute
TestPro2, the error I got was :
Exception in thread "main" java.lang.NoClassDefFoundError: com/java/MyLesson/ch8/ProtectedTest2
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader . java:502)
I understand that the class loader will look into the classpath[current directory] if it cannot find the user- defined class [ProtectedTest2.class] in the standard and optional java packages. Why did the application raise error if I have specified the classpath for the ProtectedTest2.class [which is in C:\MyUserClasses] during the compilation of TestPro2.java ?
Can someone please correct me and tell me what is the mistake here ?
Thank you all! :-)

You need to have C:\MyUserClasses in the class search path both when compiling and running.
Where the compiler finds a depency class is not saved in the generated .class file, so the runtime is on its own when it needs to find it. If C:\MyUserClasses is not in the class search path, the runtime doesn't know that it should be looking for ProtectedTest2 there. In addition to MyUserClasses you want to search for classes in the current directory (the path ".") so the command to execute TestPro2 is:
java -classpath .;C:\MyUserClasses TestPro2
See also the document on how classes are found (if you already haven't)
http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html

Similar Messages

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

  • Why does protected access also allow access from classes in same package

    Having been asked the question and found myself unable to answer it, I wonder if anyone can explain the reasoning why protected access implies the default access as well?

    Sure:
    ---------- class A ------
    package pkg;
    public class A
    protected static int _a;
    private int _i;
    public A() { _i = _a++; }
    public String toString() { return "instance "+_i; }
    --------- class B ------
    package pkg;
    public class B
    public B() { A._a = 27; }
    --------- class C -----
    public class C extends pkg.A
    -------- class main ----
    public class main
    public static void main(String[] args)
    pkg.B b1 = new pkg.B();
    pkg.A a1 = new pkg.A();
    pkg.B b2 = new pkg.B();
    C c1 = new C();
    System.out.println("a1 is "+a1);
    System.out.println("c1 is "+c1);
    The above classes are legal and compile and when
    run, the output is:
    a1 is instance 27
    c1 is instance 27
    (Please note, this is just an example of what is allowed and why I'm curious as to the advantages of this permitted behaviour, NOT what I would ever write!)

  • 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

  • Accessing a class outside the package

    Hi friends !
    Suppose I have a class called InsidePackageClass which is placed under C:\Package and other called OutsidePackageClass that is placed directly under C:
    Suppose my classpath points to C:\ and I want to declare a OutsidePackageClass member variable in the class InsidePackageClass. This leads me to an error. The compiler complains that it can't find the OutsidePackageClass class.
    What's wrong ?
    C:\
    |-Package
    | |---------InsidePackageClass
    |-OutsidePackageClass
    Thanks in advance
    Cleverson

    Like this?
    File: C:\OutsidePackageClass.java
    [code]class OutsidePackageClass {
         static String attribute = "first";
         public OutsidePackageClass() {
    }[/code]
    File: C:\Package\InsidePackageClass.java
    [code]class InsidePackageClass {
         public InsidePackageClass() {
              OutsidePackageClass o;
    }[/code]
    To compileset CLASSPATH=C:\
    cd \Package
    javac ../OutsidePackageClass.java
    javac InsidePackageClass.javaNote, javac will not run with current directory C:\

  • Java file cannot access other class in same package???????

    I have written a bean as follows-------
    package CustTags;
    public class TomMovieBean
         private String movieName;
         private String movieDirector;
         public void setmovieName(String movieName)
              this.movieName = movieName;
         public String getmovieName()
              return this.movieName;
         public void setmovieDirector(String movieDirector)
              this.movieDirector = movieDirector;
         public String getmovieDirector()
              return this.movieDirector;
    Now i am writing a tag handler for my JSP custom tag as follows----------
    package CustTags;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import java.util.*;
    public class Dynamic extends TagSupport
         private List movieList;
         public void setmovieList(List movieList)
              this.movieList = movieList;
         public int doStartTag() throws JspException
              Iterator iterator = movieList.iterator();
              TomMovieBean TMBObj = null;
              try
                   JspWriter out = pageContext.getOut();
                   while(iterator.hasNext())
                        TMBobj = (TomMovieBean)iterator.next();
                        String movieName = (String)TMBObj.getmovieName();
                        String movieDirector = (String)TMBObj.getmovieDirector();
                        out.println(movieName+"...."+movieDirector+"<br>");
              }catch(Exception ex)
                   throw new JspException("Error in doStartTag()");
              return SKIP_BODY;
    Now when i compile Dynamic.java it shows foll. errors
    Dynamic.java:19: cannot resolve symbol
    symbol : class TomMovieBean
    location: class CustTags.Dynamic
    TomMovieBean TMBObj = null;
    ^
    Dynamic.java:27: cannot resolve symbol
    symbol : variable TMBobj
    location: class CustTags.Dynamic
    TMBobj = (TomMovieBean)iterator.next();
    ^
    Dynamic.java:27: cannot resolve symbol
    symbol : class TomMovieBean
    location: class CustTags.Dynamic
    TMBobj = (TomMovieBean)iterator.next();
    ^
    3 errors
    I am unable to comprehend why it can't recognize TomMovieBean despite the fact that its a public class and in the same package as that of Dynamic.java

    Is your classpath set correctly? I.e. does it point to the directory containing the CustTags directory?
    BTW, by convention, package names are written in lower case.

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

  • How to access a class file outside the package?

    created a two java files Counter.java and TestCounter.java as shown below:
    public class Counter
         public void print()
              System.out.println("counter");
    package foo;
    public class TestCounter
         public static void main(String args[])
              Counter c = new Counter();
              c.print();
    Both these files are stored under "D:\Test". I first compiled Counter.java and got Counter.class which resides in folder "D:\Test"
    when i compile TestCounter.java i got the following error message:
    D:\Test>javac -classpath "d:\Test" -d "d:\Test" TestCounter.java
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    2 errors
    what could be the problem. Is it possible to access a class file outside the package?

    ya that's fine..if we have two java files where both resides in the same package works fine or two java files which donot have a package statement also works fine. But my doubt is, i have a Counter.class which does not reside in a package and i have a TestCounter.class which resides in a package "foo", in such a scenario, how do i tell to the compiler that "Counter.class resides in such a path, please look at that and give me TestCounter.class". i cannot use import statement to import Counter.class in TestCounter.java because i donot have a package for Counter.java.

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

  • Weird Can not access class from outside package problem

    Hi, I have this problem and it seems the error message is very clear what the problem is but I did make the GeneralTestResult class PUBLIC already. What could be wrong? I did search for it but this is too general and didn't find any solution. Anyone can point out the problem? TIA.
    public abstract class GeneralTestResult
      public static int FAILING_THRESHOLE = 25;
      public abstract String getTestName();
      public abstract boolean isPassed();
      public abstract int getLeftEyeResult();
      public abstract int getRightEyeResult();
      public abstract Calendar getTestDate();
    // in a different file
    package VisionSaver.Tests.TestResults;
    import java.util.*;
    public class AcuityORContrastTestResult extends GeneralTestResult
      private String m_testName;
      private int m_leftEyeVision, m_rightEyeVision;
      private Calendar m_testDate;
    // in a different file
    package VisionSaver.Tests;
    import VisionSaver.Tests.TestResults.*;
    public class Acuity extends VirtualKeyboard implements ActionListener, Runnable, WindowListener
    AcuityORContrastTestResult r = new AcuityORContrastTestResult(...);
    }The compiling error is:
    "Acuity.java": GeneralTestResult() in VisionSaver.Tests.TestResults.GeneralTestResult is not defined in a public class or interface; cannot be accessed from outside package at line 529, column 40

    The GeneralTestResult class is a packaged class. Sorry, when I cut and paste, I didn't copy everything. So here is the complete GeneralTestResult file:
    package VisionSaver.Tests.TestResults;
    import java.util.*;
    public abstract class GeneralTestResult
      public static int FAILING_THRESHOLE = 25;
      public abstract String getTestName();
      public abstract boolean isPassed();
      public abstract int getLeftEyeResult();
      public abstract int getRightEyeResult();
      public abstract Calendar getTestDate();
    }From the compiler's message, it seems like the import is OK. It just won't allow me to access non-public class but my classes here are declared public. Any other ideas? TIA

  • 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

  • Problem with Dynamically accessing EJB Class objects in WL 7.0 SP1

    I am trying to build a component which has the ability to instantiate and execute
    an known EJB method on the fly.
    I have managed to build the component but when I try and execute it I get a ClassNotFoundException.
    I know that the EJB I am trying to invoke is deployed and available on the server,
    as I can see it in the console, I also seen to have been able to get the remote
    interface of the object, my problem occurs when I try and access the class object
    so I can perform a create on the object and then execute my method
    The code I have written is below:
    private Object getRemoteObject(Context pCtx, String pJNDIName, String pHomeBean)
    throws Exception {
         String homeCreate = "create";
         Class []homeCreateParam = { };
         Object []homeCreateParamValues = {};           
    try {  
    //This call seems to work and doesn't throw an exception     
    Object home = pCtx.lookup(pJNDIName);
    //However this call throws a java.lang.ClassNotFoundException
    Class homeBean = Class.forName(pHomeBean);
    Method homeCreateMethod = homeBean.getMethod(homeCreate,homeCreateParam);
    return homeCreateMethod.invoke(home, homeCreateParamValues);
    } catch (NamingException ne) {             
    logStandardErrorMessage("The client was unable to lookup the EJBHome.
    Please make sure ");
    logStandardErrorMessage("that you have deployed the ejb with the JNDI
    name "+pJNDIName+" on the WebLogic server ");
    throw ne;
    } catch (Exception e) {
    logStandardErrorMessage(e.toString());
    throw e;     
    Any advice would be really appreciated, I'm fast running out of ideas, I suspect
    it has something to do with the class loader but I'm not sure how to resolve it
    Regards
    Jo Corless

    Hello Joanne,
    Congratulations! I'm very happy that you've managed to fix your problem. It's
    always essential to understand how to package applications when deploying on BEA
    WebLogic. Usually, by throwing everything into an EAR file solves just about all
    the class loader problems. :-) Let us know if you have any further problems that
    we can assist you with.
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "Joanne Corless" <[email protected]> wrote:
    >
    >
    I've fixed it!!!!!!!!
    Thanks to everyone who gave me help!!!!
    The class loader was the culprit which is what I suspected all along.
    As soon
    as I put the 2 jar files I was using into an EAR file the problem went
    away!!!!!
    Thanks again
    Jo Corless
    "Ryan LeCompte" <[email protected]> wrote:
    Hello Joanne,
    As Mr. Woollen mentioned, I also believe it's a problem with the class
    loader.
    You need to be careful how you arrange your EJBs, because WebLogic has
    a specific
    method in which it loads classes in an EAR, JAR, and WAR file(s). Please
    refer
    to http://dev2dev.bea.com/articles/musser.jsp for more information about
    BEA WebLogic
    class loading mechanisms and caveats. Also, try printing out the various
    methods
    that are available on the object that was returned to you via reflection.
    For
    example, use the getMethods() method, which returns an array of Method
    objects
    that you can subsequently cycle through and print out the various method
    names.
    This way you can discover if the class found/returned to you is indeed
    the one
    you intend to locate.
    Hope this helps,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    Rob Woollen <[email protected]> wrote:
    I believe the issue is the home interface class for this EJB is not
    available in the class loader which is doing the reflection.
    If you do:
    getClass().getClassLoader().loadClass(homeInterfaceClassName)
    I suspect it will fail. Reflection still requires that the class be
    loadable.
    -- Rob
    Joanne Corless wrote:
    Hi Slava,
    If I make my code look like you describe below I get a compliationerror telling
    me that
    home.getMethod() is not recognised (no such method)
    If I change it slightly and use
    Method homeCreateMethod =
    home.getClass().getMethod(homeCreate,homeCreateParam);
    The code will compile OK but when executed it still throws a NoSuchMethodException
    Any ideas ?
    Thanks for your help so far
    Regards
    Jo Corless
    Your code should look like
    Object home = pCtx.lookup(pJNDIName);
    Method homeCreateMethod =
    home.getMethod(homeCreate,homeCreateParam);
    return homeCreateMethod.invoke(home, homeCreateParamValues);
    Regards,
    Slava Imeshev
    "Joanne Corless" <[email protected]> wrote in message
    news:[email protected]...
    Hi Ryan,
    I also wanted to mention that if you do a "header search" in this
    particular
    newsgroup
    with the search query as "reflection", you will see many previousmessages
    regarding
    reflection and EJBs. I believe you could learn a lot from thedifficulties
    that
    others have faced and solved.I tried that and although there was a number of similar cases noneof them
    actually
    seem to fix my issue. Thanks for the suggestion though
    Are the EJBs that you are trying to access accessible via your
    system
    classpath?
    Try to avoid having them accessible via the main system classpath,and
    only bundle
    them in your appropriate EJB jar files (contained in an EAR file,for
    example).Maybe I should have laid the problem out a little clearer.
    I have a number of EJB's bundled up in a JAR file which is hot deployedto
    the
    server. Within this first JAR file is an EJB (SSB) component that
    needs
    to
    be
    able to invoke a known method on another EJB. This second EJB may
    or
    may
    not be
    within the first JAR file but it also will be hot deployed.
    The component trying to invoke the method on the 2nd EJB has to
    be
    able to
    create
    an instance of the 2nd EJB without actually knowing anything bar
    a
    JNDI
    Name which
    is passed in at runtime.
    I can get as far as doing the
    Object home = pCtx.lookup(pJNDIName);
    This returned a class with the name
    "com.csc.edc.projects.allders.httppostoffice.postman.PostmanBean_mp8qy2_Home
    Impl_WLStub"
    My problem seems to occur when I try and invoke the create method
    Method homeCreate = home.getClass().getMethod("create", new Class[0]);
    My code throws a java.lang.NoSuchMethodException at this point so
    I
    am
    unable
    to progress to the next step of :
    Object bean = homeCreate.invoke(home, null);
    So I can return the instantiated bean back to the calling client.
    Why am I getting the NoSuchMethodException, is is because I am gettinga
    stub
    back rather than the home interface and if so how do I get the truehome
    interface
    from the bean
    Thanks in advance
    Jo Corless

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

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

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

Maybe you are looking for

  • How is it possible to add title to each photo in Spry photoalbum?

    I've created an album with spry as it is shown in the tutorial, but I want every large photo to have a title below. Not the file name but title which could tell some facts about the photo. Is it possible to do using that template? Thanks.

  • New To Oracle.. Needs Help:: Conversion from SQL Server to Oracle 11g

    I am new to Oracle 11g and badly need the conversion of SQL Server Functions to Oracle.. Sample Pasted Code not working .. end with error.. pls help Create Table TempT (ID1 Varchar (10), ID2 Varchar (10) CREATE OR REPLACE PACKAGE GLOBALPKG AS TYPE RC

  • Lumia 1520 firmware update

    I have Lumia 1520 RM-937 with firmware revision 1028.3534.1343.0001, my product code is 059V3K1. When am I going to get new firmware update, which is as I found on internet 1028.3562.1402.00xx? Thanks.

  • J2EE_WSIL

    Dear All, One of my CAF Web Service which is used in VC by the web service system J2EE_WSIL (defined in Visual Admin) is not getting updated even after I change the web service operation's signature and deployed it in PNW. When I test the web service

  • How does ORDImage.processCopy() works ?

    Hi, I'm using Oracle 10g r2. I need to show ORDImages (and BLOBs). Here is my procedure that shows thumbnails : create or replace procedure show_photo_thumbnail(v_id_photo in number, v_height in number, v_width in number) as      obj ordsys.ordimage;