This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Total beginner here - Mac based Java - how do I find it/run scripts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Total beginner here - Mac based Java - how do I find it/run scripts?" Watch "Total beginner here - Mac based Java - how do I find it/run scripts?" New topic
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: 11139
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659
    
  11

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: 37874
    
  22
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: 37874
    
  22
Thank you for changing it
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

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: 60732
    
  65

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 editor
  • Compile .java files using javac; creates .class files
  • Run 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: 37874
        
      22
    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
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 14074
        
      16

    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 editor
  • Compile .java files using javac; creates .class files
  • Run 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: 1659
        
      11

    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
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 14074
        
      16

    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: 1659
        
      11

    YAY!!

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Total beginner here - Mac based Java - how do I find it/run scripts?
     
    Similar Threads
    GUI doesn't work in OS10.0
    Is J2EE installed on user's computer
    Is Mac OS X a free version
    Two versions of java on same system ?
    Setting up on the Mac