Friday, July 31, 2009

I have installed java in my c:/program files/java. the file which i save in bin folder works.?

but i want to save the file in folder somewhere in d: drive. i have heard that some path or classpath has to be set in the environment variables. but i don't know what to write...please help me..thanks

I have installed java in my c:/program files/java. the file which i save in bin folder works.?
uninstall java and this time reinstall in drive d and got to environment variables and add in path d:\java|bin wherever .bin file is located u just copy and paste it.........compiler will work
Reply:OK. I assume that when you open a Command Window and do





javac mySpiffyProgram.java





that it works and you get a class file. Yes???? That would mean your PATH variable is fine. The only time you are concerned about the CLASSPATH variable is when you are trying to link a big project with files all over the place. You can leave CLASSPATH blank (undefined) if you are working out of one folder. In fact, it is good practice to make a folder for every experiement / program you code. Create a folder on your D:/ drive with a good name. All textbooks start out with HelloWorld.





Now, you will have to navigate inside your Command Window. The command cd D:\myPrograms\HelloWorld





Then you can javac mySpiffyProgram.java





You have to understand that DOS commands are the link in the Java development cycle. That's why they call it the Java Development Kit -- the JDK. You could also in the Command Window type javac D:\myPrograms... and type that each time without doing the DOS cd to navigate.





Now, you MAY have to change CLASSPATH to automate things a bit better. The thing is: I don't know if you are Linux, Mac, Win98, WinXP. Note that on a WIN machine you use backslash when you are in the Command Window and ONLY when you are setting up Windows or Commanding something in Windows. When you code java, everything is the regular slash /.





Let's say you are Win98. You open the BAT file on C:\ . Find the line that says PATH = ....


Under that put CLASSPATH= .\; (period-backslash-semi colon)


That is the DOS for look inside the folder you have now.





Classpath is all about running the program. Note after javac it is:


java mySpiffyProgram -- no dot. no .class





There are faster ways to code. My favorite is NetBeans which is free, it is a code editor. It helps you with all of that classpath stuff, automatically.


No comments:

Post a Comment