Find classes in a package

I'm new to java. What's the best way to find all classes in a standard package (e.g. java.awt). I'm trying to create a list for classes in a package in java.
thanks

I guess you're talking about finding them in a running program (like scanning).
Well, I'm searching a solution for a similar problem.
Unfortunately, java classes are loaded on demand. That is, if you're not using kung.foo.MyClass in your code, its not known by the vm, so you can't find it using VM calls.
Since this behavior is the same for packages, you can test this behavior if you're scanning packages using Package.getPackages():
public class PackageTester {
  // drops the package info on screen.
  public static void listAll (String message , Package [] data) {
    System.out.println ( ) ;
    System.out.println ( message) ;
    System.out.println ( "Amount of passed classes : "+data.length) ;
    for (int i = 0 ; i < data.length; i++)
          System.out.println ( data.toString()) ;
public static void main (Strinbg [] args) {
// get a list of all known packages
Package [] state1 = Package.getPackages() ;
// load a yet unknown class
MyClass kong.foo.myClass = new kong.foo.MyClass () ;
// reload all packages
Package [] state2 = Package.getPackages() ;
// print lists to screen
listAll ("packages before loading MyClass" , state1) ;
listAll ("packages after loading MyClass" , state2) ;
Didnt check, but the code should compile.
This means that, if you want to scan for classes in the vm, you'll have to say the vm which classes you're scanning for. Of course, this is nonsense.
The most complete way is to scan all files starting at the classpath-entries, and looking for .class-files in directories and .jar/.zip-files. This is much work to do, but it seems to be the only useful solution to solve this nasty problem. You could use tools, which surely are available; but its not an elegant solution.
Sorry.

Similar Messages

  • 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

  • Cannot find class in same package but in different file

    I have following two source files. Both the file has same package statement as below
    package java.buron.doeacc ;
    But whenever i try to compile File: shoepolish.java ( mainfram.java compiled succesfully before)
    following error message appear
    ..\..\buron\doeacc\shoepolish.java:12: cannot resolve symbol
    symbol : class MainFrame
    location: class java.buron.doeacc.shoepolish
              MainFrame mainFrame = new MainFrame();
    ^
    ..\..\buron\doeacc\shoepolish.java:12: cannot resolve symbol
    symbol : class MainFrame
    location: class java.buron.doeacc.shoepolish
              MainFrame mainFrame = new MainFrame();
    ^
    Please tell me What is the problem and how it can be solved.
    why cannot find the class that are in same package.
    I have JDK 1.3
    FOLLOWING ARE THE TWO FILES
    File: mainframe.java/////////////////////////////////////////////////////////////////////
    package java.buron.doeacc ;
    import javax.swing.* ;
    import java.awt.*;
    import java.awt.event.* ;
    class MainFrame extends JFrame
         private final String APP_NAME = "Shoe Polish";
         // constructor
         public MainFrame()
              super("Shoe Polish");
              setSize(500, 500);
              setVisible(true);
    File : shoepolish.java
    package java.buron.doeacc ;
    import java.io.* ;
    import java.buron.doeacc.* ;
    class shoepolish
         public static void main(String args[])
              MainFrame mainFrame = new MainFrame();

    The javac compiler uses the Classpath to find classes. If your directory structure is c:\myjava\buron\doeacc (for example) then you need to have c:\myjava in the Classpath when you compile. For example javac -classpath c:\myjava MainFrame.java

  • How to find classes in the package if package path

    in java i want to find classes,Interface,Exception names which are presant
    in the package..
    for example
    java.sql; if i give this it should return
    class name
    Date
    Time
    DrivarManager
    pls helpme in this field

    download the jdk documentation or view it here
    http://java.sun.com/j2se/1.3/docs/api/index.html
    The exact problem is i hava set the path to my application that path contains several jar's(contains classes,Interfaces) and classes with package structure,
    now my need is if i run the application ,the application
    should find out the classes and Interfaces for given package structure which are present in classpath...
    for this i have to load all the classes to memory(using classes loader) . then find out the classes which are present in memory...
    or
    any other inbuilt method is there in java when i give path structure it find and give classes which are in class path..
    for ex..
    if i set path to jdk
    then if i give the path like java.lang
    it should give me the out put as
    String (or) String.class
    Double
    Cloneable
    (classes & interface in that package)

  • How to find classes in a particular package?

    Does anyone know how in Java to find out what classes belong to a particular package? Or to find out what classes inherit from a particular class?
    The reason why I'm asking this is that I want to create a BeanInfo property editor for a widget that will give me a list of any classes in a particular package. I know what that package can be and I know what the main class is that everyone should inherit from. I can easily create a beaninfo property editor with a string array of the classes, but I don't want to have to go back and maintain this code everytime I add another class to that package. I would love to use introspection but I haven't found the right commands to use yet.
    Anyone have any ideas?
    Thanks!

    Not too difficult, the following snippet is used to gather information about a class. beanClass can be parsed to extract package name. and you ask the class directly about its superClasses and implemented Interfaces.
        private Class beanClass = null;
        private Class beanSuperClass = null;
        private Constructor[] constructors = null;
        private Field[] fields = null;
        private Method[] methods = null;
        private Object beanInstance = null;
        public setBeanDetail(Object o) {
            beanInstance = o;
            beanClass = o.getClass();
            beanSuperClass = beanClass.getSuperclass();
            constructors = beanClass.getConstructors();
            fields = beanClass.getDeclaredFields();
            methods = beanClass.getMethods();
        }have loads of fun with it.
    tj...

  • 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 find (classes,interface,subpackage info) in some package

    Plz tell me if any one know how to find (classes,interface,subpackage) in some package
    e.g. in java.io
    "Above senerio in not concern with java doc
    but tell me if an other way i.e by help of programming
    i could find some package information"
    as we know we find out any "object" classType , methods and fields information with help of "java.lang.reflect" API's
    but how to find a package information as provided by jdk is in current use

    You can locate the .zip or .jar file where the stuff is, and say either
    unzip -l classes.zip
    or
    jar tvf classes.jar.
    So you see the list of the classes in the given package.
    Then you can say
    javap -classpath classes.zip MyPackage.MyClass
    to see the fields and methods of the given class.

  • Cannot find symbol symbol : class Item location: package platypos.services.

    Well, I am having a few problems getting this java file to compile.
    /home/brandon/Desktop/platypos/services/order/Seat.java
    package platypos.services.order;
    import platypos.services.order.Item;
    import java.util.Vector;
    public class Seat
        private int             _number;
        private Vector<Item>    _items  = new Vector<Item>();
        public static void main(String args[])
            System.out.println("Hello");
    }here is my terminal session:
    brandon@Aspire5100:~$ javac /home/brandon/Desktop/platypos/services/order/Seat.java
    /home/brandon/Desktop/platypos/services/order/Seat.java:17: cannot find symbol
    symbol  : class Item
    location: package platypos.services.order
    import platypos.services.order.Item;
                                  ^
    /home/brandon/Desktop/platypos/services/order/Seat.java:23: cannot find symbol
    symbol  : class Item
    location: class platypos.services.order.Seat
        private Vector<Item>    _items  = new Vector<Item>();
                       ^
    /home/brandon/Desktop/platypos/services/order/Seat.java:23: cannot find symbol
    symbol  : class Item
    location: class platypos.services.order.Seat
        private Vector<Item>    _items  = new Vector<Item>();
                                                     ^
    3 errors/home/brandon/Desktop/platypos/services/order/Item.java is packaged as follows
    package platypos.services.order;and has been successfully compiled to Item.class in the same directory.
    I am using the latest JDK on Ubuntu 8.04
    I am a bit more skilled in C++ and am trying to learn java, anyone got any clues as to what I am doing wrong?
    Thank you

    yep, here is an abridged version of the Item.java file. and it has been successfully compiled to Item.class
    package platypos.services.order;
    import java.util.Vector;
    class Item
         // Constructor     
         public Item(String name)
              SetName(name);     
        // Main Function
        public static void main(String args[])
    }Edited by: javaperson on Apr 30, 2008 11:01 PM

