• Post Reply Bookmark Topic Watch Topic
  • New Topic

*Mac* Head First Java Initial Setup Question  RSS feed

 
M Haas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Coderanch community!

I recently took interest in learning java and bought Head First Java(2nd ed.) after reading some excellent reviews on Amazon. I've been attempting for the past few hours to work through the initial setup required to tackle the first part of the book but to no avail. After reading how marvelously the contributors here take mercy on new aspiring Java students I made an account and so here I am.

My objectives for tonight: Setup Java and text editor so I can create class files and then compile and run them in terminal. In other words, I just want to be able to do exercises from the book…

This is how far I got-

When I open my terminal window and type "java -version" I get this:

Michaels-MacBook-Pro:~ michael_haas1989$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Michaels-MacBook-Pro:~ michael_haas1989$


I've went into TextEdit and turned off the ".txt" appendage

Now I don't plan on using Netbeans but as a test to make sure everything was working correctly I went in and made a Hello World program with the following code, COPIED the code and pasted into my TextEdit and saved my text edit in this: /Users/michael_haas1989/Documents/JavaClasses



This is saved here: /Users/michael_haas1989/Documents/JavaClasses under the name HelloWorld.Java

When I enter "javac HelloWorld.java" I get this back from the terminal:

Michaels-MacBook-Pro:~ michael_haas1989$ javac HelloWorld.java
javac: file not found: HelloWorld.java
Usage: javac <options> <source files>
use -help for a list of possible options
Michaels-MacBook-Pro:~ michael_haas1989$

I've read about changing the path environment which is what I believe I have to do, and also researched how to do that but everything I've read isn't clear to me exactly how to do that. Do I do something with "export PATH=/Users/michael_haas1989/Documents/JavaClasses

Any feedback would be MUCH appreciated. I have very, very little programming experience outside of some MATLAB but won't give up if someone would just put me on the right scent.

Any recommendation of learning materials that would assist me with learning computer programming from a beginner's standpoint would also be helpful.

Thanks to all that take time to consider my problem and I'm excited to see your feedback!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

No, the PATH is not what you need to use. The PATH is used for the OS to find executables (like java and javac), but that seems to work fine.

The issue is that the Terminal by default opens in your home directory, which is not where the code was stored. The first thing to do is to find out in which directory the Terminal opened. Type "pwd" and hit return. Most likely it's going to say "/Users/michael_haas1989". You can change into another directory via the "cd" command, either with an absolute path ("cd /Users/michael_haas1989/Documents/JavaClasses") or a relative path ("cd Documents/JavaClasses").

Once you've done that you should be able to compile the code.
 
M Haas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Ulf!
Thank you VERY much for your quick response. After taking your advice I was able to compile the program and now see a ".class" version of the program in the directory. I'm still unable to execute the program though. The terminal is saying I'm missing my java virtual machine. Take a look:

Michaels-MacBook-Pro:JavaClasses michael_haas1989$ java -classpath.MooseGreetings
Unrecognized option: -classpath.MooseGreetings
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Michaels-MacBook-Pro:JavaClasses michael_haas1989$

I'm working now to find and install the missing software. If anyone has a link to what I need it would be greatly appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not believe that there is any missing software to find. Why is there a dot after -classpath?
 
M Haas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just following http://www.coderanch.com/how-to/java/how-to-create-java-program#compileExecute

It seems the way the run command works in Windows is Different. I figured it out just by trial and error. It worked when I just typed java MooseGreetings.

Michaels-MacBook-Pro:JavaClasses michael_haas1989$ java MooseGreetings
mooooooooooo
Michaels-MacBook-Pro:JavaClasses michael_haas1989$

Thank you both for the feedback
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you forgot the spaces around the dot.
 
Shane Harrison
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Welcome to JavaRanch.

No, the PATH is not what you need to use. The PATH is used for the OS to find executables (like java and javac), but that seems to work fine.

The issue is that the Terminal by default opens in your home directory, which is not where the code was stored. The first thing to do is to find out in which directory the Terminal opened. Type "pwd" and hit return. Most likely it's going to say "/Users/michael_haas1989". You can change into another directory via the "cd" command, either with an absolute path ("cd /Users/michael_haas1989/Documents/JavaClasses") or a relative path ("cd Documents/JavaClasses").

Once you've done that you should be able to compile the code.


Ulf,

You rock!!!

Thank you.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf will doubtless be pleased when he reads that post, but in the meantime …

Welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!