• Post Reply Bookmark Topic Watch Topic
  • New Topic

HelloWorld app -- "File Not Found" on Mac  RSS feed

 
Hitch Kennedy
Greenhorn
Posts: 2
Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Total newbie. Trying to get my HellowWorld app to run my Mac. In the terminal after I enter "javac HelloWorld.java", I get "file not found". Where should the file be located? This is not clear to me. I assume the file is in the wrong directory.

I have not configured JAVA_HOME, PATH or CLASS_PATH. I have struggled mightily this afternoon without success. Is this even relevant? I appeared to be unable to save any changes into what I believe was a file called .profile.

When enter "pwd" in the terminal, I get "/Users/myname".

Any insight into these struggles would be most helpful.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running javac from the directory that you saved the HelloWorld.java file.

$ cd directory_where_HelloWorld.java_was_saved

$ ls *.java
# ... make sure HelloWorld.java is listed in the output of the ls command

$ javac HelloWorld.java
$
# no output if it compiled successfully

# run the program
$ java HelloWorld
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you type

javac HelloWorld.java

It assumes that the HellowWorld.java file is in whatever directory you are sitting in with your command prompt. as Junilu implies, if you do an ls (or dir or whatever Macs use) and the file isn't listed, then java won't find it to compile it.

alternatively, you could also do this:

javac /complete/path/to/HelloWorld.java

but that could cause you other issues by putting the .class file somewhere other than where you want it.
 
Hitch Kennedy
Greenhorn
Posts: 2
Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the feedback. Basically, both Junilu and fred were spot-on. Once I saved the file and navigated to that directory via the terminal using the cd command, a new experience, I was able to run javac. However, I did not realize I also needed to run the newly created class file. D'oh! But, careful reading of the documentation provided at this site enabled me to get the program to run. Of course, the mismatch between the file-name and the public class didn't help. But, I figured it out, too.

I have found myself stymied very much by the Mac GUI in navigating the directory structure. This is my first Mac in a couple of decades. So there's been a lot of wheel-spinning on that front. But, I'm over this embarrassing hump. As for the three-week delay in updating this thread -- car accident, logon problems, illness, etc. Thank-you for the help and patience. I really appreciate it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!