• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up Java for the first time  RSS feed

 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, I am a beginner at Java, I downloaded java recently. My address to java folder is "C:\Program Files (x86)\Java\jdk1.7.0_17" respectively.
I have also set the path for javac by going to environment variables then adding a new variable in 'system variables' and pointing it to the location of bin folder in my java folder in my C drive, and that works fine i guess but I am having trouble in setting up path for classpath. I followed instructions present on internet asking to go to environment variables and add the new variable to 'user defined variables' part and naming it 'CLASSPATH' and giving its address to be "C:\Program Files (x86)\Java\jdk1.7.0_17\lib" . after doing all this i wrote a hello world program in notepad and saved it in H Drive (H:\javaprogs) and named it first .java. then I opened DOS command and typed in "javac H:\javaprogs\first.java" but everytime it says file not found.

also i am very confused, as when i click environ variables i have two boxes one saying 'user defined variables' and other saying 'system variables', on scrolling down system variables section there is a variable called classpath and its address is located as ".;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip" . where am i going wrong?? i am very confused...


I HAVE WINDOWS 7 LAPTOP
 
drac yang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first let's check out what the "file not found" means, what is the file, does it mean the file of javac or the first.java.

to check that, just type javac in command line, if the path that was set is correct, it would print the usage of the javac on screen.

commonly i don't set ClassPath, only if your class files are located in the current directory.

btw, i think system variables are applicable for all the users under the operating system while the user defined variables is only for the current user that logged on.
 
Kavisha Paranamana
Greenhorn
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsh , what is the error massage you get ?

I think the problem is with your environment variables. Either you have to add your '/bin' folder to Path variable or add custom variable as JAVAHOME and then 'Path' variable should include 'JAVAHOME/bin'.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

There is a description of the path in our FAQ. The classpath is where the “java” tool looks for class files used as part of your application.

The advice not to set a system classpath is correct. It is a particularly bad idea to add Java installation folders to your classpath. Unfortunately some programs set up their own classpath, and that messes up all your settings for Java. QuickTime (QT) is notorious for doing that. It sets up folders with QT in their name and adds them to the system classpath. If you still wish to use QT, edit the classpath by adding .; to its start (on a DOS/Windows® box) or .: to its start on a Unix/Mac/Linux box.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drac yang wrote:first let's check out what the "file not found" means, what is the file, does it mean the file of javac or the first.java.

to check that, just type javac in command line, if the path that was set is correct, it would print the usage of the javac on screen.

commonly i don't set ClassPath, only if your class files are located in the current directory.

btw, i think system variables are applicable for all the users under the operating system while the user defined variables is only for the current user that logged on.



ok so when I type javac in cmd this is what i get :
javac.jpg
[Thumbnail for javac.jpg]
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kavisha Paranamana wrote:Harsh , what is the error massage you get ?

I think the problem is with your environment variables. Either you have to add your '/bin' folder to Path variable or add custom variable as JAVAHOME and then 'Path' variable should include 'JAVAHOME/bin'.


I think i did that .. but i am not doing something right... I went to environment variables and to system variables i added a variable called PATH and gave its address to be the bin folder. after that i dont understand what to do. I added a new variable called CLASSPATH in the user defined variables box and directed its address to where the lib folder exists .
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsh Chandola wrote:ok so when I type javac in cmd this is what i get :

That looks perfectly normal.

Try this:


C:\Users\Somebody> h:
H:\> cd javaprogs
H:\javaprogs> javac first.java


What do you get when you do that? Please copy & paste the text of the error message instead of posting a screenshot.

Maybe Notepad added the ".txt" extension after your file. Check if the file is not named "first.java.txt", and if it is, rename it to "first.java" before compiling.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsh Chandola wrote: . . . ok so when I type javac in cmd this is what i get :
Please repeat the procedure and post the text.
 
drac yang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsh Chandola wrote:
Kavisha Paranamana wrote:Harsh , what is the error massage you get ?

I think the problem is with your environment variables. Either you have to add your '/bin' folder to Path variable or add custom variable as JAVAHOME and then 'Path' variable should include 'JAVAHOME/bin'.


I think i did that .. but i am not doing something right... I went to environment variables and to system variables i added a variable called PATH and gave its address to be the bin folder. after that i dont understand what to do. I added a new variable called CLASSPATH in the user defined variables box and directed its address to where the lib folder exists .

that means the path for the java utilities has correctly been set, the file not found should point to the java file you want to compile, normally you could javac a file with prepended path, try to find out something wrong with the correctness of the file name or its related path just as Jesper de Jong pointed out.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drac yang wrote: . . . to check that, just type javac in command line, if the path that was set is correct, it would print the usage of the javac on screen. . . .
So that is why you are getting that particular output.

I still think the problem has to do with your classpath and it is QT which has caused it and you can solve it easily by adding .; to the start of the classpath.
 
Harsh Chandola
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
Harsh Chandola wrote:ok so when I type javac in cmd this is what i get :

That looks perfectly normal.

Try this:


C:\Users\Somebody> h:
H:\> cd javaprogs
H:\javaprogs> javac first.java


What do you get when you do that? Please copy & paste the text of the error message instead of posting a screenshot.

Maybe Notepad added the ".txt" extension after your file. Check if the file is not named "first.java.txt", and if it is, rename it to "first.java" before compiling.



Yes thats what exactly happened I had to work in H: and also it had saved my file as first.java.txt. Thank You all very much. I would also like to ask that i downloaded the api documentation and after i unzipped it, i get a folder called docs. am i supposed to copy that folder to the C drive java directory and I dont understand how it works if I am not using any IDE?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API documentation is just a big collection of HTML files, that you can view with your web browser. Double-click the file index.html in the directory to open the documentation in your browser.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe better to bookmark this link to the API. Use it online and forget about the downloaded file (until your Internet connection goes belly‑up, that is ‍).
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done Jesper guessing he was using NotePad. I would suggest you stop using NotePad; you will find some suggestions here. The editors mentioned there are much better, and you don’t have to pay for them
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!