compiling Java

Discussion in 'General Mac Discussion' started by jefhatfield, Jul 15, 2004.

  1. jefhatfield Retired


    Jul 9, 2000
    ok, i took a java class and when we wrote source code, we compiled it in some gui like environment which i can't remember

    i have a new java book, with examples, and i am relearning java on my own

    i wrote the source code in notepad on a PC...all fine and ok

    then, according to the lesson, i have to compile it in do i do that?
  2. gbojim macrumors 6502

    Jan 30, 2002
  3. zv470 macrumors 6502

    Jul 4, 2004
    New Zealand
    Hi, you should get Eclipse, it's an awesome IDE for Java, and it's cross-platform. Download the OSX binary from :)
  4. jefhatfield thread starter Retired


    Jul 9, 2000
    thanks for the tips


    what i did was write the source code in a notepad file and gave it a ".java" extension...i put the notepad file on the desktop (windows 98, btw)

    then i went into the DOS prompt and went from windows to the c drive

    from there, i went to the desktop in c drive

    from there, i tried the javac example but it didn't compile

    that's where it just didn't come out...and that's where i am lost
  5. Diploid macrumors newbie


    Jun 27, 2004
    Huh... I thought this was MAC Rumors...


    You need to make sure you have java installed in the first place...
    (MacOSX is still the only OS shipping with Java installed by default !) Check the installed software list or try to locate a folder named java or jre or something similar in your Program files. If you can't find it go to and download the installer
    Then, once you have confirmation that it's there, go to the shell prompt and just type "java" and hit "enter". If the shell says it can't find the prog Java, make sure to add the location of the java binaries in the PATH (in capital letters) environmental variable.
    once all this is taken care of you should be able to use the above command and compile your .java file....

    PS: if your new to java development try: for a real simple and easy to use Java IDE... later on you can move to a full blown IDE like Eclipse.

    Have fun! ;)
  6. jefhatfield thread starter Retired


    Jul 9, 2000
    i have 1.3.1 and it is compatible with that's a start

    but where do i type my souce code?

    and then how do i do it?

    there is no place to type in source code unless i do it in notepad and then drag the file in somewhere to bluej, right?

    there is no helpme on the website and the adobe pdf that is supposedly a tutorial does not exist so i have bluej but nothing telling me how to use it

    does eclipse make any more sense than bluej?


    what i am looking for is a practical way to type in source code so i can complile it...i wish i can remember the program i used in school which was so told you where you made mistakes and then you hit "compile" and whoosh, it's hit "run" and then it's done any other methods you java types know of outside of bluej and notepad?

    what is great about java and what is bad about it is how hard it is to compile and run something...the bad part is, like mentioned by the author of one java book, that it can take an extremely long time to learn how to compile even the simplest java it took him an eternity

    but the good thing is the extreme persistence it takes to learn how to compile really makes a person understand the intricacies of being a programmer and learning how to navigate in windows or mac os to make it all come together seamlessly


    the other class i took in college was visual basic...nothing was really much of a struggle so i got to do a lot of cute things...but since it was easy, i didn't have to spend countless hours on making something work and thus nothing really "stuck" in my head

    the professor had to run the program in visual basic to see if it would work


    but with java, as he calls it the most advanced and difficult language many of us will ever learn, he struggled also through the intensity of even the most simple things that he came to understand every intricacy to the point he could look at hundreds of lines of code and spot any mistake within seconds

    i like to learn things that come extremely hard because it's those things that stick into my memory for life

    ...but hey, who invented such an unfriendly language like java?

    ...and no wonder why people who have mastered it are so proud, so into it, and have all those java caps, t-shirts, bumper stickers,'s as if java is the navy seal training of programming


    anyway, i am rambling, but thanks for the tips...i think to get anywhere or get a jumpstart on this language, i will have to hire a tutor

    our class in college had one and more of us should have used him...a class which once started at 30 people ended up being just 10 of us in the end...and that was "intro" to java on the undergraduate level :) he he...i like pain but i don't really know if i can do a more advanced may be like hiring someone to tie you up, whip you, and call you their bi*** ;)
  7. G5orbust macrumors 65816


    Jun 14, 2002
    In DOS

    1) cd into the folder/disk your file is located on (type 'cd' then drag the folder its in into the DOS window and press enter)

    2) To compile:

    javac Java Source File

    3) To Run:

    java Source File Name


    cd My Documents
    java HelloWorld

    have fun!

    (I knew AP comp sci would be useful for something :))
  8. jefhatfield thread starter Retired


    Jul 9, 2000
    thanks for the tips

    you know when i go, cd My Documents, it returns a message that says "too many parameters, Documents"

    it could be that jdsk 1.3.1 does not run very well on windows 98 first edition...which is what i have

    i have seen some java compilers and other supporting stuff on disks but they wanted windows 2000/ME and windows xp...except for the disk in the back of the book i did say windows 98 would work, but they probably only meant second edition

    when i tried to put windows 98 second edition on this old, late 1998 laptop, it would not work with all the components on the machine

    it could be that i need a new machine with windows xp
  9. jonck macrumors newbie

    Jul 16, 2004
    Though I don't know much about DOS myself, I do know that the command "cd" has nothing to do with Java. "cd" is the command that you give when you want to navigate to a different directory. Same as under Unix, you cannot have spaces in the name of the directory that you are navigating to or it complains of you sending too many arguments.
    In this case you are sending 2 arguments: "My" and "Documents".
    In order to navigate to that folder, therefore you have negate that space by putting an escape character in front of it. When you do that, the interpreter knows that you don't want the space taken literally (meaning as a divider between arguments) but you want it to be part of your directory name.
    In Unix you can tell the interpreter to not take the space litterally in two ways:
    1) cd My\ Documents
    2) cd "My Documents"

    Gill Bates never was very original, so no doubt DOS will function much the same way ;)
  10. jefhatfield thread starter Retired


    Jul 9, 2000
    that's interesting and has occured to me since i tried My_Documents

    unfortunately the examples in the book showing the DOS screen with what supposed to be white letters bled through and the pages are almost all black and cannot be's that for luck??

    at least 1.3.1 installed into my pc laptop from the cd-rom

    some people have to go into the BIOS and/or registry of a windows pc machine to even make the compiler go into the computer...for some reason compilers don't load as easily, as often, as let's say a game or photos

    being cross platform is fine and dandy, but having the cd disks not load up on macs *as was the case with this disk, was a bummer...the cd said it loads on all operating systems...that meant windows, solaris, unix, linux, and even be-os

    ...because all they said was type the source code in any program, on a mac, then drag it into the environment and hit "compile"

    as with almost anthing programming related, especially java, all the components of learning it, from the cd to the book to the examples/exercises, to the the actual compiling, is a maze and too hard for techies to write in english and too hard techinically for writers to understand

    it's been my pet peeve that technical people are almost always bad writers and communicators and good writers are almost always bad techies...there could be something to the left-brain dominance or right-brain dominance thing...similar to most people being right handed or left handed ;)

    all the aptitute tests said i was good to be an engineer or a technician, but something related to math...when i look at tech specs, i get embarrassed since i know more than i should...i feel my geekiness coming out and wonder if i will turn into a fat, jolt drinking,fritos eating, greasy techie who rarely bathes ;)

    actually in silicon valley, they do bathe since a ton of them hang out at the nudist colonies, like elephant seals, and sit in the hot tubs all day and talk computers

    so, life story here, he he, i tried being an english major for three semesters and massage the "other" side of my brain...i must have averaged a "D" average in all those instructor would say something like, "see that vase over there, pretend it was your girlfriend/boyfriend, and then tell me how it would feel if it fell down and broke?"...people would write amazing ten page works of fiction in the hour while i just sat there totally stumped

    to this day, i still find writing very fun...thus my many posts, but my strength in computer hardware techie stuff pays the bills and is what comes easy to me in college and everyday life

    programming would come easier though, even know i know it's not directly computer hardware related per se, if there were some good books on online documentation that could take me step by step from the beginning written by that rare person who knows how to program and how to write ;)
  11. sonofslim macrumors 6502a


    Jun 6, 2003
    really? i've always been told java is great for beginning programmers, because it's actually simpler than many other languages. (or perhaps he was being back-handed, saying that many of your classmates would never learn anything harder than java?) other than remembering all of the nitty-gritty that comes with static typing and declaring every last little thing, i've found java to be pretty straight forward.
  12. jefhatfield thread starter Retired


    Jul 9, 2000

    at the local school beginning programming is C++, intermediate is visual basic and advanced C++, and java is the last in the series

    the other college has some java but is more into web design and their grad program is business/ecommerce and management of networks

    my peers basically are not coders, they all have their bachelor's in business and electrical/electronic engineering so we focus on hardware side issues

    but a pure programmer/cs major would most likely do the C++, vb, and java, and go way beyond those three into more sophisticated, or should i say, harder to learn languages like prolog, etc

    some unsophisticated, lower level languages, are the hardest to learn...and memorize and those old style coders also had to know high math..they were also almost entirely math majors ;) but that is old, like sad ;)
  13. G5orbust macrumors 65816


    Jun 14, 2002
    Thats strange. I guess Win 98 2nd Ed. doesnt like Java.

    The instructions I gave you also translate perfectly into OSX, so if you want to give it a run there you could without any change.
  14. Mancunian macrumors newbie

    Jul 16, 2004
    How to compile the code!

    1. 'My Documents' is too long for DOS, so the DOS name is actually Mydocu~1
    If you're not sure what the DOS file name is, just type dir at the DOS prompt, and this will give you a list of all subfolders

    2. Now, how to compile java code.......

    I had a similar problem. The DOS commands in this thread are all valid, but, in order for DOS to be able to compile a file with a compiler, YOU NEED TO TELL DOS THE FULL TARGET DIRECTORY OF EACH THE COMPILER AND THE FILE TO BE COMPILED.

    For example, if the java compiler is located at c:\java\javac.exe
    and the file to be compiled is at c:\my documents , here are the correct commands:

    cd c:\java
    javac c:\mydocu~1\

    this will compile the code for this senario. to save having to type the full target path, you can update the Path Variable - go to the sun website for more details, this website here is a good starting point for java beginners:
  15. jefhatfield thread starter Retired


    Jul 9, 2000
    again guys and girls, thanks for all the great tips

    some of the stuff you gave me is not in the book i have...i returned the book to borders since the DOS screenshots were too dark to read legibly and a "." is different than a ","...and a "(" is different than a "{" which again is different than a "[", but the illegible examples in the book blurred them all ;)

    at least i got my money back and i will tackle java with another, more legible book that has java on disk for mac os 9

    the book also said the disk would load on a mac, but then the disk itself only had ways to put it on windows, solaris, linux, unix, and beos...but not mac os ;)

    many of the java books came with disks, but when i checked, the disk was taken out...sure i know the jdsk is open source and free, but taking them out of the book is cheap to say the least...many of the games at office depot are also cd

    the british books and magazines come with tons of freeware on them and the disk is never sealed...the jewel case is just taped on back to the magazine and the jewel case just opens up and there's the cd

    people come into the bookstore and download all the freeware and trials and then put the disk back into the magazine or could tell by all the fingerprints on the disk ;)

    what i can't figure out is why more java books with disks, assuming they have not been lifted, don't come with something like bluej and sdk 1.3.1 or 1.4.1 on it?

    i still am going to wait until august and use the school's free tutor and learn some of the tricks and shortcuts in java

    ...btw what programming languages have you software development majors worked with that's harder than the obviously simple C/C++, vb, and java?
  16. applekid macrumors 68020

    Jul 3, 2003
    I really don't have any Java book recommendations except for this textbook we got last school year that was specifically designed for the AP course. I can't remember what it was called, but it was something along the lines Java Programming AP or Computer Science A. It was mostly purple and there were these yellow pages that asked questions about your program. You'd need a teacher's edition for the answers though.

    I really don't recommend using OS 9 to program with Java. I ditched OS 9 as soon as I could and moved up to Project Builder/XCode. Sure, you have to wait like 5 minutes for all of the classes to load, but once it's ready for your code and to build, it's great. Apple's own support for Java in OS 9 is flaky, and the version of CodeWarrior LE I had was for like Java 1.0. I also had to use the Terminal for one program. The Java Marine Biology Case Study... required for the AP exam. (shivers) I made a thread about it at, if you'd like to learn about it. Search for Java MBS in the forums. It's nice a example of using the Terminal and Java. It's quite similar to DOS, in my opinion. There's plenty of advantages using OS X to learn Java, in my opinoin.

    Oh, and make sure to ask any programming questions you have in the forums. It's thanks to the people there I was able to ace my two years of comp sci.
  17. JRam macrumors member


    Jun 25, 2004
    Santa Cruz


    Just wanted to put in my .02 cents. Haven't read all the posts (too much reading atm) so if I say something that has already been said, please dont hate ;)

    I skimmed the posts and didnt see JBuilder come up., its easy, and its free (for personal use). I used it when I was programing in java and it was very helpful, especially JBuilder X. Very intuitive to use, if you have any questions about it feel free to msg me somehow. Im not a professional although would gladly offer help to get ya started again.

    And for books on java, I give my complete endorsement to the Java 2 book in the Little Black Book series. It gives a lot of code snippets for useful functions and tricks if thats what your looking for. If your looking for a book with more information on the language itself and the basics, then give Head First Java a look into, by O'Reilly press... anything by O'Reilly is usually golden in my opinion. Head First is helpful if your tired of the usual way that programing books are written in.

    Wouldn't call java to be the hardest languages. Although I believe that a really personal thing about whats hard and not. I had a easy time with java once it *snapped*, it was my first programing language. Although C has proven to be a lot more complicated for me. Debugging in C is my personal hell....

    Hope I didnt repeat anything too basic...
  18. applekid macrumors 68020

    Jul 3, 2003
    I can concur with that. OOP is great in my opinion. I'm moving into the Cocoa territory with Java. Java "snapped" for me as well. I was struggling for a few months trying to understand Java. It didn't help my teacher didn't know that much Java in the first place nor was he is actually good at teaching. It was much more complicated than the BASIC I learned years ago and the programming I did on my TI calculator. Java was just so frustrating because of my situation. But once you get it, you can whip up any program you desire and you'll start loving Java. Even my grades showed it. I went from getting B's for my first quarters and a C on the midterm. By the end of the year, I had an A average.
  19. jsw Moderator emeritus


    Mar 16, 2004
    Andover, MA
    Sorry, just skimmed the thread, but were you aware that you can download the SDK's from here [but not for Macs, of course]?

    As I think others have said, once you go to OS X, Java is built into the system. You can access it from Terminal as well as via Xcode and Eclipse (as others have mentioned). OS X is an infinitely better environment for Java than OS 9.

    I develop Java professionally, mainly in Windows and Unix environments, but I play with it on the Mac as well, and the Mac is where I prefer to use it (work dictates the Windows/Unix stuff). If you have questions, please feel free to PM me or post them and PM me to let me know to look there. I'll be happy to help.
  20. jefhatfield thread starter Retired


    Jul 9, 2000
    thanks for tips

    i know one day it will all snap into place...visual basic was easy from day 1...some people say that about c/c++...but java takes time and i will be patient

Share This Page