Using wildcards in import statement

I typically use wildcards in my import statements. For example:
import javax.swing.*;
Are there any advantages, though, in specifying exactly which classes I am importing?
For example,
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JEditorPane;
import java.swing.JProgressBar;
// etc.
Specigically, is the resulting class file any smaller if I specify exactly which classes to use and does the Java runtime engine load faster if I specify exactly which classes I use in the import statemetents?
Thanks,

Import has precisely zero runtime impact. I believe it is used to help locate the specified class at runtime. Take the following 2 simple source files:
import java.util.Vector;
//import java.util.*;
public class VectorTest
     public static void main( String[] args )
          Vector v = new Vector();
          v.add("Item 1");
          v.add("Item 2");
          System.out.println( v.get(1) );
public class Vector
     public boolean add(Object o)
          return true;
     public Object get(int index)
          return "doh!";
}1) Run the code as is and "Item 2" is displayed
2) Recompile the code using the generic import and "doh!" is displayed.
The point is that by fully qualifying the import statement you are sure you are executing the correct class and not just some class that happens to be lying around somewhere in your classpath.

Similar Messages

  • Use of wildcard(*) in import statement

    I am a bit new in Actionscript 3.0 and I love to learn it.
    I saw the following two import statements in an actionscript 3.0 code.
    import flash.display.MovieClip;
    import flash.display.SimpleButton;
    In this case, can I use just juse * sign as in import.flash.display.*; ???
    Is this change would cause any problem?
    Sami

    There are cases when it works and cases when it doesn't, and I don't know if there is a reason.  You can try and see if it makes a difference, and if you get error regarding lack of definition you can hopefully determine that you need to explicitly name the class.
    Also, it partly depends on where you are implementing the code.  Usually when coding in the Actions panel you do not need to import most classes at all.  But when you are working with class files you normally have to import any that are not top-level, such as the two you identified.

  • Using wildcard in If statement

    Hi. I have 2 part numbers I'm trying to find and I just want to display the text below on these 2 parts only. The 2 part numbers are:
    PL-PLCC44-S-01TR
    PL-PLCC68-S-01TR
    This is not on a search page, so the Like command does not work.I created this If statement and when I put the whole part number in the quotes, it works fine, but I want to use a wildcard since there will be more parts like this and I will not want to keep adding parts to this If statement.So basically, I'm trying to search for all the part numbers that end in TR. If they do, display the text below on the page. How can I use these wilcards correctly?
    <cfif ThisPart.Client_SKU EQ "%TR">Min. buy of 50pcs is required.</cfif>
    Thanks.
    Andy

    Here's the answer:
    <cfif right(ThisPart.Client_SKU, 2) EQ "TR">Min. buy of 50pcs is required.</cfif>

  • Is it possible to use wildcards to match cell contents in an if statement?

    I need to return a ID along with some other information on a page by page basis, so that the information comes out linked by position.  I use a couple of loops and if statements to navigate through the document.  I am able to use exact matches of cell contents which is fine when the contents doesn't vary.  But the IDs, though they have a similar pattern, are all different. In a menu driven search, I am able to find what I need with '150^9^9^9^9^9-^9^9^9' But when I try putting this (or any number of [0-9], *, ? combinations) it fails.  Is it possible to use wildcards?  The symbol used for the match (==) makes me suspect that it is not possible and that only literal, exact matches will work.  But I wanted to check with the experts before giving up.
    Thanks
    pcbaz

    Thanks for the input.  You're right, a GREP search is much more efficient.  But what I'm trying to do and the circumstances here don't allow me, I think,  to go that route. I am trying to generate a list of values coming from several textframes on a single page and have them come out so that I can tell which values belong together.
    I'm using an inherited document with masters that were created 'manually';  the index numbering for textframes and tables is random. I navigate through the pages, looping through textframe indices asking ' does this textframe exist?' If so, I ask if it is a table -- if no, it is a simple textframe and I ask about the ID, if yes, I ask if the contents of cell (0,0) (invariant position and contents) are equal to the table I want..  I am sending the ID and other pieces of information from the table to one row of a new table on a new page.  So the ID and other information from a single page are linked by being in the same row.
    I know this a little 'off-normal' -- I'm using the search to navigate through the document and find things by location the way you do with a spreadsheet.  I have devised a work-around that helps me get around the fact that the ID is not invariant.  I create a list of the (exact) IDs from another document, equating them to a variable ('a').  I then loop through the list of IDs and ask if the contents of the textframe is equal to 'a'..This works o.k, unless there happens to be an extra space, a different kind of hyphen, etc. It would be so much easier if I could use the wildcards that work in a menu-driven text or GREP search in script just to ask about the contents of the textframe.
    Thanks again
    pcbaz (Peter BIerly)
    P.S. we have since rewritten the masters so this problem will not exist in the future -- we now know exactly which textframe and/or table indices to refer to to get any particular bits of information and don't need to ask questions about the contents.

  • Which one better to use - jsp:useBean or import statement

    Hi,
    I just want to know that which one is better to use jsp:useBean or import statement .
    I can instantiate and call method of myclass -
    1) by importing the class through import tag in jsp as <%@page import="myclass"%. or
    2). by using <jsp:useBean tag....
    i have these two option to do the same thing. i know that basically useBean is used to call setter and getter method of bean class and but it can be used to call a normal java file that have some logic .
    so what should i used , which one is better and why?
    useBean provides scope and object instance so no need to create object by new operator. and with import you have to create an instance .
    but which tag should i use in my jsp?
    i am confused???

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Using Import Statement

    Hi,
    I understand that in order to access the methods of a different class, I can "import" it. Here is my question though:
    Where am I importing it from? I mean, surely if I am importing a class from e.g. the Java.util package, doesn't this package need to be on my computer somewhere?
    And also, if I make a .jar file of my application for use on another computer and the files contain import statements, doesn't the other computer need to have these packages on their machine?
    I know this seems like a silly question but it's bothering me!
    GF

    Yep, you can unzip them to see inside. The package name unzips into a directory structure and the Class name is a file. So java.util.HashMap will unzip into a directory java/util and have a file called HashMap.class in it.
    You can usually download the source code for these classes also.

  • Using imported archive in UDF using import statement

    Hello Expert,
    I am trying to use the class of keystore_api.jar which is impoted in imported archive in my UDF using the import statement
    com.sap.engine.interfaces.keystore.KeystoreManager but I am getting the error
    package com.sap.engine.interfaces.keystore does not exist
    import com.sap.engine.interfaces.keystore.*;
    Appreciate your valuable replies.
    Kind Regards,
    Kubra fatima

    Hi,
    as ur import statement  states
    com.sap.engine.interfaces.keystore
    You need to import the jar in directory hierarchy as above manner.
    com[sap[engine[interface[]keystore[JAR]]]]
    Regards
    Ashu

  • When is necessary to use import statements to import classes?

    Hi,
    I'm sure that it must be necessary to use import statements
    in some situations, I'm finding that my code often works fine
    without them. For example, some instructions will say it is
    necessary to use import.flash.events.MouseEvent; before
    MouseEvent.CLICK will work, or that I must import the loader class
    before loading an SWF, but I'm finding that I can skip timporting
    and it works fine. Could anyone please explain why this it, and
    give me some idea of how to knew when to import and when I don't
    have to?
    Thank you in advance!

    Importing is only necessary when you create you own classes
    or are using a class that Flash doesn't auto import such as the
    fscommand package. Any time you create your own custom
    package/class, it is also necessary to use import statements unless
    you add the folder containing your custom packages to the default
    class path.

  • Import Statement - Which is Better ???

    Which import statement is better? Are there any performance advantages of calling the ones you need explicitly instead of using the shorthand (.*)?
    import java.util.*
    or
    import java.util.Vector;
    import java.util.TreeMap;

    there is no runtime performance difference. There could be a difference in compliation time if you use wildcards, but even that difference would probably be insignificant (plus, is compile time usually a concern in java?). The main advantage to importing only the classes you need, as the previous poster pointed out, is to reduce compilation ambiguities (e.g. does 'Date' refer to java.sql.Date or java.util.Date). For example, a recent poster just reported a problem where he imported java.beans.* and java.sql.* and, after upgrading to 1.4, none of his code compiles because both packages now have a Statement class, which causes ambiguities. As a general rule, it is best to import only the classes you need.

  • Some questions on import statements.

    When I see
    import java.awt.*
    import java.awt.event.*
    am I on track interpreting this to mean that you want to be able to use any of the classes found in package java.awt?
    why would import java.awt.event.* be necessary if event is a class in the java.awt.* package you're importing in the second import statement up above?
    does * mean like a "wildcard" which allows you to utilize
    anything that is part of java.awt?

    It allows you to use any of the classes in that directory, but not any classes in sub-directories of that directory.

  • Import statements disappearing in FB3

    I am trying create an actionscript file in Flex Builder 3 and
    I noticed that after I put in all my imports and I start declaring
    variables, most of my import statements will just disappear. I did
    some searching on the net and heard some people mention about using
    wildcards in there import statements, but I am not using any
    wildcards. Is this a function of Flex Builder and if so, how do I
    turn it off?

    Hi,
    You can turn it off. Go to
    Window -> Preferences... -> Flex -> Editors ->
    ActionScript Code
    deselect the check box for "Remove unused imports while
    organizing"
    Hope this helps.

  • Filename in import statement

    Hi srinivas bobbala,
    Thank you for your response.But I think my quesition was not clear.My ques... is for suppose there is one datafile for importing like.. "datafile_21" Here my intention is it takes file from datafile_21 only but it appears in import statement like datafile_21<<curmon>>.
    import database sample.sample data from data_file "c:\\ABC\datafile_21_AUG.txt" using server rules_file datafile on error abort;
    In this it takes datafile from datafile_21.But it appears like datafile_21_AUG in import statement.This AUG coming from batch file.
    Essmsh c:\\ABC\loadmxl.mxl %curmon%

    No it is not possible.
    I assume the data file "datafile_21" is first renamed to datafile_21_${CurrMth} in the batchscript.
    After that this data file *datafile_21_${CurrMth}* is pointed in the import statement.
    In the logs you will see this file as datafile_21_Aug.

  • Import Statement Different ways to refer ???

    Dear Friends,
    Can any one help me the difference between the usage of import statement....
    1. using import statement
    2. using the class directly
    that is,
    for example ;
    1. import java.util.Date;
    Date dt = new Date();
    2. java.util.Date dt = new java.util.Date();
    what's the difference between two reference of Date class...is there any meaning beyond this ?????
    Regards,
    V.Prasanna

    what's the difference between two reference of Date
    class...is there any meaning beyond this ?????there is no difference once the code is compiled - the compiler resolves single class names to their fully-qualified names (ie with the package prefix) and that appears in the .class file constant pool
    before compilation then my opinion is that having all the imports at the top of the file is good practice because you can see what is being used easily

  • IMPORT Statement Issue (Internal Table)

    Hi All,
    I am using an IMPORT statement to get all the data from other report's internal table. Now whenever this (the other report's internal table) is changed (for field addition, etc), my report throws a dump. Hence, everytime I have to add these fields in my program as well.
    Is there any way by which I can include the whole internal table of that report in my program just like
    'INCLUDE STRUCTURE VBRK'.
    Thanks in advance

    Hi, CHeck this code related to your problem..This will helpful to you...
    I have done this program earlier..I hope it will helpful to u..
    This programa calling the other program to import the data..
    Check it out...
    *" Tables declarations.................................................
    TABLES:
      spfli.
    *" Type declarations...................................................
    Type declaration of the structure to hold data from table SPFLI     *
    TYPES:
      BEGIN OF type_s_spfli,
        carrid LIKE spfli-carrid,          " Carrier Id
        connid LIKE spfli-connid,          " Connection Number
        cityfrom LIKE spfli-cityfrom,      " City from
        cityto LIKE spfli-cityto,          " City to
        airpfrom LIKE spfli-airpfrom,      " Airport from
        airpto LIKE spfli-airpto,          " Airport to
        countryfr LIKE spfli-countryfr,    " Country from
        countryto LIKE spfli-countryto,    " Country to
      END OF type_s_spfli.
    Data Declaration...................................................*
         Field String To Hold Flight Details Record from SPFLI          *
    DATA
      fs_spfli TYPE type_s_spfli.
    Data Declaration...................................................*
         Internal Table To Hold Flight Details Records from SPFLI       *
    DATA
      t_spfli LIKE STANDARD TABLE OF fs_spfli.
    TYPES:
      BEGIN OF types_s_itab,
        carrid LIKE sflight-carrid,        " Carrier id
        connid LIKE sflight-connid,        " Connection number
        fldate LIKE sflight-fldate,        " Flight date
      END OF types_s_itab.
    Data Declaration...................................................*
         Field String To Hold Flight Details Record from SFLIGHT        *
    DATA
      fs_itab TYPE types_s_itab.
    Data Declaration...................................................*
         Internal Table To Hold Flight Details Records from SFLIGHT     *
    DATA
      t_itab LIKE STANDARD TABLE OF fs_itab.
    *" Type declarations...................................................
    Type declaration of the structure to hold data from table SBOOK     *
    TYPES:
    BEGIN OF type_s_sbook,
       carrid LIKE sbook-carrid,           " Carrier Id
       connid LIKE sbook-connid,           " Connection Number
       fldate LIKE sbook-fldate,           " Flight date
       bookid LIKE sbook-bookid,           " Booking number
       loccuram LIKE sbook-loccuram,       " Local currency
       loccurkey LIKE sbook-loccurkey,
       order_date LIKE sbook-order_date,   " Booking date
    END OF type_s_sbook.
    Data Declaration...................................................*
         Field String To Hold Flight Details Record from BOOK           *
    DATA
      fs_sbook TYPE type_s_sbook.
    Data Declaration...................................................*
         Internal Table To Hold Flight Details Records from SBOOK       *
    DATA
      t_sbook LIKE STANDARD TABLE OF fs_sbook.
    DATA
      w_checkbox.                          " Checkbox
    SELECT-OPTIONS:
      s_carr FOR spfli-carrid.             " Carrier id range
                          START-OF-SELECTION EVENT                      *
    START-OF-SELECTION.
      PERFORM selectq.
                          END-OF-SELECTION EVENT                        *
    END-OF-SELECTION.
      SET PF-STATUS 'YH1314_030502'.
      PERFORM display_basic.
    AT USER-COMMAND.
      PERFORM ucomm.
    *&    Form  selectq
        This subroutine retreive data from SPFLI table
      There are no interface parameters to be passed to this subroutine.
    FORM selectq .
      SELECT carrid                        " Carrier id
             connid                        " Connection number
             cityfrom                      " City from
             cityto                        " City to
             airpfrom                      " Airport from
             airpto                        " Airport to
             countryfr                     " Country from
             countryto                     " Country to
             INTO CORRESPONDING FIELDS OF TABLE t_spfli
             FROM spfli
             WHERE carrid IN s_carr.
    ENDFORM.                               " Selectq
    *&      Form  display_basic
        This subroutine displays data from internal table
      There are no interface parameters to be passed to this subroutine.
    FORM display_basic .
      LOOP AT t_spfli INTO fs_spfli.
        WRITE:
          / w_checkbox AS CHECKBOX,
            fs_spfli-carrid,
            fs_spfli-connid,
            fs_spfli-cityfrom,
            fs_spfli-cityto,
            fs_spfli-airpfrom,
            fs_spfli-airpto,
            fs_spfli-countryfr,
            fs_spfli-countryto.
      ENDLOOP.                             " LOOP AT T-SPFLI INTO...
    ENDFORM.                               " Display_basic
    *&      Form  UCOMM
      This subroutine for at user-command event
      There are no interface parameters to be passed to this subroutine.
    FORM ucomm .
      RANGES :
        r_carr FOR spfli-carrid,
        r_conn FOR spfli-connid,
        r_carrid FOR sflight-carrid,
        r_connid FOR sflight-connid,
        r_fldate FOR sflight-fldate.
      CASE sy-ucomm.
        WHEN 'DISPLAY'.
          DATA:
            lw_lines TYPE i,
            lw_lineno TYPE i VALUE 3.
          DESCRIBE TABLE t_spfli LINES lw_lines.
          DO lw_lines TIMES.
            READ LINE lw_lineno FIELD
                 VALUE w_checkbox   INTO w_checkbox
                       fs_spfli-carrid INTO  fs_spfli-carrid
                       fs_spfli-connid INTO  fs_spfli-connid.
            IF sy-subrc = 0.
              IF w_checkbox = 'X'.
                r_carr-sign = 'I'.
                r_carr-option = 'EQ'.
                r_carr-low = fs_spfli-carrid.
                APPEND r_carr.
                r_conn-sign = 'I'.
                r_conn-option = 'EQ'.
                r_conn-low = fs_spfli-connid.
                APPEND r_conn.
              ENDIF.                       " IF W_CHECKBOX = 'X'
            ENDIF.                         " IF SY-SUBRC = 0
            ADD 1 TO lw_lineno.
          ENDDO.                           " DO LW_LINES TIMES
          SUBMIT yh1314_030502_call
            WITH s_carr IN r_carr
            WITH s_conn IN r_conn
             AND RETURN.
          IMPORT t_itab FROM MEMORY ID 'YH1314'.
          LOOP AT t_itab INTO fs_itab.
            r_carrid-sign = 'I'.
            r_carrid-option = 'EQ'.
            r_carrid-low = fs_itab-carrid.
            APPEND r_carrid.
            r_connid-sign = 'I'.
            r_connid-option = 'EQ'.
            r_connid-low = fs_itab-connid.
            APPEND r_connid.
            r_fldate-sign = 'I'.
            r_fldate-option = 'EQ'.
            r_fldate-low = fs_itab-fldate.
            APPEND r_fldate.
          ENDLOOP.                         " LOOP AT T_ITAB INTO.....
          SELECT carrid                    " Carriee Id
                 connid                    " Connection number
                 fldate                    " Flight date
                 bookid                    " Booking number
                 loccuram                  " Local Currency
                 order_date                " Booking date
             INTO CORRESPONDING FIELDS OF TABLE t_sbook
             FROM sbook
             WHERE carrid IN r_carrid AND
                   connid IN r_connid AND
                   fldate IN r_fldate.
          IF SY-SUBRC NE 0.
            MESSAGE 'NO RECORDS FOUND'(006) TYPE 'S'.
          ENDIF.                           " IF SY-SUBRC NE 0
          LOOP AT t_sbook INTO fs_sbook.
            AT FIRST.
              WRITE: /5 'Carrier Id'(001),
                     20 'Conn Id'(002),
                     35 'Flight date'(003),
                     50 'Book Id'(004),
                     65 'Local Currency'(005).
            ENDAT.                         " AT FIRST
            WRITE: /5 fs_sbook-carrid,
                   20 fs_sbook-connid,
                   35 fs_sbook-fldate,
                   50 fs_sbook-bookid,
                   65 fs_sbook-loccuram CURRENCY fs_sbook-loccurkey.
          ENDLOOP.                         " LOOP AT T_SBOOK INTO.....
      ENDCASE.                             " CASE SY-UCOMM
    ENDFORM.                               " UCOMM
    Regards
    Kiran

  • Import Statement without ID Specification

    There is an import statement
    IMPORT tab g_acc_tab FROM MEMORY.
    While UCChecking it.. it saying that
    import statement without id specification is only used for the sake of r/2 ......
    Can i Comment it ? If so won't my application  go into dump while running on 6.0cc???

    It has to do with packages. Most java classes are in a package, the name of which must conform to its place on the filesystem relative to the classpath. By that I mean that if you have com.mystuff.One.java, it must be in a folder com/mystuff where com is located somewhere in the classpath.
    What you've done is a little different. I'm assuming a couple of things:
    1. you have no package declaration at the top of one.java or two.java
    2. you have the current directory "." in your classpath.
    Java has the concept of the "default package", which covers classes without a declared package, and in your case is the current directory.
    So when you're in c:\sourcefolder and run the compiler, then "."="c:\sourcefolder", and that directory is part of the default package. No import statements are necessary for classes that are in the same package. This is why two.java can call methods in one.java without an import statement.
    When you run your jsp, the "current directory" part of your classpath is not c:\sourcefolder, but some other value (probably the directory you start your jsp engine from) You will have to import all non-java-library classes because the jsp itself becomes a java class, with a package that is determined by the jsp engine.

