Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Java Command LIne

 
Mark Nibert
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I posted earlier and maybe I am missing something w/ running a java program from the command line. Here is the path I have in the command line "C:\Program Files (x86)\Java\jdk1.6.0_14\bin"
Where do I save the .java files, I have read through a couple tutorials and maybe I just dont get it. I appreciate any help as I have searched and searched and cannot seem to get it.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You put the .java (the source code files) in a package/directory hierarchy, wherever you want.
 
Mark Nibert
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is where I am confused when I run javac <programname> and I am in the bin file how does it know where the compiler is? I am not following how to do it at all.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You put the .java (the source code files) in a package/directory hierarchy, wherever you want

I would not recommend to put them under C:\Program Files (x86)\Java\jdk1.6.0_14\bin

I suggest you to make a new directory somewhere. For example, C:\java\src. If your source is in a package, make new directories under C:\java\src. For example :

You would put this class here : C:\java\src\sample\MarkNibert.java
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how does it know where the compiler is?

I see your are using Windows. Windows uses special environment variables to hold certain information. There's one called PATH. It holds directories. If you type a command at the command line, these directories will be scanned to find the command. Try to type SET at the command line. You'll see PATH in the list. C:\Program Files (x86)\Java\jdk1.6.0_14\bin must be in there.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, a good place to start is here.
 
Mark Nibert
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am feeling pretty retarded. I am not able to get it to work. I created c:\java\src and the folder I have my application in is chap11 so the full path is c:\java\src\chap11 here is the code



When I run the code while in the c:\java\src directory or the c:\java\src\chap11 directory it returns an error

'javac' is not recognized as an internal or external command, operable program or batch file

So I retyped it out w/ the full path to the javac and it still doesnt work. I am on windows 7 and eclipse works so I think I have the right jdk installed.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'javac' is not recognized as an internal or external command, operable program or batch file

Which means that your sdk bin directory is not in the PATH. Check this page which tells you how to edit the PATH in Vista. Edit it, and add "C:\Program Files (x86)\Java\jdk1.6.0_14\bin". Make it the first directory in the PATH.
 
Mark Nibert
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok that worked so it knows where the compiler is. It is now working, thanks a million for putting up w/ my ignorance.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lots of people have that problem; setting the PATH is very confusing until you have done it a few times.
 
Mark Nibert
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah it seems easy looking back but last night I was ready to rip my hair out. I appreciate the help. I really enjoy these forums, everyone is so helpful. I wish I had the money to do the 200 dollar class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic