how to use package

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mistusen
    New Member
    • Oct 2008
    • 7

    #1

    how to use package

    Code:
    import java.lang.Math;
    
    class power2 {
        public double square (int n) {
            return java.lang.Math.pow(n,2);
        }
    }
    
    class power1 {
        public static void main(String args[]) {
                    power2 x1 = new power2();
                    int m =(int)x1.square(3);
                    System.out.println(m);
        }
    }
    i've wriiten this code for getting the value of square of a number(integer) .
    i'am using Jcreator pro for writing java code.i want to bundle these classes into a package say pack1;and i want to import this package to other place.how should i do it?

    only writing package pack1at the top,does not work.....
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    only writing package pack1at the top,does not work.....
    you may read first the JAR File Specification.

    In there, you will know how to create jar file effectively....

    when you execute your main class from the commandline, take a look at the option -cp and its relationship between the main class and another jar files.on the net.....

    and if you are going to JAR your main class, read this.

    regards,
    sukatoa

    Comment

    Working...