Concept about  import statements

Hi all,
I write a GUI application and I notice I have to write these two import statement at the same time in order to handle the events:
import java.awt.*;
import java.awt.event.*;
Why is that? Does java.awt.* not include java.awt.event.*?
thank you,
Li

I'm unsure what you are talking about...do you mean something like this?
import java.util.LinkedList;
import java.util.concurrent.*;-or- perhaps something like:
import java.util.*;
import java.util.LinkedList;In the case of the former, that is perfectly legal and possible. In the case of the latter, it is possible, but absurd. Perhaps neither of these were what you were talking about. If not, let me know more precisely what you mean and we'll see about it.

Similar Messages

  • Question about import statements

    Why is it that I must have the import statement on the
    same frame
    and same layer
    as the AS code that utilizes the Class that I am importing?
    At least that is how it appears.

    Because that is how it works.
    Remember, import doesn't actually "import" anything. It is
    just a shortcut so you don't have to type the whole package name
    every time you use the coded in your example.
    It is actually kind of nice when you come back to code later
    or if you open somebody else's code (that you have to update or
    change) and to see at the top, "Oh, this bit of code has a reliance
    on class blah.blah.Yadda." In a way it kind of helps enforce a bit
    of good coding practice.

  • Explain about import statement..

    Hi All,
    what is happening for the below code, pls explain.
      import mdpsx release_9400 block_9400 upd_mro_9400 route_9400 mdvux
          from database indx(zb) id indx_key.
    below is the information
    mdpsx - Internaltable
    release_9400 - Internaltable
    block_9400 - Internaltable
    upd_mro_9400 - Internaltable
    route_9400 - Internaltable
    mdvux - Internaltable
    indx - Database Table
    indx_key is the structure and have the below files in that structure:
    matnr like matvp-matnr
    werks like matvp-werks
    subbu.

    hi
    you wrote..
    >
    subbu ilam wrote:
    > what is happening for the below code, pls explain.
    >
    >
    >   import mdpsx release_9400 block_9400 upd_mro_9400 route_9400 mdvux
    >       from database indx(zb) id indx_key.
    >
    > below is the information
    >
    > mdpsx - Internaltable
    > release_9400 - Internaltable
    > block_9400 - Internaltable
    > upd_mro_9400 - Internaltable
    > route_9400 - Internaltable
    > mdvux - Internaltable
    > indx - Database Table
    >
    > indx_key is the structure and have the below files in that structure:
    >
    > matnr like matvp-matnr
    > werks like matvp-werks
    >
    >
    > subbu.
    NOTE :-IMPORT nad EXPORT is use to importing exporting data to or from the ABAP memory
    import mdpsx release_9400 block_9400 upd_mro_9400 route_9400 mdvux
         from database indx(zb) id indx_key.
    in the above statement mdpsx release_9400 block_9400 upd_mro_9400 route_9400 mdvux is import from the from the ABAP memory database indx(zb)
    hope this helps
    Regards
    Ritesh

  • Question about import statement

    Hi all!
    I was wondering if a line like this:
    import java.io.*imports all classes from java.io or just the classes needed by your program (the classes you actually using in your code). Can anyone give me a little hint on that?

    The way I understand it is that it simply makes the
    classes in that package 'visible'. This means that you
    don't have to type the fully qualified name each timeOh, yeah. I was thinking too much in C and it's #include.
    Thanks :-)

  • Newbie question about import statement

    Lets say for example I have a class A and a class B.
    Then lets say I import class A into class B.
    If I instantiate some objects and methods in class A
    Will I be able to access them in class B.
    Thanks gemann

    Imports are used to import classed from another package.
    Conside a package named package1 and class named A in it.
    package package1;
    public class A{
      //public method
      public void publicmethod() {}
      //private method
      private void privatemethod() {}
      //default method
      void defaultmethod(){}
      //protected method
      void portectedmethod(){}
    }Now conside another package named package2 having a class B.. and you want to make an object of class A and want to call its method..
    package package2;
    import  package1.A;  // or import package1.*   it imoprts every class in this package
    class B{
    B(){
    A a=new A() ; // possible since we imported it..
    a.publicmethod() // possible since it is public method
    a.defaultmethod()// Not possible. since it is a this is in a different package
    a.protectedmethod()// Not possible since this is in  a different package, and this is not a derived a derived class of B
    a.privatemethod() // Not possible since it is private
    }Hope it is clear now..
    appu

  • Confused about CLASSPATH and how java handles import statements...

    Hello,
    I must admit I don't get it. I read the articles about setting CLASSPATH etc. but I still wonder:
    If you use an import statement, what does the compiler do? I.e. where does it look for the specified classes? I find it confusing because I see in different locations different .jar files:
    C:\jdk1.3.1_03\lib\dt.jar
    C:\jdk1.3.1_03\lib\htmlconvertor.jar
    C:\jdk1.3.1_03\lib\tools.jar
    and also
    C:\jdk1.3.1_03\jre\lib\i18n.jar
    C:\jdk1.3.1_03\jre\lib\rt.jar
    C:\jdk1.3.1_03\jre\lib\jaws.jar
    C:\jdk1.3.1_03\jre\lib\sunrassign.jar
    Can someone explain me what the purpose is of these files?
    And why do I have the same contents in
    C:\Program Files\JavaSoft\JRE\1.3.1_03\lib
    and in
    C:\jdk1.3.1_03\jre\lib
    Why is that?
    Thanks for answering my questions!
    -mike

    Thanx for the answers, but I still wonder, everyone
    here says I need to set the classpath, but I don't.Probably because your classes are already in the class path. The compiler/jvm also look for classes by themselves not just in jar files, when just a directory is supplied in the class path. And a period (".") is a valid directory.
    Programs importing different classes compile with no
    problem. So what's up with that?
    Presumably you are referring to your own code - because they are in the class path.
    Second, I still don't understand why the runtime needs
    the .jar files. The runtime uses classes, like String, that have to come from somewhere.
    This would also mean that end-users
    need to set the classpath to the .jar files in their
    JRE directory to be able to run programs that import
    classes from these .jars. But this is not true, right?No it is true. The end-users will have to set the class path. There are variations on this which make it seem like no class path is set. For instance applets in a browser are java but the end-user does not need to set a class path. That is because the browser knows how to download classes/jars and how to set it up so it uses them. (Actually it uses a class loader, but that is probably more information that you need.)
    Because if I make some nice classes myself and import
    them, how can I expect my end-user to install these
    classes and make a classpath for them?That would be between you and you end-user.
    First installation is not part of java. For installation you will have to find something outside of java to accomplish the goal.
    Additionally how the class path gets set is OS specific. Java does not deal with that. You will also have to find some way to deal with this (most likely part of the installation.)
    There are also variations on this. For example the browser example I gave above. Or using the ext directory. Or creating an executable jar. Or simply setting the class path.
    In my understanding it should only be needed in the JDK, not
    in the JRE. True or am I mistaken?Mistaken. The class path is needed in the JRE as well. You will need to set it.

  • Import statement in .java files and .jsp files ..correction

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement in two.java I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import one.class in My.jsp .That is i have to say
    <%@page import="one"%>
    in My.jsp.
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder and MyJsp is compiled sucessfully.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.

    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.

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

  • Import statement .. what does it do ??

    Hi All,
    What is IMPORT statement doing ??
    IMPORT order_items_in to w_order_items_in from MEMORY ID
    'FREEGOODSTERMS'.
    can you kindly explain what this statement is doing ?
    I was by my friend that this is used to pass order_items from one session to this sesssion, but when I searched for FREEGOODSTERMS, I could find export after this statment. I was wondering how can import me first and then export.
    Please let me know.
    Thanks
    venkat.

    Hello Venkat,
    Sorry for late reply..
    Please see the program which other program submitting somewhere.
    if they are using multiple purpose then export and import statement may possible in one include.
    Best way just use where used list for that include and other programs searching like export and submit..
    For better understanding about export and import then see the below sample programs.
    Create one program and paste below code :
    REPORT  ZTEST_AMEM1.
    tables : lfa1.
    data : begin of i_lfa1 occurs 0 ,
           lifnr like lfa1-lifnr,
           name1 like lfa1-name1,
           land1 like lfa1-land1,
           end of i_lfa1.
    start-of-selection.
    select lifnr
           name1
           land1 from lfa1
           into table i_lfa1 up to 100 rows.
    Export
    export i_lfa1 to memory id 'SAP'.
    submit ztest_amem2 and return.
    write:/ 'hello'.
    Now create one more program  and paste below code :
    REPORT  ZTEST_AMEM2.
    data : begin of j_lfa1 occurs 0,
           lifnr like lfa1-lifnr,
           name1 like lfa1-name1,
           land1 like lfa1-land1,
           end of j_lfa1.
    start-of-selection.
    import i_lfa1 to j_lfa1 from memory id 'SAP'.
    loop at j_lfa1.
    write:/ j_lfa1-lifnr,j_lfa1-name1,j_lfa1-land1.
    endloop.
    Thanks
    Seshu

  • Import statement clashes

    Hi,
    If 2 import statements happen to import the same class implicitly (as opposed to naming the exact class in the import statement), then how does the compiler decide which one is used? Apparently the order of the import statements doesn't matter... already tried that.
    For example:
    //class Test.java
    import java.lang.*; /redundant, but shows that we're importing Object
    import org.omg.CORBA.Object;
    public class Test {
    public static void main(String[] args) {
    Object obj = new String();
    ... here, the compiler complains about "found: java.lang.String" and "required: org.omg.CORBA.Object". Switching the order of the import statements had no effect... same issue. How are name clashes handled with import statements?

    The conflict is not resolved -- if there is any ambiguity the compiler complains. In these cases you need to use the fully qualified class name; e.g. java.lang.Object or org.omg.CORBA.Object -- it's not allowed to use the simple name "Object" because there's no way to know which of the two is meant.

  • Import statement and directory structure

    First of all, sorry for such a long post, I believe part of it is because I am unsure of the concept of importing in Java. Secondly, Thanks to anyone who can ultimately enlighten me to the concept of import. I did ask this question before in the "erorr and error handling" forum, and the people who have helped me there did a great job. But, I believe I require a little more clarification and thus have decided to post here.
    Anyhow, my question..
    Could someone explain to me the concept of the import statement, or direct me to a webpage with sort of explanation for newbies? For some reason, I am having a hard time grasping the concept.
    As I understand it, the import statement in Java, is very similar to the namespace keyword in C. That is to say, import doesn't actually "import" any source code, the way that the #include statement does in C.
    So I suppose what my question is, say I have a java class file like below:
    //filename: sentence.java
    //located: c:\school\csc365
    package csc365;
    class sentence
    //some variables here..
    //some constructor here..
    //some methods here..
    And some sample program like the one below which implements the above..
    //filename: test.java
    //located: c:\school\csc365
    import csc365.*;
    import java.io.*;
    class test.java
    //creates some sentence object
    //uses the object's methods
    //some other things.
    As I understand it, the test.java file should not compile because the csc365 package is not in the correct directory. (assuming of course, the classpath is like c:\school\csc365;c:\school )
    But, ... where then should the sentence.java be located? In a subdirectory of c:\school called csc365 (i.e c:\school\csc365\) ?
    And thus that would mean the test.java file could be located anywhere on the hard drive?
    I suppose, I just need a little clarification on the correlation between a package's "name" (i.e package csc365; ) and its corresponding directory's name, and also how the javac compiler searches the classpath for java classes.
    ..So, theoretically if I were to set the classpath to look in every conceivable directory(provided the directory names were all unique) of the harddrive, then I could compile a test.java anywhere?
    As a note: I have been able to get the test.java file to compile, by leaving out the import statement in the test.java file, and also leaving out the package statement for the sentence class, but I assume this is because the files are defaulted to the same package?

    Hi Mary,
    No, import isn't analogous to C++ namespace - Java package is closer to the namespace mark.
    import is just a convenience for the programmer. You can go your whole Java career without ever writing an import statement if you wish. All that means is that you'll have to type out the fully-resolved class name every time you want to use a class that's in a package other than java.lang. Example:
    // NOTE: No import statements
    public class Family
       // NOTE: fully-resolved class names
       private java.util.List children = new java.util.ArrayList();
    }If you use the import statement, you can save yourself from typing:
    import java.util.ArrayList;
    import java.util.List;
    public class Family
       // NOTE: fully-resolved class names
       private List children = new ArrayList();
    }import isn't the same as class loader. It does not bring in any source code at all.
    import comes into play when you're compiling or running your code. Java will check to make sure that any "shorthand" class names you give it live in one of the packages you've imported. If it can't find a matching fully-resolved class name, it'll give you a message like "Symbol not found" or something like that.
    I arrange Java source in a directory structure that matches the package structure in the .class files.
    If I've got a Java source file like this:
    package foo.bar;
    public class Baz
       public static void main(String [] args)
            Baz baz = new Baz();
            System.out.println(baz);
       public String toString()
           return "I am a Baz";
    }I'll store it in a directory structure like this:
    root
    +---classes
    +---src
          +---foo
               +---bar
                    +---Baz.javaWhen I compile, I go to root and compile by typing this:
    javac -d classes foo/bar/*.javaI can run the code from root by typing:
    java -classpath classes foo.bar.BazI hope this wasn't patronizing or beneath you. I don't mean to be insulting. - MOD

  • Import statement in .java files and .jsp files

    Guys I have few mysteries about this import statement.
    Please correct me if I am wrong.
    1)Suppose if I have a folder c:\SourceFolder it has one.java and two.java files.If I compile one.java then one.class files is created in c:\ClassFolder .Now two.java uses one of the method of one.java,and without using import statement I am able to compile two.java, and two.class file is created in c:\ClassFolder.I assume that the path of one.class was taken from the CLASSPATH environment variable,hence I there was no need for import statement .........am i right ?
    BUT... in My.jsp,which is in C:\JspFolder, if I want to use one.class,then I have to specifically import the class I want to use.That is i have to say
    <%@page import="one"%>
    and since the classpath is C:\ClassFolder ,it finds one.class in the C:\ClassFolder.(Note that My.class is created in a folder different from c:\ClassFolder )
    But I am wondering why was there no need for me to import one.class in two.java.
    (Note I am using JDeveloper and Apache server)
    Please help.
    In this case the pSo I am wondering in JSP why it doesn't take the class I am looking for from the classpath .
    Help.

    You have to understand Java scoping rules. In the 1st scenario with the two Java files I am guessing neither one of them begins with a package statement. This means that they belong to the default package. When you compile the compiler uses the classpath to resolve method calls looking in the default package since there was no import statement specified in two.java. JSP is a little different. Now I just read this here in these forums a couple of days ago. Since the classfiles generated from the JSP files are not in the CLASSPATH they are loaded by a different classloader. This is why you have to import all references to all classes in the default package.

  • How can i append the variable to filename in import statement?

    how can i append variable(substitution variable) to file name in import command for maxL?
    example : For suppose there is a file like "dataload.txt" and a variable like cur_month(august).How can i rename the file like daload_august in import statement.
    Edited by: 788996 on Aug 22, 2010 11:18 PM

    Are you saying you want to use an OS level environment variable in a MaxL statement to substitute for an entire file name? I am going to illustrate Windows, but do it your own way in *nix if you want.
    YourCallingCode.cmd
    REM Note the \\ and then the \\, you had \\ and \
    SET curmon=c:\\ABC\\datafile_21_AUG.txt 
    REM Call MaxL with a paramenter
    startMaxL.cmd DoItForTheCurrentMonth.msh %curmon%DoItForTheCurrentMonth.msh
    login blah blah for blah ;
    import database appname.dbname data from local text data_file $curmon using server rules_file "rulefile"
         on error abort ;The trick is to change whatever's in % and % and replace it with a $ in the MaxL script.
    I gave a presentation last year on MaxL at ODTUG Kaleidoscope. If you go to http://www.odtug.com, then Tech Resources, then Essbase, then search on my name, you'll find "Master Essbase with MaxL Automation". More than you could ever want to know about MaxL, variables (parameter, environment, and explicitly declared), scripting, etc., etc., are all there for the taking. If you're not already a member, you'll have to join, but an associate membership is free. You can then download my presentation and all of the others. It is a treasure chest of technical tips and knowledge.
    Yes, I am a fan a member of the Hyperion SIG, so I am ever so slightly biased. Regardless, it is good information, for free.
    Regards,
    Cameron Lackpour
    Edited by: CL on Aug 24, 2010 5:33 AM
    If you want to substitute part of the data file name, you can do that too:
    set curmon=21_AUG
    Your MaxL statement would look like:
    import database appname.dbname data from local text data_file "c:\\ABC\\datafile_$curmon.txt" using server rules_file "rulefile"
         on error abort ;

  • Import statement throws exception

    Hey,
    I just added the code into my program to have a tray icon as is now supported in Java 1.6.0 "Mustang". Really easy and straight forward to do.
    Trouble is that the program will throw an exception if run on 1.4.2 or 1.5.0. The icon is a convenience not a necessity so I want to be able to allow the program to run on any of these platforms.
    Is there a way to import the classes other than using the import command and allow the program to catch the exception and respond with something like JOptionPane.showmessagedialog(frame,"Upgrade to Mustang to have tray icon");
    I thought about catching the exception when the class with the import statements is called, but that would cause the object to be null and would cause NullPointerExceptions all over my application.
    Any suggestions?
    Thanks,
    DAvid

    One way round it would be to use Class.forName() to obtain the class and then call the methods using reflection. If the class isn't found, catch the ClassNotFoundException and ignore it.
    It's not pretty but it'd work.
    Import statements are only used at compile time, though. Your runtime exception is produced when the class is accessed in the code. Nothing to do with imports. You can import all the classes you like and as long as the code doesn't need to resolve them at runtime, it'll work just fine.

  • Java import statement problems

    Hello...
    I have the book "Java in a Nutshell, 2nd ed" and have a query about a nested top-level interface example they have in the book.
    Basically there's two files/classes. The first, LinkedList.java, is as follows:
    public class LinkedList {
        public static interface Linkable {
            // Linkable interface details here
        // rest of LinkedList class here
    Next is LinkedList.java as follows:
    import LinkedList.*;
    class LinkableInteger2 implements Linkable {
        // rest of LinkableInteger2 class here
    Now I thought the import statement had two forms - and both used a package name as part of the statement:
    import package.class;
    import package.*;
    Obviously, neither class has a package statement.
    As written, these classes do not compile. Am I right in assuming the lack of a package name is causing this problem, or is there something else going on here?
    Thanks...
    Mark.

    Since you don't have package statements in the files, the classes are being placed in the default package. You cannot explicitly import classes from the default package. Al classes in the default package, the java.lang package and the current package are always imported automatically. Your import statement is incorrect - remove it.

Maybe you are looking for

  • Can I create a new itunes account for my kids and still keep old music on both?

    My kids currently have ipod nanos.  They are getting ipod touches for christmas.  Originally we setup a "family" itunes account on my computer.  We now want to set them up their own account on their own laptop.  Can we transfer old music from nano to

  • Virtual machine setup mini guide for thoes with XP or 7

    Sorry this guide is very rough. Why do we need this? Because application loader works only on mac. Not on PC. The final step to submit the application requires application loader. There is no way around it at the moment. So you need to submit your ap

  • Drill Down in Visual Composer

    In input form- for the feilds, i used as Drill down, and selected entry list as dynamic in control properties. when i publish in Portal , i can see list of values ( A- F) for input feilds.-when i select the one value ( A) and i see the output aswell.

  • Java.sql.SQLException: XA error: XA_RBROLLBACK

    [Context failure: onAcquire[Unexpected exception while enlisting XAConnection java.sql.SQLException: XA error: XA_RBROLLBACK : Rollback was caused by unspecified reason start() failed on resource "XAConnectionPool";: XA_RBROLLBACK : Rollback was caus

  • Prolem with Cache-Control:max-age http header

    Hello It seems that safari do not take into account Cache-Control:max-age=31536000 http header. Sending this header to the browser I would expect that safari will not ask the server for these resources before current date + one year. It's the way IE