Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I type in:

javac D:\JavaTest\Hello.java

Here is what I get:

enter image description here

I'm a beginner in Java. I installed the Java SE Development Kit 6u22 from Sun's website.

I tried writing this code in Notepad:

 class Hello {
    public static void main (String[] args) {
       System.out.println("Welcome to the world of Java Programming.");
    } // method main
 } // class Hello

I tried to compile it in a Command Prompt following these instructions.

To compile and run this program, you need to have installed JDK and added a line to your path statement referring to the directory of where it was install + \bin. (e.g. path %path%;c:\jdk\bin;)

  • Type this file into Notepad or a similar text editor
  • Save it as Hello.java (class name + .java)
  • Drop to a Command Prompt
  • Type javac Hello.java (e.g. javac C:\work\Hello.java)
  • Type java Hello (e.g. java C:\work\Hello)
  • Watch the magic

I got an error message that 'javac' is not recognized as an external or internal command, operable program or batch file.

How can I fix this problem?

share|improve this question
3  
This is probably an issue with the path variable for the environment you're working in. If you are not using an IDE, you probably just need to add the location of javac.exe to your system PATH variable. –  MaQleod Nov 7 '10 at 0:30
    
what do you mean MaQleod? I made another folder on my D drive which I named it as JavaTest so when I compiled it in command prompt this is what I typed: javac D:\JavaTest\Hello.java and I got the error –  tintincutes Nov 7 '10 at 0:32

4 Answers 4

up vote 2 down vote accepted

You need to add the proper location of the javac binary to your PATH. See directions on the Oracle website.

After updating your PATH variable, open a new command prompt window. The old ones will not work as it rereads the variable upon starting.

share|improve this answer
    
@John: ok will try this one and will go back once it's ok. thanks –  tintincutes Nov 7 '10 at 0:45
    
exactly what I said. This should do the trick. –  MaQleod Nov 7 '10 at 0:50
    
I am reading the link from the Oracle website, and sorry it seems I can't understand, I tried copying the file Hello.java in the folder C:\Program Files\Java\jdk1.6.0_22\bin\javac and it is still the same error –  tintincutes Nov 7 '10 at 20:18
1  
@tin, you do not copy java files to the folder... You add that folder to your PATH. See this video: youtube.com/watch?v=Hl-zzrqQoSE&feature=related –  John T Nov 7 '10 at 20:24
1  
Or simply go to the start menu and click "Run", then type in sysdm.cpl and hit Enter. On the Advanced tab, you will see "Environment Variables" button on the bottom. –  John T Nov 7 '10 at 20:43

You sure you've installed the JDK? Have you restarted since installing it? As a side note, thats the correct way to do it, so I can't see why it wouldn't work.

share|improve this answer
    
yes I installed the JDK. I can find it in my C:\Program Files\Java\jdk1.6.0_22. I actually have 4 folders here. How can I restart it? –  tintincutes Nov 7 '10 at 0:30
    
I meant restarted the computer, have you done that? –  InBetween Nov 7 '10 at 0:31
    
no. do I need to restart? –  tintincutes Nov 7 '10 at 0:34

I create a gojava script in my home directory. It just adds the java SDK directory to the PATH. This isn't the approved method but I dislike having a huge PATH.

Open a command prompt window from Start menu or a desktop shortcut ...

Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\RGB> javac
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\RGB> gojava

C:\Users\RGB> javac
Usage: javac <options> <source files>

C:\Users\RGB> type gojava.bat
PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_22\bin

You could add cd C:\work\ to that batch file.

Even better, you could install Eclipse or Netbeans.

share|improve this answer
    
what is RGB here? Do I need to create this folder? –  tintincutes Nov 7 '10 at 20:09
    
do I need to create a folder work under C:\? –  tintincutes Nov 7 '10 at 20:19
    
You can put your Java source anywhere convenient. For example you could put it in "My Documents/Java" or "C:\Workspace" or anywhere that suits you. Consider that the "Java base directory". Java source code is normally arranged in "packages" based on reverse DNS domain names. E.g. com.tintincute.lottogame, com.tintincute.killerapp. The main java for this would be in <basedir>/com/tintincute/killerapp/Killer.Java. –  RedGrittyBrick Nov 7 '10 at 20:47

I looked at the image, and that is actually normal. When nothing displayed, it compiled fine!

Now you just have to run it.

When you compiled it:

c:\>javac d:\javatest\Hello.java

When it displayed nothing, it worked. It created a file hello.class.

Now you type:

c:\>java Hello

and it should display the output.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.