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
Joined: Jul 20, 2007
i'm working with windows vista home premium
i have compiled programs where i dont use packages.. so its not my very firs program
Once your PATH is set, let's say you've created your own directory that's not under the JDK's bin...
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).
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.
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...
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 ]