Maybe you are looking for

  • Program for LE_SHP_DELNOTE (smartform)

    Hi, I've to do some changes at my sapscript for shipment (TC VT03N) and I want to make change to smartforms; it's a good moment... I know the following: In SAPScript, you can use SHIPMENT_DOC and program RV56TD00 But... In SmartForms, you can use LE_

  • Security exceptions not configurable after release 31 (bug number 1042889 is not fixed)

    We are running Firefox 31 32 and 33 on different machines on windows/XP (updated until end of support). Our router has an expired certificate. On the machines updated to Firefox 32 or above the security popup screen does not show. Instead we just get

  • I want to download Visio Stencils for ADF Faces

    Dear members I read about Visio Stencils for ADF Faces and I really Like it. https://blogs.oracle.com/jdeveloperpm/entry/adf_faces_stencils_for_visio_available_on_samplecode And I want to download it. Has any one tried it before.Can any one tell me w

  • Use of function module 'FTP connect'

    when we use the function module 'FTP connect', and 'FTP_R3_TO_SERVER'

  • Error- Query Name ZQFIAP01B Exists Already

    I have deleted an old query named ZQFIAP01B and tried to save a new query using this technical name. Unfornately SAP BEx produces an error saying "Query Name ZQFIAP01B Exists Already". Have any of you encountered with this type of error before? Appre