This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
What does your CLASSPATH look like? It most likely does not contain '.' (the current directory), as Ivan suggests. Note that if you do not set the CLASSPATH evironment variable at all, Java will automatically look in the current directory.
Since this question does not really have much to do with the SCJP exam, I am moving this to the Java in General (Beginner) forum. Please continue there.
assume that java file stored in a directory named "JAVAPRJ"
Joined: Jun 13, 2007
I already set the classpath,path and JAVA_HOME but why the simple java program is not running on my mechine. I try to run the simple *.class file with package and without package but I did not.
Any *.java file is compiling fine but not running.
what is the problem..?
Actually I have Java 1.5 version on my mechine I set every thing in environment variables but that was run some day's with out any problem. After some time I installed Net Beans IDE 6.0 with that java 1.6 is installed on my mechine...I didn't set any environment variable for java 1.6 but when I try the follwoing command I am getting this :: C:\>java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
If any one had idea help me. Thanks & regards... Ishmayel.
The difference is that the -cp . adds the "." to the classpath, which means that "java" looks for whichever class you are executing in the "." as well as the rest of the classpath.
The "." means the directory your command prompt happens to be open in, the current directory.
Joined: Jun 13, 2007
Hi.. why I have to alway run my .class file with java -cp . Test how can I eliminate this ? i already set my CLASS PATH, PATH and JAVA_HOME. can any one have any idea..? Thanks in advance... Ishmayel.
Joined: Oct 13, 2005
Plase copy and paste your CLASSPATH environment variable. And why you are working at the root of your C drive rather than in a "Java" folder? Please use mkdir to create a "java" folder and try working inside that.
Joined: Aug 05, 2005
Originally posted by ishmayel vemuru: Hi.. why I have to alway run my .class file with java -cp . Test how can I eliminate this ? i already set my CLASS PATH, PATH and JAVA_HOME. can any one have any idea..? Thanks in advance... Ishmayel.
When you're just learning and only writing small apps, it is not a problem to use the CLASSPATH environment variable. However, once your apps start getting more complicated and you need to make use of different 3rd party jar files with each app then the CLASSPATH variable will become very difficult to maintain. Using the -cp option will enable you to specify a different classpath for each of your applications. If you don't want to write the whole command line each time, then you can just put it in a btach/script file and run that. Later on you will learn about jar files which will also make it easier.