Results 1 to 6 of 6

Thread: default package

  1. #1
    rachushetty is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Question default package

    why java.lang package is imported defaultly in every program???

    i got one point that this package contains all the classes that are required in every program,so it is set as default package..
    am i correct???
    if yes plzz tel me how this package is set as default package??

    if no plzz tel me the reason behind setting java.lang as default package..


    pllzzzz help me out!!!!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: default package

    Quote Originally Posted by rachushetty View Post
    why java.lang package is imported defaultly in every program?
    Because the language specification requires it.
    Chapter*7.*Packages
    A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.
    Quote Originally Posted by rachushetty View Post
    pllzzzz help me out!!!!
    This is a technical forum, not internet chat. Please use correct spellings and avoid multiple punctuation marks.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    rachushetty is offline Member
    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    Default Re: default package

    Quote Originally Posted by DarrylBurke View Post
    Because the language specification requires it.
    Chapter*7.*Packages



    This is a technical forum, not internet chat. Please use correct spellings and avoid multiple punctuation marks.

    db

    thank you for the solution.
    but i want to know how it is set as automatic access.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: default package

    Quote Originally Posted by rachushetty View Post
    thank you for the solution.
    but i want to know how it is set as automatic access.
    The compiler does it all for you, there's no need to worry about it, because it is defined that way (see Darryl's reply)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default Re: default package

    And if you're trying to add your own classes to the "default package", I doubt that's possible.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: default package

    Quote Originally Posted by rachushetty View Post
    thank you for the solution.
    but i want to know how it is set as automatic access.
    That will be compiler implementation specific.
    The specification merely requires that it be automatically imported without a class having to do it itself.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 3
    Last Post: 03-27-2012, 10:27 AM
  2. Default / package-private access
    By genkuro in forum New To Java
    Replies: 1
    Last Post: 12-30-2010, 07:08 AM
  3. Default Access (package access) confusion
    By gauravrajbehl in forum New To Java
    Replies: 1
    Last Post: 11-18-2009, 11:48 AM
  4. Replies: 1
    Last Post: 03-10-2009, 02:12 PM
  5. importing from default package?
    By diggitydoggz in forum New To Java
    Replies: 6
    Last Post: 01-06-2009, 02:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •