Does Java come on macs?

Discussion in 'Mac Programming' started by JuliaG, Nov 25, 2008.

  1. JuliaG macrumors newbie

    Joined:
    Nov 25, 2008
    #1
    My sister has to take a class on Java at community college to fulfill her requirements to move on to four year. Even though she does not have to take the class anymore I made her keep the book she bought because I am interested in learning. But I am way confused.
    I need an editor. I know mac comes with text edit so could that work as my editor for java. Also it says macs are known to come with Java already installed. I have a mac book pro. In the book it says to open terminal and enter to see if you have java installed.
    javac
    I did that but it did not recognize it so that means it does not come with java on my computer. Here is what it said
    Last login: Tue Nov 25 11:17:47 on ttys000
    apples-macbook-pro-2:~ juliagrohman$ javac
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are used
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system

    apples-macbook-pro-2:~ juliagrohman$
    So does that mean I Have dont have java included. If not how do I download java. Because it says the place to download java java.sun.com does not support mac operating systems. Please help me as I am very confused and want to start learning java. Please help me.
     
  2. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #2
    No, the response you got does mean javac is installed. If it wasn't you would get:
    Code:
    -bash: javac: command not found
    By the way, I enclosed that in CODE tags which makes it easier to read. You should do the same.

    Just typing "javac" isn't valid - you need to provide a source file for javac to compile, something like this:

    Code:
    public class HelloYellowJello {
        public static final void main(String[] args) {
            System.out.println("Hello yellow jello");
        }
    }
    
    saved to "HelloYellowJello.java" - the file name MUST match the class name in the file.

    Type after saving:
    Code:
    javac HelloYellowJello.java
    java HelloYellowJello
    Edit: depending on your Terminal setup, you might need to type
    Code:
    java -cp . HelloYellowJello
    to get it to run if you get "java.lang.NoClassDefFoundError: HelloYellowJello"
     
  3. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #3
    Alternatively, you can try this:
    Code:
    javac -version
     
  4. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #4
    Looks like it worked. You typed "javac" so it ran the javac program. That program looked at the command line for the name of a java program, did not find one, nor did it find anything else so it printed a list of valid things it would accept.
     
  5. JuliaG thread starter macrumors newbie

    Joined:
    Nov 25, 2008
    #5
    Thanks everyone. This is good news yes. I have one more question. Will textedit work for my java editor.
     
  6. HOiYA macrumors member

    Joined:
    Feb 13, 2008
    #6
    I would recommend that you use something other than textpad as your editor. You can download XCode from Apple. I hear it has a decent java editor. Personally I use eclipse. I have used it extensively for work for the past 8 years. And since it is open source, you will find almost any plugin you will ever need.
     
  7. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #7
    For a beginning programmer, I recommend a basic text editor (I use TextMate, which I can't recommend highly enough) and command-line build tools.

    Using an IDE, such as Xcode or Eclipse, abstracts the build process away from the student and hides it all behind this weird fog of binary voodoo. Getting your hands dirty, with javac and gcc and anything else, is really the best way to learn.
     
  8. JuliaG thread starter macrumors newbie

    Joined:
    Nov 25, 2008
  9. Amuraivel macrumors member

    Joined:
    Jan 31, 2006
    #9
    I disagree, there is nothing more frustrating than trying to do arcane commands at the command line when you are trying to learn how to program. One layer of complexity.

    That said some IDE's have a steep learning curve themselves.

    Xcode can just be used as a good text editor.

    For Java programming with a decent set of training wheels I like IntelliJ. It parses the code making things easier.
     
  10. daflake macrumors 6502a

    Joined:
    Apr 8, 2008
    #10
    LOL, the IDE debate has been going on for years. I started with a textpad but quickly moved to Netbeans for my IDE. It is all I use now. You have to be willing to dig into them though....
     
  11. Amuraivel macrumors member

    Joined:
    Jan 31, 2006
    #11
    While we are on the topic.

    Does anyone know of a parser/language spec set for Xcode three that works for java?

    Like if type: Math.

    That I get all the choices like, Math.round(), Math.sqrt(), etc.
     
  12. cube macrumors G4

    Joined:
    May 10, 2004
  13. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #13
    XCode does do that, you just need to hit the ESC* key to bring up code completion list.

    *This may not be the default key since I may have changed it on my machine, check your prefs for the "Completion List" command
     
  14. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #14
    Exactly.

    A beginning programmer really needs to learn the relationship between the characters they type and the way the compiler reacts to it and the output it generates. IDE's abstract that all away, showing you class trees and root nodes and autocompleting, you need to set up project files and go through the build manager and blah blah blah. Which is all wonderful once you understand what's going on (I love Eclipse), but too much all at once for the beginner.

    Take a plain text editor, type in 4 lines of "Hello World" code, type two commands into the shell and suddenly everything starts to make sense at the most basic level. You can ramp up very quickly from there.

    Start someone too quickly with a GUI and not only will they have to fight the learning curve, but you'll get questions like the one in the first post, where the OP didn't see the relationship between the command line and the output it generated (no offense intended to the OP, of course). Teach a kid to rely on a calculator too soon and their basic math skills will suffer.
     
  15. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #15
    I will breifly restate what I say every time this comes up:
    Learn with the basic tools (a text editor, java, javac, jar in this case). When you are totally comfortable with these, and find that your projects get very large, then you can learn ant and be even more proficient in standard tools, or switch to an IDE.

    Jumping into an IDE immediately robs you of valuable experience and knowledge.

    If/when you switch to an IDE, make sure it is crossplatform so you are not locked in to one environment.

    In summary, focus first on the language syntax and basic tools, not on learning an IDE.

    -Lee
     
  16. alphaod macrumors Core

    alphaod

    Joined:
    Feb 9, 2008
    Location:
    NYC
  17. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #17
    Oh, boy! Can we make this a pro-/anti-IDE debate AND a vi/emacs debate? Awesome!
     
  18. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #18
    ... Are you serious? Adding the IDE in the mix introduces a layer of complexity. Not only do you have to install and configure the IDE, but you still have to be able to read and understand the compiler when it complains.
     
  19. mkelly11 macrumors newbie

    Joined:
    Dec 1, 2008
    #19
    Take a look at using Java in xcode. You've got your source files sorted out neatly, your code highlighted neatly, and the tools you need all in one place. When you build it, the compiler doesn't just output some hard-to-deciper text; instead, it cleanly and concisely lists all of the errors and warnings, and even lets you jump to their location with a single click. But with a command prompt, you've got none of this functionality. While I guess you could say it's good to learn how to use the command line to compile, it's certainly not the highest priority thing when you're learning a new language. It really just throws out another unnecessary hurdle. I think it's best to start off in a comfortable spot, and then learn about what's going on underneath the hood of the IDE.
     

Share This Page