Results 1 to 17 of 17
  1. #1
    java beginner is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default How do you use the Mac command line for Java?

    Could someone please write in numbered, step-by-step instructions how to run compile and run a basic java file using the Mac OS 10.6.x Terminal?

    Assume I wrote a Hello World type of program, and that it typed *perfectly*.
    Assume the file is called basketball and has been saved as a plain text file on the Mac with its file extension named .java as it is supposed to be: basketball.java

    I'm looking for a numbered set of instructions something like this:

    1)Launch Terminal
    2)Type this exact thing into the command prompt: ......
    3)Then do this exact thing......
    4)Then do this...
    5)You should see this....

    I cannot extrapolate the understanding from Windows. So please no "guessing" from Windows people. I need a Mac-head who knows point-by-point exactly what I'm facing on the screen, and point-by-point what I need to do.

    Right now, I'm getting a "file not found" for my basketball.java program.

    I first had it in the standard "Documents" directory that the system wants to put everything in by default. That didn't work. So then I tried putting the basketball.java file in the system/library/java folder. That still didn't work.

    I find the Mac file structure to be weird to tell you the truth. I simply have no idea what directory to put this file in, or how to tell the Mac Terminal program how to find it.

    I'm trying to learn how to code without relying on an IDE. But not being able to get the files found and lined up in the Terminal is really making it difficult.
    Last edited by java beginner; 05-07-2011 at 04:15 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Click here.

    db

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    [guessing from a linux user, so feel free to ignore...]

    Try "cd ~" in the console (aka "Terminal" since it has to be called something different to justify the price tag)

    Then "ls" to list the folder's contents. If you see "Documents" you're in business: "cd Documents" moves into the Documents folder and "ls" should reveal YourProgram.java

    The folder containing YourProgram.java is the one from which to issue the standard compile/run commands. (as you more or less suggest). STay away from system/library/java which - as it's name suggests - is for Java executables and resources not your program source files which are, essentially, data files.

  4. #4
    java beginner is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks,

    But I'm not looking to play "go fetch".

    I want the instructions right here on this site.

    I don't click on links of unfamiliar sites due to viruses, etc.

  5. #5
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default

    Quote Originally Posted by java beginner View Post
    Thanks,

    But I'm not looking to play "go fetch".

    I want the instructions right here on this site.

    I don't click on links of unfamiliar sites due to viruses, etc.
    If you are looking to tell people how to help you maybe you should pony up some money.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Right here, Darryl. Right here, right now. And request specification (5) suggests "with pictures". Possibly you could add circles and arrows and a paragraph explaining what each thing does.

    @OP: Sorry. Maybe a "mac-head" will wander by with what you need. That would be good. But it's important to realise how attitudes can "come across" in a text mediated discourse like this.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by pbrockway2 View Post
    Right here, Darryl. Right here, right now. And request specification (5) suggests "with pictures". Possibly you could add circles and arrows and a paragraph explaining what each thing does.
    What were you arrested for, kid?

  8. #8
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default

    Quote Originally Posted by java beginner View Post

    I don't click on links of unfamiliar sites due to viruses, etc.
    I thought macs couldn't get viruses

  9. #9
    java beginner is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks for guessing anyway, even though it will probably be a bridge-too-far for me to close the understanding gap between linux and mac.

    I don't understand what cd is.
    I don't know why there is a tilde after it
    I don't know what ls means
    I tried typing cd ~ into terminal and it didn't do anything. I just gave me another command prompt.

    Thanks for the advice on staying away from the system/library/java folder. When I put a copy of the file in there, it asked for my computer password. This seemed kind of weird. So I just took the file out of there. It asked for the system password again to remove the file. That tells me (in my own "I don't know what I'm talking about" kind of way) that this must be an important folder. It gets kind of protective when you try to add or subtract contents from it.

    Ironically, I *did* just get the file to work by placing it in my computer user name directory. So if my computer user name is Joe5000, I put it in there.

    I think it then created a file called basketball.class from the basketball.java file.

    This whole Terminal thing is very cryptic.

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Quote Originally Posted by Fubarable View Post
    What were you arrested for, kid?
    Litterin'...

  11. #11
    java beginner is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    When I wrote you should "see" this, I'm not talking about a picture. I'm talking about something like "You should see the screen output the following...". What I typed was a general construct to provide an understanding of the answer *format* I'm looking for. It was never meant to be micro-studied. If I knew exactly what should be typed into the procedural steps and how many steps there are for this task, I wouldn't need to ask the question.

    I am looking for exact *procedural* instructions for this particular task, point-by-point, exactly for the Mac. Like a cooking recipe. Complete these exact steps, and you will get the exact result you are looking for. No theory. Just follow the steps exactly.

    I spend *hours* helping people in forums with detailed, precision answers to their questions typed directly into the forum thread. Not here, obviously, because I'm a complete beginner at this topic. But on things I know well, you can bet I "pay it forward".

    Someone who really does know the exact answer to my question could type it step-by-step in two minutes right into this forum. Is that too much to hope for in a "New To Java" forum? I don't think so, but maybe I'm wrong. If someone does not want to help me in the way that I am requesting the help, they can just skip the question and ignore me. No need for negative energy.

    And as a benefit to this website, it helps its search engine visibility if you type detailed content directly into the forums. Linking out helps promote someone *else's* website in the eyes of the Googlebot. You can help promote *this* website to the Googlebot with fresh, relevant content typed in plain-text right into these forums.
    Last edited by java beginner; 05-07-2011 at 05:50 AM.

  12. #12
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    If you don't trust other links(which is a perfectly reasonable thing), try googling this term "Mac command line for Java", then click on links to safe sites. The first few hits contain some safe websites. Including one which is oracles java website.

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    ls=="list contents", like dir
    cd=="change directory", like its windows counterpart
    cd ~==change to my home directory (the directory with your name) It won;t do anything if you are already in that folder

    The macs use "debian style" security (I think) and, by design, you cannot access system folders using your user account and, moreover, the root account is not enabled! I am sort of loathe to mention how you *do* access them, because you're not supposed to.

    btw - if you locate the .java file with the "Finder" application there will be a gui command somewhere saying "Open a Terminal here" or some such. This will open the Terminal at the right place to compile/run.

    -----

    So, you are compiling now? If so, good. But you should rename the class and the .java file to Basketball to respect Java naming conventions. Recompile to create Basketball.class

  14. #14
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Quote Originally Posted by java beginner View Post
    Jeez, if you don't want to help, or can't help in the way I'm requesting you don't have to. Just cruise on by.

    It just never works that way! For my part I only littered the thread in the first place because of the tone of your OP. (@our esteemed moderator: only littering!)

    -----

    In my day job I have to deal with users whose mac clients don't wrok. When I point out the sentiment expressed above about how throughly cryptic the interface of this OS is, they give me that born-again look, their hearts filled with sorrow rather than anger. I just don't get it, do I?

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by pbrockway2 View Post
    (@our esteemed moderator: only littering!)
    AND creating a nuisance!

  16. #16
    java beginner is offline Member
    Join Date
    May 2011
    Posts
    9
    Rep Power
    0

    Default

    I'm not "telling" anyone to do anything. I am *requesting* information in a very specific way. I spend a lot of money on classes, textbooks, and private tutoring. I have no problem paying market rates for quality instruction. I think it would be a bit overkill to hire a private tutor for such a simple task as what I'm looking to accomplish.

    I just bought an expensive textbook on Java. But the one thing it glosses over is the one thing I need right now: the basic procedural steps to save, compile, and run a Java program in a Mac environment.

    I must have gotten it to compile and run, because it output the string text I put in the class block, exactly as it was supposed to based on the coding I typed in. But it's still very strange to me what the Terminal is doing, and where I'm supposed to save files on the Mac, etc.
    Last edited by java beginner; 05-07-2011 at 05:45 AM.

  17. #17
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    It's generally the same for all operating systems.
    1)navigate to containing folder
    2)javac FileName.java
    3)java FileName

Similar Threads

  1. Command line args for your java app!
    By aadem in forum New To Java
    Replies: 2
    Last Post: 03-04-2011, 10:05 PM
  2. Replies: 2
    Last Post: 07-02-2010, 03:20 PM
  3. Command line interface in Java
    By simmi in forum New To Java
    Replies: 1
    Last Post: 03-17-2010, 08:07 AM
  4. Java command line
    By agouzoul in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 01:12 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •