| Author |
Total beginner here - Mac based Java - how do I find it/run scripts?
|
R Arthur
Greenhorn
Joined: Jan 27, 2010
Posts: 6
|
|
Hi all,
So I have decided to jump in to Java. I have one problem though....I understand that Mac has Java already installed into OS X 10.4.11
However, I can't find it. Or at least, I can't find the JVM to test some scripts. I bought Head First Java, and I want to plug in one of their examples scripts....but where? I also don't see any Java folders in the Library.
I know there are no stupid questions, but I have been trying to figure this out for 3 days....and I feel stupid. Is it possible that it is not installed on my computer? I am about to move over to my desktop PC....but I'd rather have the portability of my Macbook.
Thanks so much for any help!
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9950
|
|
Welcome to the Ranch!!!
I know nothing about Macs, but I always assumed that when they said java was already installed on them, they meant the JRE, not the JDK.
the JRE is what lets you RUN a java program. I.e. it's been compiled and you have the class files.
if you want to write and compile your own java, you may still have to install the JDK (Java Development Kit). But I can't address how you do that.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
This link has a video...
http://blog.adsdevshop.com/2009/03/17/installing-the-jdk-16-on-mac-os-x-the-video/
Hope that helps,
Janeice
|
When you do things right, people won't be sure you've done anything at all.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Welcome to the Ranch
People will be keener to answer if you tell them what the question is about in the thread title.
|
 |
R Arthur
Greenhorn
Joined: Jan 27, 2010
Posts: 6
|
|
Campbell Ritchie wrote:Welcome to the Ranch
People will be keener to answer if you tell them what the question is about in the thread title.
right you are....thanks Campbell...
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Thank you for changing it
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56202
|
|
Bring up a Terminal window, and enter javac at the command line.
If you get "command not found", the JDK is not installed.
If you get a usage message, you are good to go.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56202
|
|
|
P.S. Using a good subject works. I would not have opened this topic if it hadn't had the word "Mac" in the subject.
|
 |
R Arthur
Greenhorn
Joined: Jan 27, 2010
Posts: 6
|
|
Bear Bibeault wrote:Bring up a Terminal window, and enter javac at the command line.
If you get "command not found", the JDK is not installed.
If you get a usage message, you are good to go.
Thanks Bear...
Looks like it is installed....so can you then tell me how I would test a script....I think I need to enter the script in a compiler? Where do I find that? Thanks for helping....I swear I'm not an idiot....I just gotta learn once....thanks so much.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56202
|
|
Once you are at the command line, you can just follow any tutorial on writing Java programs. There's nothing Mac-specific you need to worry about.
Essentially:
Write Java program in .java files using a text editorCompile .java files using javac; creates .class filesRun program using java command
The devil is in the details. So pay attention to what the book is telling you.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Suggest a couple of stages before what Bear told you.
mkdir javawork
cd javawork
That will create a nice directory called javawork (you can obviously give it any name you like) and you can keep all your Java safe in it; the line starting cd will take you directly to it.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12928
|
|
|
Have a look at Sun's Java tutorials. For the Mac, follow the Hello World tutorial for Solaris and Linux (Mac OS X is a Unix-like operating system, so it will be almost the same as for Solaris and Linux).
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
R Arthur
Greenhorn
Joined: Jan 27, 2010
Posts: 6
|
|
Bear Bibeault wrote:Once you are at the command line, you can just follow any tutorial on writing Java programs. There's nothing Mac-specific you need to worry about.
Essentially:
Write Java program in .java files using a text editorCompile .java files using javac; creates .class filesRun program using java command
The devil is in the details. So pay attention to what the book is telling you.
Yea, I get the gist of steps 1, 2 and 3....I guess I just haven't grasped how one compiles .java files using javac......what program is used to compile?
Anyway, I'll figure it out one way or another...thanks for the help!
-Let me rephrase that....I thought I compiled in the JVM....and that's what I can't find...
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
Okay.... here's another way to say this. I'm used to PC, but I think Macs are pretty much the same when it comes to this.....
The Java Virtual Machine is what most people have on their computers. It's used, most notably, to run Java based applications as well as view Java content on web pages.
The Java Developer Kit (JDK) is a bunch of stuff used by developers (like us) to compile programs. The programs are written in a text editor (if you're using the HeadFirst book I recommend NotePad++), or you can use a development environment like Eclipse.
"javac" is the compiler you need to get the files you write in your text editor to turn into useful Java class files. In windows, there's a way to add the file to the known paths of the operating system. I think that video I linked to might have information on that for Macs.
So you write a file, say "HelloWorld.java". How do you compile it?
Type:
... at the command prompt while you're in the folder that has the file in it. If you're lucky and there are no errors , you get a class file. So now you have 2 files with different extentions (one java that you wrote, the other class... the compiled version). The JVM runs the class files. If you set your system properties correctly, you should then be able to type
And your application will run.
Hello World!! :-)
Is this getting clearer? I remember it took me about a week to understand this whole thing when I started....
-Janeice
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12928
|
|
R Arthur wrote:I guess I just haven't grasped how one compiles .java files using javac......what program is used to compile?
The program that you use to compile Java source files to Java class files is javac, the Java compiler. It doesn't have a graphical user interface, it's a program that you use on the command line of the terminal window.
The page About the Java Technology from Sun's tutorials explains it in detail, with pictures:
|
 |
R Arthur
Greenhorn
Joined: Jan 27, 2010
Posts: 6
|
|
Janeice DelVecchio wrote:Okay.... here's another way to say this. I'm used to PC, but I think Macs are pretty much the same when it comes to this.....
The Java Virtual Machine is what most people have on their computers. It's used, most notably, to run Java based applications as well as view Java content on web pages.
The Java Developer Kit (JDK) is a bunch of stuff used by developers (like us) to compile programs. The programs are written in a text editor (if you're using the HeadFirst book I recommend NotePad++), or you can use a development environment like Eclipse.
"javac" is the compiler you need to get the files you write in your text editor to turn into useful Java class files. In windows, there's a way to add the file to the known paths of the operating system. I think that video I linked to might have information on that for Macs.
So you write a file, say "HelloWorld.java". How do you compile it?
Type:
... at the command prompt while you're in the folder that has the file in it. If you're lucky and there are no errors  , you get a class file. So now you have 2 files with different extentions (one java that you wrote, the other class... the compiled version). The JVM runs the class files. If you set your system properties correctly, you should then be able to type
And your application will run.
Hello World!! :-)
Is this getting clearer? I remember it took me about a week to understand this whole thing when I started....
-Janeice
Thank you so much Janeice...it is becoming much clearer....that was very helpful!
|
 |
R Arthur
Greenhorn
Joined: Jan 27, 2010
Posts: 6
|
|
Jesper Young wrote:
R Arthur wrote:I guess I just haven't grasped how one compiles .java files using javac......what program is used to compile?
The program that you use to compile Java source files to Java class files is javac, the Java compiler. It doesn't have a graphical user interface, it's a program that you use on the command line of the terminal window.
The page About the Java Technology from Sun's tutorials explains it in detail, with pictures:

Thanks Jesper....that helped me visualize it....this is a great forum....I hope I can repay someday....
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
YAY!!
|
 |
 |
|
|
subject: Total beginner here - Mac based Java - how do I find it/run scripts?
|
|
|