Thread: Java Imports. Explained

Results 1 to 4 of 4
  1. #1 Java Imports. Explained 
    Registered Member 'Lex's Avatar
    Join Date
    Nov 2010
    Age
    28
    Posts
    401
    Thanks given
    2
    Thanks received
    38
    Rep Power
    21
    Lets go straight into it;
    import
    Because of the straight solid source code naming convention, the Javac compiler can easily find the corresponding source or class files just from the fully qualified name of a package and class. By fully qualified I mean like the specific package name ETC.
    Example:
    [code=java]java.util.ArrayList x = new java.util.ArrayList ( 149 );[/code]
    The other option to this long-spaced style of coding, is to use import statements. A typical set of import statements.
    Example:
    Code:
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Date;
    They must come right after the package statement, before the class statement. They are traditionally kept placed and organized in alphabetical order.

    Lets say you import something from within your source. Ands its named... Boobies?
    You would do it like this:

    Code:
    import com.name.Jvs.Boobies;
    But nessasarily, it doesn't always have to be like that.
    There is also another form of import you can use.

    Code:
    import.com.name.Jvs.*;
    Then you can refer to the class as plain Boobies,
    static methods as MyClass.myStaticMethod()
    and static variables and constants as MyClass.myStaticValue,
    without the com.mindprod.mypackage qualification.
    There is no form of the import that lets you get away with coding your references
    without MyClass, e. g. just myStaticMethod() or myStaticValue.

    Also a little tip when using imports. Try keeps your Class names origional, avoid name clashes
    or you'll be in big trouble.

    Hope this helped.

    Reply With Quote  
     

  2. #2  
    Registered Member
    Mister Maggot's Avatar
    Join Date
    Dec 2008
    Posts
    7,227
    Thanks given
    3,283
    Thanks received
    2,875
    Rep Power
    5000
    import.PATH.TO.FILE doesn't work....
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    thx i learned alot from this, good tut
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jul 2008
    Posts
    1,043
    Thanks given
    209
    Thanks received
    46
    Rep Power
    0
    Best tut on the internet. GJ might add it to my serba.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 7
    Last Post: 07-15-2009, 08:46 PM
  2. Imports
    By Nathan in forum Help
    Replies: 5
    Last Post: 07-01-2009, 04:50 PM
  3. 2 types of imports?
    By iZAjz in forum RS 503+ Client & Server
    Replies: 8
    Last Post: 06-13-2009, 09:36 PM
  4. Static Imports?
    By Soulevoker in forum Help
    Replies: 8
    Last Post: 01-22-2009, 07:40 PM
  5. Replies: 9
    Last Post: 08-07-2008, 11:00 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •