Results 1 to 10 of 10
  1. #1
    Tarasj is offline Member
    Join Date
    Mar 2012
    Posts
    14
    Rep Power
    0

    Default how to make a package

    help me guys to make a package using the command prompt

  2. #2
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: how to make a package

    Quote Originally Posted by Tarasj View Post
    help me guys to make a package using the command prompt
    package should be made using "package package_name;" at the beginning of a java file, so another class can access all the methods and visible variables(and methods including constructors) whichever class have the same package name. It is a file, and not a command, to create a package.

    Java Code:
    package abc;
    class1
    {
      method1()
       {
    //
       }
    }
    Java Code:
    package abc;
    class 2
    {
      method2()
       {
    //
       }
    }
    Java Code:
    package abc;
    class 3
    {
      method3()
       {
    //
       }
    }
    Java Code:
    import abc.method1;
    import abc.method2;
    import abc.method3;//3 lines edited (sorry I did a mistake in previous post )
    //(or) import abc.*;
    class 4
    {
    //
    }


    regards
    dhilip
    Last edited by noobplus; 03-26-2012 at 02:57 PM.

  3. #3
    Tarasj is offline Member
    Join Date
    Mar 2012
    Posts
    14
    Rep Power
    0

    Default Re: how to make a package

    Thanks a lot but i also the need the command prompt command what you have given is just a declaration as far as i know

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

    Default Re: how to make a package

    A package is nothing other than an organisational thing, at the source code level.
    When you compile the source to class files, that same structure is reflected in the directory structure of the output.
    So your question makes no sense, as it's covered by simply compiling the java files.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Tarasj is offline Member
    Join Date
    Mar 2012
    Posts
    14
    Rep Power
    0

    Default Re: how to make a package

    oh how will java know the path of the package is it automatic process

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default Re: how to make a package

    The package statement in the source tells javac what package name to add on to the classname. Inside of the class file, the full classname includes the package name.
    When you execute a class that is in a package, you must use the full name that includes the package name:
    java packagename.classname
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Tarasj is offline Member
    Join Date
    Mar 2012
    Posts
    14
    Rep Power
    0

    Default Re: how to make a package

    Is it possible to import that package from any directory
    or is there some rule to follow if yes please tell me the syntax to follow

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,403
    Rep Power
    25

    Default Re: how to make a package

    See post#4.
    When importing a package the package must be on the classpath.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: how to make a package

    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Galichka is offline Member
    Join Date
    Mar 2012
    Posts
    13
    Rep Power
    0

    Default Re: how to make a package

    working in cmd, if you want to compile file in package you use simple comand:
    javac -d packagename.classname;
    whenever you want to start the program, you have to show it the classspath:
    java -classpath ./packagename.classname;

    this is how you work in cmd, but i'm not sure if this is what you asked.

Similar Threads

  1. How to make Eclipse find stuff inside same package?
    By StateMachine in forum New To Java
    Replies: 2
    Last Post: 12-27-2011, 09:19 PM
  2. Replies: 0
    Last Post: 09-14-2011, 07:52 AM
  3. Replies: 13
    Last Post: 12-06-2010, 05:57 AM
  4. Replies: 7
    Last Post: 11-09-2009, 07:51 AM
  5. A good Java installation package can make things much easier
    By freezea in forum Reviews / Advertising
    Replies: 2
    Last Post: 02-01-2009, 12:03 PM

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
  •