  • Cannot find class CustomerFacadeRemote in NetBeans IDE 5.0 Quick Start Guid

    Hi,
    I am new to Sun Java Studio Enterprise 8.1. I am follwing NetBeans IDE 5.0 Quick Start Guide for J2EE Applications example and got two following errors:
    C:\SunStudioWS\CustomerBook\CustomerBook-war\src\java\web\CustomerDetail.java:41: cannot find symbol
    symbol : class CustomerFacadeRemote
    location: package ejb
    ejb.CustomerFacadeRemote custFacade = lookupCustomerFacadeBean();
    C:\SunStudioWS\CustomerBook\CustomerBook-war\src\java\web\CustomerDetail.java:41: cannot find symbol
    symbol : method lookupCustomerFacadeBean()
    location: class web.CustomerDetail
    ejb.CustomerFacadeRemote custFacade = lookupCustomerFacadeBean();
    2 errors
    C:\SunStudioWS\CustomerBook\CustomerBook-war\nbproject\build-impl.xml:299: The following error occurred while executing this line:
    C:\SunStudioWS\CustomerBook\CustomerBook-war\nbproject\build-impl.xml:141: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 1 second)
    Here is the code:
    * CustomerDetail.java
    * Created on July 23, 2007, 3:27 PM
    package web;
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * @author yl
    * @version
    public class CustomerDetail extends HttpServlet {
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet customerDetail</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Servlet customerDetail at " + request.getContextPath () + "</h1>");
    String customerNr = request.getParameter("customer_nr");
    if((customerNr != null) && !(customerNr.equals("")))
    try{
    ejb.CustomerFacadeRemote custFacade = lookupCustomerFacadeBean();
    out.println("Customer's info for nr. " + customerNr + ": " + custFacade.getCustomerInfo(
    Integer.parseInt(customerNr)));
    }catch(javax.ejb.FinderException ex){
    out.println("Customer with nr. " + customerNr +" not found");
    out.println("<form>");
    out.println("Customer number: <input type='text' name='customer_nr' />");
    out.println("<input type=submit value=Select />");
    out.println("</form>");
    out.println("</body>");
    out.println("</html>");
    out.close();
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    /** Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
    return "Short description";
    // </editor-fold>
    private web.ServiceLocator serviceLocator;
    private web.ServiceLocator getServiceLocator() {
    if (serviceLocator == null) {
    serviceLocator = new web.ServiceLocator();
    return serviceLocator;
    private ejb.CustomerFacaderRemote lookupCustomerFacaderBean() {
    try {
    return ((ejb.CustomerFacaderRemoteHome) getServiceLocator().getRemoteHome("java:comp/env/ejb/CustomerFacaderBean",ejb.CustomerFacaderRemoteHome.class)).create();
    } catch(javax.naming.NamingException ne) {
    java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
    throw new RuntimeException(ne);
    } catch(javax.ejb.CreateException ce) {
    java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ce);
    throw new RuntimeException(ce);
    } catch(java.rmi.RemoteException re) {
    java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,re);
    throw new RuntimeException(re);
    Thank you very much for any help.
    ylou

    In the code you have posted, some places refer to '.CustomerFacader' while others refer to '.CustomerFacade' leading to issues.
    Also: Have you considered using NetBeans 5.5.1 as an alternative to JSE 8.1?
    http://forum.java.sun.com/thread.jspa?threadID=5192837

  • Error(2): Unable to find class for bean: connection defined by tag...

    I created a project, and a JavaBean that connects to the database and I want to use it in a JSP page that exists in my project.
    Bean:
    package BeerPackage;
    import java.sql.*;
    public class ConnectionBean
    JSP:
    <%@ page import="BeerPackage.*" contentType="text/html;charset=windows-1252"%>
    <jsp:useBean id="connection" class="ConnectionBean" scope="session"/>
    Then I get the error:
    Error(2): Unable to find class for bean: connection defined by tag with class: ConnectionBean
    When I try to build the JSP
    Any ideas?

    Seems even though I have an import, I still have to specify the package name in front of the useBean.
    What am I missing here?

  • Compiling JSP within a WAR cannot find classes

              I have developed a WAR file containing a trivial JSP that simply invokes functionality contained within
              a Java class. The WAR file is registered without a problem, and unpacks my libraries and classes to
              C:\weblogic\myserver\_tmp_war (jar files & top-level package dirs are in the root). When I invoke the
              JSP, the code is generated correctly within C:\weblogic\myserver\_tmp_war\jsp_servlet. However the
              compiler fails to find the class referenced by the JSP, and the following error is logged.
              java.io.IOException: Compiler failed executable.exec([Ljava.lang.String;[javac, -classpath, C:\weblogic\myserver\serverclasses;C:\weblogic\jre1_2\jre\lib\rt.jar;C:\weblogic\jre1_2\jre\lib\i18n.jar;C:\weblogic\classes\boot;C:\weblogic\eval\cloudscape\lib\cloudscape.jar;C:\weblogic\license;C:\weblogic\classes;C:\weblogic\myserver\serverclasses;C:\weblogic\lib\weblogicaux.jar;C:\weblogic\myserver\myserver.war;C:\weblogic\myserver\_tmp_war\cos.jar;C:\weblogic\myserver\_tmp_war\gnu-regexp-1.0.8.jar;C:\weblogic\myserver\_tmp_war\xerces.jar, -d, C:\weblogic\myserver\_tmp_war, C:\weblogic\myserver\_tmp_war\jsp_servlet\_test.java])
              My classes are contained within /WEB-INF/classes inside the WAR file when it is generated. Upon
              inspection of the compile command, it would appear that the libraries expanded from the WAR are
              added, but not the general classes (i.e. C:\weblogic\myserver\_tmp_war is not in the compile classpath.
              Any help on this would be greatly appreciated.
              David Barton
              >>> The following is the web.xml file <<<<<
              <!DOCTYPE web-app PUBLIC
              "-//Sun Microsystems, Inc.//DTD Web Application 1.2//EN"
              "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
              <web-app>
              </web-app>
              >>>>> The following is the JSP page <<<<<<<<<
              <%@ page import="oneit.Formatter" %>
              <html>
              <body>
              <%= Formatter.format (10) %>
              </body>
              </html>
              >>>>> The Formatter class is below <<<<<<
              package oneit;
              public class Formatter
              public static String format (int number)
              return String.valueOf (number);
              

              I have also found that extracting the WAR file and referencing the resulting directory rather then
              the WAR works.
              David Barton
              

  • How to compile package which contain class outside the package

    I am writing a JDBC driver.
    I have the following package structure in the folder:
    MyDriver
        |_manager.jar
        |_com
               |_ jdbc
                       |_ HXDriver
                       |_ HXConnection
                       |_ HXResultSet
                       |_ HXStatementIn manager.jar, there is a remote object Interaface(Manager.java) which I need to use inside HXConnection.
    My question is how to compile(or/and how to set the classpath)so that I can compile the 4 classes inside jdbc package.
    I tried this:
    C:\MyDriver>javac -cp .;manager.jar com/hx/jdbc/*.java
    However, this does not work, compiler says it cannot find Manager
    Please help me.
    Cheers

    D:\380 Project\Driver>javac -cp .;manager.jar com\hx\jdbc\*.java
    com\hx\jdbc\HXConnection.java:21: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXConnection
            private Manager manager;
                    ^
    com\hx\jdbc\HXStatement.java:18: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXStatement
            private Manager manager;
                    ^
    com\hx\jdbc\HXStatement.java:20: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXStatement
            public HXStatement(Manager manager){
                               ^
    com\hx\jdbc\HXConnection.java:41: cannot find symbol
    symbol  : class Manager
    location: class com.hx.jdbc.HXConnection
                            manager = (Manager)reg.lookup("manager");
                                       ^

  • Cannot find class: Exception??

    Hi
    The compiler claims it cannot find class FileNotFoundException or any other exception in my Main. Any packages I import has no problem. My structure:
    java \ myMain \ Main.java
    java \ com \ myName \ packages //no, the space is just there as visual help:)
    Use javac -classpath java\ @compile.file
    ...where compile.file is a txt file giving the paths and filenames to all files I include.
    This is first time I use the -classpath parameter, but I believed java.lang always was included. What Am I doing wrong.
    regards
    JT

    You should review the tool documentation for the javac command and its use of classpath.
    Your problem appears to be due to the way you defined classpath, "-classpath java\". While you don't provide enough information to conclusively say what it should be, I'm guessing it should also include java\myMain\ - assuming that you're issuing the javac command from the parent of the \java\ directory, as your command example indicates.
    Here is a clip about its use of the classpath.
    "When compiling a source file, the compiler often needs information about a type whose definition did not appear in the source files given on the command line. The compiler needs type information for every class or interface used, extended, or implemented in the source file. This includes classes and interfaces not explicitly mentioned in the source file but which provide information through inheritance.
    For example, when you subclass java.applet.Applet, you are also using Applet's ancestor classes: java.awt.Panel, java.awt.Container, java.awt.Component, and java.lang.Object.
    When the compiler needs type information, it looks for a source file or class file which defines the type. The compiler searches for class files first in the bootstrap and extension classes, then in the user class path (which by default is the current directory). The user class path is defined by setting the CLASSPATH environment variable or by using the -classpath command line option. (For details, see Setting the Class Path).
    If you set the -sourcepath option, the compiler searches the indicated path for source files; otherwise the compiler searches the user class path for both class files and source files."

  • How to Find Classes Urgent!

    I have loaded .class files using classLoader ..
    i want to find calsses & interfaces which are present in perticular package structure(in memory)..if i use Package.getPackages() mathod
    its returning me all the packages which are loaded in memory.using that package structure how to find the
    classes and interface's
    Advance Thanx

    the problem is that its to hard to track the each classes and its packages.. i have more then 20 jars..each jar having morethen 25 classes with diff packge structure.. (more then one jar having same package structued classes )
    so that i have loade all the classes using Systems class loader..
    now my need is to find classes whichare present in perticular package structure..
    for Ex. in system class loader it will automatically load java.jang.allclasses;
    what i want is if i knew that package name (java.jang)
    i should find the class name's like Object,String,Long...etc

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

Maybe you are looking for