Help coderanch get a
new server
by contributing to the fundraiser

R Arthur

Greenhorn
+ Follow
since Jan 27, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by R Arthur

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....
14 years ago

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!
14 years ago

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...
    14 years ago

    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.
    14 years ago

    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...
    14 years ago
    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!
    14 years ago