The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Total beginner question about Java

    Discussion in 'Windows OS and Software' started by Callidor, Jan 21, 2009.

  1. Callidor

    Callidor Notebook Evangelist

    Reputations:
    241
    Messages:
    665
    Likes Received:
    0
    Trophy Points:
    30
    Hi. I'm starting a programming class on Tuesday that deals with Alice and Java. I want to learn a little bit before I get started, seeing as the only programming experience of any kind that I have is just some very basic html.

    So, I'm following Sun's Java tutorial, I downloaded the Java SE Development Kit 6, and am following the steps to write a Hello World application. Where I'm hitting trouble is in trying to compile the source .java file. My command prompt window is returning the error "'javac' is not recognized as an internal or external command, operable program or batch file" According to the common problems page, this means that windows can't find the compiler. Ok..seems simple enough.

    There are two solutions offered. Either type in the file path for javac before the javac command, or edit the PATH variables so that this shouldn't be necessary. I am having no success with either approach and could use some help.

    First, I tried updating the PATH variable. This is supposed to tell Windows where to look for javac so that I don't need to manually type in the file path. The problem is, when I go to Environment Variables, like Sun's instructions tell me, I don't see anything called PATH which I can edit. (Judging by their instructions, it doesn't sound like I'm supposed to add it myself.)

    So next, I just tried typing in the file path for javac manually. The first problem with this approach is that depending on which specific page of Sun's instructions I look at, it tells me to do this different ways.

    When I do it this way, the command prompt returns the error that "C:\ is not an internal or external command ..." Another page reads

    When I type the file path this way, I don't get an error, but nothing happens. So..that's my situation. I'm fairly sure whatever mistake I'm making is very obvious, but bear in mind I am just starting out learning this. Any help welcomed.
     
  2. Laughing Laura

    Laughing Laura Notebook Guru

    Reputations:
    1
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    15
    I'm excited for you! Sounds like a cool class. I've looked into Alice a bit -- intriguing area of CS.

    Your second approach could have compiled your java file successfully.

    Check to see if you now have a MyClass.class file in the directory from which you wrote the "javac" command.

    The next step is to run it with the "java" command.

    ------------------------------------------------------------------------------------

    You can write a batch file to take care of this, once you see that it works, so that you don't have to keep typing (or cutting and pasting) the whole line each time.

    You just save the command in a text file using notepad or some other program that doesn't add formatting (I like notepad+++, a free resource) with the extension ".bat" .

    Then you can run it from the command line using the name of the file without ".bat"

    So, if the file is called "Compile.bat" -- you'd type "Compile" on the command line.

    -------------------------------------------------------------------------------------

    Depending on what your school recommends, at some point, you may want to check out NetBeans, which is an environment for developing java and a bunch of other things -- and it's free. It takes care of compiling and running and lots of other little details. But it also can add to the confusion.
     
  3. sipp11

    sipp11 Notebook Consultant

    Reputations:
    25
    Messages:
    131
    Likes Received:
    0
    Trophy Points:
    30
    actually, in Windows, you could do like
    Code:
    PATH=%PATH%;[ dir you want to set ]
    For example,
    Code:
    PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_\bin;
    Then you will be able to use 'javac', 'java' anywhere.

    This is not permanent solution though. If you set it permanently, you have to go check out in Control panel | system | advanced system setting | advanced tab | Environmental Variable | look at Path in system variables and edit it like above. Then you will be all set.

    I don't know if you prefer Notepad++ like Laughing Laura mentioned. I just think it might be better to use IDE such as eclipse. It's more complicated; there is a learning curve, but once you get used to it. It's faster/easier to code a program. Just my 2 cents.
     
  4. Laughing Laura

    Laughing Laura Notebook Guru

    Reputations:
    1
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    15
    To clarify --

    I only recommended notepad++ to create a batch file.

    I recommended NetBeans for coding, though I believe it's probably wisest to stick with whatever approach is used in class while you take the class.
     
  5. swarmer

    swarmer beep beep

    Reputations:
    2,071
    Messages:
    5,234
    Likes Received:
    0
    Trophy Points:
    205
    Using Explorer, check the path to javac or javac.exe on your system. (You can search for it or browse under the Program Files directory.) Right-click the "javac" file and select "Properties".

    The path of the file should be under the "Location" field in the properties window. Highlight this path and press Ctrl-C to copy it to your clipboard.

    If you don't see a "PATH" environment variable, look for one called "Path". If that's not there either, try creating it. You can use Ctrl-V to paste the path you copied earlier.

    You will probably have to open a new Command Prompt window after creating or modifying the env. variable.

    In the new window, enter this command:
    path

    It should print out the value of path variable and you can make sure it shows the new path that you added.

    Now try this command:

    where javac

    If your path is set up right, it should display the path to the javac.exe file.

    Then try running javac again:

    cd \directory\with\java\files\
    javac MyClass.java

    As an alternative to using the Path environment variable, you can try putting the path on the command line, as in:

    " [path]"\javac MyClass.java

    ...where " [path]" is replaced by the path you copied to the clipboard. Keep the quotes though... that'll be needed if there are any spaces in the path.
     
  6. codan

    codan Notebook Enthusiast

    Reputations:
    0
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    15
    If you are using windows, go to textpad.com and download textpad. Install it. It should find the java compiler automatically, and you will be able to edit, compile and run from within TextPad, though some of my students have reported problems.

    You could also try drjava.org for the Dr. Java editor that will hook to you compiler automatically.

    I thought Alice included and IDE, so no need to use a command line compiler. Maybe I am wrong.

    General advice - find a student that already has it working and have them sit down with you and your computer and walk you through the first couple of programs. This can save *hours* of wasted time.

    EDIT: I just downloaded Java 6 SE and then textpad and it installed perfectly. And I know DrJava does also. If you want a heavy weight environment (which I don't recommend for a beginner) download netbeans (find on sun somewhere). But I'd check with the prof or his/her website and get whatever they recommend.
     
  7. strangesweet

    strangesweet Notebook Deity

    Reputations:
    44
    Messages:
    786
    Likes Received:
    0
    Trophy Points:
    30
    You can get Visual Studio 2008 Professional for free at DreamSpark (owned by Microsoft) if you're a student.

    Alice was fun. Good to see another person jumping into Java. I just got started this semester, too!
     
  8. nfsnyc

    nfsnyc Notebook Consultant

    Reputations:
    72
    Messages:
    236
    Likes Received:
    0
    Trophy Points:
    30
    Fellow java beginner here :)

    Textpad is the way to go for beginners, and to compile from the command prompt you need to set your path.

    To do it the graphical way you (IN XP) right click my computer, hit properties, advanced tab, select environment variables on the bottom. Create a new one named "Path" and set the location to where your java files are installed. (Usually program files > java >jdk....

    In Vista its the same, just the path to the environment variables thing is a little different.

    If there is already a Path variable, you can click edit, put a semicolon ; and your path to it.

    Additionally once you do this, you have to make sure youre in the directory of your .java file when running javac so that the computer knows where YourClass.java is!

    BTW The reason I say textpad is better for beginners is because using an IDE you start to forget whats happening "behind the scenes", and if you never used textpad then you dont even know whats happening behind the scenes!! You use textpad for a bit, then once you know whats flying you use an IDE...thats my opinion.

    Im still with Textpad lol..
     
  9. strangesweet

    strangesweet Notebook Deity

    Reputations:
    44
    Messages:
    786
    Likes Received:
    0
    Trophy Points:
    30
    This is what I did to make it work.

    1) Find the location of javac.exe [if you have the latest version, it's same as what I put in at #5.
    2) Right Click 'Computer' and then Left Click 'Advanced system settings'
    3) Left Click 'Environment Variables...'
    4) Edit... 'Path'
    5) Add C:\Program Files\Java\jdk1.6.0_11\bin to 'Path'

    If you already have another things in path, just add ; before C:\.

    Try test your javac file. It should compile. That's how I got mine started few days ago.


    Is TextPad evaluation version?

    Anyway, is it bad habit to start with Visual Studio from the beginning? Any book recommendation? Our textbook sucks.. I got a free copy through DreamSpark though..
     
  10. Callidor

    Callidor Notebook Evangelist

    Reputations:
    241
    Messages:
    665
    Likes Received:
    0
    Trophy Points:
    30
    thanks for all the responses. I got it sorted out by adding a PATH variable, as I see some of you suggested :)

    Beyond getting the hello world app to run, sun's tutorial is actually very confusing about explaining the actual language lol >< I think I'll wait for the class before really diving in.
     
  11. nfsnyc

    nfsnyc Notebook Consultant

    Reputations:
    72
    Messages:
    236
    Likes Received:
    0
    Trophy Points:
    30
    I use this book :

    http://www.allbookstores.com/book/9780321479273/Tony_Gaddis/Starting_Out_With_Java.html

    I found it to be VERY good and explains things perfectly. Im currently up to chapter 6. This book teaches objects and methods AFTER teaching you the basics, which some like and some dont, I do.

    There is a new version released this month apparently:

    http://www.allbookstores.com/book/9780136080206/Tony_Gaddis/Starting_Out_With_Java.html

    Shop around though it will be cheaper.

    My teacher recommends starting with textpad, this teaches you the basics you need to know.
     
  12. nfsnyc

    nfsnyc Notebook Consultant

    Reputations:
    72
    Messages:
    236
    Likes Received:
    0
    Trophy Points:
    30
    I tried learning some Java things online, I found it WAY too complicated, this is one case where books are better!
     
  13. Callidor

    Callidor Notebook Evangelist

    Reputations:
    241
    Messages:
    665
    Likes Received:
    0
    Trophy Points:
    30