Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

user define packages

  Asked By: Jason    Date: Aug 30    Category: Java    Views: 1120
  

i don't understand how to create and use,user define packages.
where i can save my packages and how can i use them?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Willie Gomez     Answered On: Aug 30

Creating & Using packages  in Java is very very simple...

first u have add the "package <package_name>;" line in your every java
program tht u want to add inside a package.

u have to mention the directory while compiling
<syntax>
javac -d <dir_name> <java_file.java>

to run u have to mention package name in command line
<syntax>
java <package>.<main_class>


ex:-

package mypackage;

public class PackageDemo
{
public static void main(String args[])
{
System.out.println("Hello, world!!");
}
}

javac -d C:\JavaDemo PackageDemo.java

java mypackage.PackageDemo

 
Didn't find what you were looking for? Find more on user define packages Or get search suggestion and latest updates.




Tagged: