Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jason Perry   on Aug 30 In Java Category.

  
Question Answered By: Willie Gomez   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

Share: 

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


Tagged: