• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Javac finding my source code

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I am new to Java and it took me quite long to get cmd to find javac. I have tried a lot of stuff and looked on the internet but am very stuck. I have wrote a few programs but all i get is javac file not found.please help
 
Ranch Hand
Posts: 38
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)
Use "set" command to set value of PATH environment variable as shown in below example:

C:\Documents and Settings>set PATH=%PATH%; C:\Program Files\Java\jdk1.6.0_26\bin

%PATH% is actually representing current path and we are appending java bin directory into PATH. Note that every path in windows is comma (;) separated while in UNIX it would be colon ( : ) separated

2)
Use short cut "window key + pause/break" --> Advanced --> Environment Variables -->PATH

Just append the path of java installation directory here and you are done. Open a command prompt and type java or javac and you can see the output.


 
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple things to add to Vivek's answer:
1. Make sure that you have the JDK (Java Development Kit) installed. The JRE (Java Runtime Environment) can only run Java applications, you need the JDK to build/compile them.
2. The paths that Vivek is referring to is the path to the Java Development Kit. There's an executable program called javac.exe (on Windows) in the bin directory of the folder the JDK was installed into. You can open Windows Explorer and navigate into the Java directory (typically in C:/Program Files/Java/ on Windows), and try to find the javac.exe program. You can try opening up a command prompt in that directory and running "javac --version" to make sure that javac can be found. If it can be, that proves that you need to set the PATH environment variable so that Windows knows where to look without providing the whole path to javac every time.
3. Any changes to the PATH environment variable only take effect on new command prompt windows. So if you checked javac.exe again, then added Java to the PATH, you would have to open a new command prompt to test your changes.

If you're still having problems after following these instructions, please include the following in your response:
1. The location of javac.exe on your computer.
2. The contents of your PATH environment variable.
3. The command you are trying to run and its output.
 
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look at this FAQ, which includes setting the PATH. There are at least two ways to set the PATH. If you follow those instructions (missing out the bits for other operating systems) you should be all right.

And welcome to the Ranch
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I have the file in C:\Program Files\Java\jdk1.7.0_40\bin. It is called javac not javac exe, there is no file with that name. I set my path to this and it finds javac when i type javac in cmd promt. If i try putting path as C:\>set PATH=%PATH%; C:\Program Files\Java\jdk1.7.0_40\bin then when i type javac in cmd prompt nothing is found. I have typed programs in word pad and note pad i know one is text free format. These are in C:\Java programs. when i type javac HelloWorldApp.java and i always get nothing. i also have tried cd C:\Java programs and it find this then i try and get nothing.

 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also have windows 8 i dont know if that is a problem
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not know whether Win8 is any different from Win7. These instructions do not seem to have any differences.
On a Windows box, the file is called javac.exe, but you invoke it with javac. You may have hide extensions for common file types enabled.
It is normal to get no output from a successful invocation. The stony silence represents completion of the task: rest assured you get lots of error messages if anything goes wrong.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry what i meant was that i just get javac file not found
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my cmd prompt finds java but when i try to compile programs it says file not found
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so every time i start my computer and open cmd promt i type javac and it finds it so no problem there. It is when i try to compile a program it always says program not found
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S thanks to those who have helped me I am reading up on java alot but it hrts when i cant get anything to compile.
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you even execute a simple example like the hello world example in our FAQ? If not, tell us exactly what happens, with folder names and everything.

Have you set a system or user classpath? That simple action can prevent you finding your own work.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have set a system path. my programs are on c drive C:\Java programs,when i type javac i get alot of relevent info so i know it has been found. i have checked what i should get on utube. when i type javac HelloWorldApp with all the wrire case it always says error javac file not found. i am very stressed.
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yesterday, I wrote: . . . tell us exactly what happens, with folder names and everything. . . .

When I said exactly I meant exactly. Show us your input and output. Also tell us what your classpath is. We already know your path is correct, at least until you upgrade to update 45, because we know you get different error messages from a wrong path. Tell us what you get from ECHO %CLASSPATH%
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

steven collins wrote: . . .when i type javac i get alot of relevent info . . .

When you use javac correctly you usually get no output. Any output you are getting is probably error messages.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i type that in i get %CLASSPATH%
The program i am trying to get has the classpath HelloWorldApp
I type javac HelloWorldApp.java and get:
javac: file not found: HelloWorldApp.java
Usage: javac <options> <source files>
use -help for a list of possible options

 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

steven collins wrote:when i type that in i get %CLASSPATH%

At first I thought I had given you misleading information, but when I looked at this Java Tutorials page, it appears that is a real response (scroll down to the bottom). It appears to mean that there isn't a CLASSPATH set, which is the correct configuration.

The program i am trying to get has the classpath HelloWorldApp
I type javac HelloWorldApp.java and get:
javac: file not found: HelloWorldApp.java . . .

A program doesn't usually have a classpath; you supply a classpath to the OS.
Try javac -cp . HelloWorldApp.java, but I suspect that will work no better. Try the dir command to confirm the .java file is actually in the folder you are in.
You haven't been using Microsoft Notepad have you? That has a nasty habit of adding .txt to the name of your file while you aren't watching, so the file named XXX.java doesn't exist.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have used note pad and word pad both cant be found,this is rediculous i just want to compile a program
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the command prompt, type
dir
and show us what output you get
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:When you use javac correctly you usually get no output.


If you type just javac you get a list of options. I assume that's what the OP means by relevant info.
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I see what you mean.

I suspect the file isn't in the correct location or it has had its name altered. NotePad is notorious for changing file names. Don't use word processors, because they do things like changing "" to “” and the javac tool will perceive that as incorrect characters.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im so stressed with this its been weeks and all i get is file not found. I have looked on all the links and spent hours and even whole weekends. I needed this for my ou degree but this is unbelievable. I think if i dont stop trying i will go made.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

On Windows, you can use the "search programs and files" feature, in the start menu to find the file. Hopefully, it is just misplaced, and not deleted.

Obviously, this is not a Java issue; nor a java compiler issue; nor a CLASSPATh file. You can't compile a java program if you don't have the source file to compile.

Henry
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello im going to download netbeans to help is this cheating and will it help
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

steven collins wrote:hello im going to download netbeans to help is this cheating and will it help




I seem to be missing the point. The java compiler can't find the source file. And you say that both notepad and wordpad editors can't find the source file. So, what is netbeans going to do to help here? I don't think netbeans have a feature that finds missing files.

Henry
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it isn't cheating. No, it won't help; it may actually hinder your learning. As Henry says, and I thought earlier, it is almost certainly a case of finding where the file has got to.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i just thought that it might make finding the file easier if i wrote it on that. Is there a writer that is text free and best for writting java programs.Maybe the files i wrote are not compatable.What am i looking for i know where they are myself they are in C:\Users\steven\Downloads\Java programs. Is that not what you mean. i have copied exactly what is written on the net and in my book i have three files. one is even one i copied exactly from net called class HelloWorldApp on a wordpad document. when i do the file directory command for them in that place it finds them.
but javac wont.
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you have navigated to the right folder? What do you see with the dir command? Apart from . and .. which always appear. Please copy and post the output. This FAQ should help you with the copying. We can probably see the problem in a few seconds if we actually see the output. Also please post the entire text of the smallest of those files.

We have already tested your classpath, but it is worth trying it again:-
NetBeans won't help you find those file, but it can allow you to write them again, in its own location. The trouble with IDEs is that they have a steep learning curve and you have probably got your brain working full‑stretch learning Java®.
You have already been given a suggestion about editors: you will find it hard to beat Notepad++. It is similar to Notepad2 (both use the same engine) but completely different from the M$ NotePad.
As I said, word processors tend to add control characters or convert ordinary quotes to posh quotes, which the javac tool cannot cope with.

 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/*
This is a simple Java program.
Call this file Example.java.
*/
class Example {
// A Java program begins with a call to main ().
public static void main (String args[]) {
System.out.println ("Java drives the Web.") ;
}
}

Thanks im working on the dir stuff i will read and try that.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i type dir i get a list of folders in c:\users which is where
my downloads files are that i have put the java folder in. is this all useless i dont want to spend over a month getting one simple program to compile .
i think i should just carry on reading about jave programming from my book i mean this is rediculous.
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\Users\steven>dir
Volume in drive C has no label.
Volume Serial Number is CC14-5092

Directory of C:\Users\steven

30/10/2013 19:35 <DIR> .
30/10/2013 19:35 <DIR> ..
14/10/2013 18:05 <DIR> .eclipse
14/10/2013 18:06 <DIR> .jmc
22/10/2013 10:36 <DIR> .VirtualBox
30/10/2013 19:35 <DIR> Contacts
30/10/2013 19:35 <DIR> Desktop
31/10/2013 19:32 <DIR> Documents
31/10/2013 13:06 <DIR> Downloads
30/10/2013 19:35 <DIR> Favorites
30/10/2013 19:35 <DIR> Links
30/10/2013 19:35 <DIR> Music
30/10/2013 19:35 <DIR> Pictures
30/10/2013 19:35 <DIR> Saved Games
30/10/2013 19:36 <DIR> Searches
12/10/2013 20:08 0 set
30/10/2013 19:35 <DIR> Videos
22/10/2013 10:26 <DIR> VirtualBox VMs
1 File(s) 0 bytes
17 Dir(s) 872,118,915,072 bytes free

C:\Users\steven>
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry im getting emotional its taking alot of effort to get no program compiled .sorry people
 
Campbell Ritchie
Marshal
Posts: 79964
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There ain't any sign of any Java files in that dir output. You can't find them becuase you aren't in the correct directory, and they are somewhere else.
The Example.java file posted earlier is a Hello World class by a different name. Hello World serves to confirm your compilation process is running correctly. I recommend you follow the procedure described here; the instructions happen to be the same (I think) in Windows®. Unix, Mac and Linux. For Foo read Example, HelloWorld or something else. On subsequent occasions when you run Java, omit the line starting mkdir. Now find all your other.java files and move them to that folder; when it starts to get too full you can create packages there.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

steven collins wrote:I have typed programs in word pad and note pad i know one is text free format. These are in C:\Java programs. when i type javac HelloWorldApp.java and i always get nothing.



steven collins wrote:C:\Users\steven>dir
Volume in drive C has no label.
Volume Serial Number is CC14-5092

Directory of C:\Users\steven


You are in a directory called C:\Users\steven. Your source code is in a directory called C:\Java programs
You need to change directory to C:\Java programs (cd "C:\Java programs") and then type javac HelloWorldApp.java.
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:There ain't any sign of any Java files in that dir output. You can't find them becuase you aren't in the correct directory, and they are somewhere else.
The Example.java file posted earlier is a Hello World class by a different name. Hello World serves to confirm your compilation process is running correctly. I recommend you follow the procedure described here; the instructions happen to be the same (I think) in Windows®. Unix, Mac and Linux. For Foo read Example, HelloWorld or something else. On subsequent occasions when you run Java, omit the line starting mkdir. Now find all your other.java files and move them to that folder; when it starts to get too full you can create packages there.




Agreed. We can't help you if you provide incorrect information. You said earlier that the file is there; that "notepad" and "wordpad" can find the file (which is different from earlier still that it could not); and that "dir" can list the file... yet, your "dir listing" example is showing otherwise. Simply, if you can't find the file, then javac can't find the file either.

Henry
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C:\Program Files\Java\Java programs>javac HelloWorldApp.java
javac: file not found: HelloWorldApp.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\Program Files\Java\Java programs>
Idid that but still the same.

I have changed the java,programs folder around abit to see if its found anywhere better thats why i moved it around. didnt work though. word pad and notepad do always find them. i dont see where im giving wrong info
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the directory above - issue the dir command and copy and paste the result here please.

thanks
-steve
 
steven collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\steven>cd C:\Program Files\Java\Java programs

C:\Program Files\Java\Java programs>dir
Volume in drive C has no label.
Volume Serial Number is CC14-5092

Directory of C:\Program Files\Java\Java programs

18/10/2013 21:01 <DIR> .
18/10/2013 21:01 <DIR> ..
14/10/2013 15:18 492 Example.java..rtf
14/10/2013 17:30 356 Example2.java..txt
14/10/2013 17:00 1,901 HelloWorldApp.java.java
3 File(s) 2,749 bytes
2 Dir(s) 871,884,988,416 bytes free

C:\Program Files\Java\Java programs>


 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

steven collins wrote:Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\steven>cd C:\Program Files\Java\Java programs

C:\Program Files\Java\Java programs>dir
Volume in drive C has no label.
Volume Serial Number is CC14-5092

Directory of C:\Program Files\Java\Java programs

18/10/2013 21:01 <DIR> .
18/10/2013 21:01 <DIR> ..
14/10/2013 15:18 492 Example.java..rtf
14/10/2013 17:30 356 Example2.java..txt
14/10/2013 17:00 1,901 HelloWorldApp.java.java
3 File(s) 2,749 bytes
2 Dir(s) 871,884,988,416 bytes free

C:\Program Files\Java\Java programs>



You have three files in that directory. They are named "Example.java..rtf", "Example2.java..txt", and "HelloWorldApp.java.java". The java compiler is looking for "HelloWorldApp.java" which doesn't match any of the three.

Henry
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic