• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to compile packages

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Anand Divakaran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think if you set the path variables , you should be able to

but haven't tried it yet
 
Anand Divakaran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi "Anand Dk",

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

Kind Regards,
Katrina Owen
Saloon Bartender
 
reply
    Bookmark Topic Watch Topic
  • New Topic