aspose file tools*
The moose likes Beginning Java and the fly likes how to compile packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to compile packages" Watch "how to compile packages" New topic
Author

how to compile packages

Anand Divakaran
Greenhorn

Joined: Jul 20, 2007
Posts: 11
How do i compile and run this program...

this is my path where the MyPack folder is..
g:\Program Files\java\jdk1.6.0_01\bin\examples\MyPack



Edit by mw: Added Code Tags.
[ July 20, 2007: Message edited by: marc weber ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Anand Dk:
...this is my path where the MyPack folder is..
g:\Program Files\java\jdk1.6.0_01\bin\examples\MyPack...

Welcome to JavaRanch!

Whoa... First, do not save your own code under the bin directory. This is for the JDK's binary files, and you don't want to confuse matters by adding your own stuff there. Instead, keep things clean (and safe) by making your own directory, like g:\java.

My guess is that you're saving under the bin directory because that's the only way you could get the Java installation to work. If that's the case, then the problem is with your system path variable. Let us know what operating system you're running, and we'll help you through that.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Anand Divakaran
Greenhorn

Joined: Jul 20, 2007
Posts: 11
i'm working with windows vista home premium

i have compiled programs where i dont use packages..
so its not my very firs program
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Anand Dk:
...i have compiled programs where i dont use packages...

Yes, but can you compile files that are not under the JDK bin directory?

What error messages are you getting when you try to compile the above program?
[ July 20, 2007: Message edited by: marc weber ]
Anand Divakaran
Greenhorn

Joined: Jul 20, 2007
Posts: 11
i think if you set the path variables , you should be able to

but haven't tried it yet
Anand Divakaran
Greenhorn

Joined: Jul 20, 2007
Posts: 11
could you tell me how to compile the program and to run it,

let's assume its located as the way its mentioned above..

thnx
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Setting the PATH variable tells your system where to find the Java executables, and this allows you to compile and run from any directory.

To set the PATH variable, see Sun's installation instructions for Windows. Step 4 describes setting the PATH variable for Windows 2000 and XP. Hopefully, the Vista procedure isn't too different from XP.

Once your PATH is set, let's say you've created your own directory that's not under the JDK's bin...

g:\java\examples\MyPack

And suppose this is where you've saved the above file as "AccountBalance.java." Now let's say the current directory is g:\java\examples. To compile, use the javac command along with the source file location (including the directory MyPack). Then to run, use the java command along with the fully qualified class name (MyPack.AccountBalance).

G:\java\examples> javac MyPack\AccountBalance.java
G:\java\examples> java MyPack.AccountBalance

Note JLS 6.7...
The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.

[ July 20, 2007: Message edited by: marc weber ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Anand Dk:
...let's assume its located as the way its mentioned above...

Again, it's a Bad Idea to mix your own files with the JDK's bin contents, and you really should set a system PATH variable for Java. But assuming your file is where it is and you don't have a PATH set for Java, you could do it like this...

G:\Program Files\java\jdk1.6.0_01\bin> javac MyPack\AccountBalance.java
G:\Program Files\java\jdk1.6.0_01\bin> java MyPack.AccountBalance

Since the current directory is bin, your system should be able to find javac and java without having a PATH pointing elsewhere. So it's just a matter of providing javac with the relative path for the .java file (including the directory MyPack), and then providing java with the fully qualified class name (MyPack.AccountBalance).
[ July 20, 2007: Message edited by: marc weber ]
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
Hi "Anand Dk",

Please check your email for a message from the JavaRanch Staff.

Kind Regards,
Katrina Owen
Saloon Bartender
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to compile packages