0

Ok, I am beginner in JAVA. I have just started. I downloaded Java SE Development Kit 6u21 and wrote a program, saved it in .java and try to run it, but I can not do it. What's wrong? Thank you.

good_evening
  • 21,085
  • 65
  • 193
  • 298

3 Answers3

6

You will need to compile it first using javac:

javac YourClass.java

And then run:

java YourClass
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
6

If you really want to do it manually, you have to use the javac compiler in command line like this :

javac package/of/your/project/YourClass.java

and then

java package.of.your.project.YourClass

Your class YourClass must have a public static void main(String... args) method.

If your class isn't in a package, then javac YourClass.java and java YourClass are sufficient.

You should really consider to use an IDE which will handle this for you.


Resources :

On the same topic :

Community
  • 1
  • 1
Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
  • 1
    I actually think it's good for anyone to do these things manually for at least the first Hello World program, just to get to know the basics. – Carlos Sep 05 '10 at 21:17
  • I agree, I was just implying that manual compilation isn't the only way to compile. – Colin Hebert Sep 05 '10 at 21:19
  • 'javac' is not recognized as an internal or external command, operable program or batch file – good_evening Sep 05 '10 at 21:39
  • 1
    You may not have defined the JDK bin folder as a part of your $PATH (or %PATH%) environment variable. See http://download.oracle.com/docs/cd/E17824_01/dsc_docs/docs/javacaps/installing/jcapsinstgui.inst_jdk_javahome_t.html – Colin Hebert Sep 05 '10 at 21:47
1

I suggest you read and follow this tutorial by Oracle: "Hello World!" for Microsoft Windows. Once you have successfully done so, you should have JDK installed and know how to run your program.

If you are still getting "'javac' is not recognized as an internal or external command, operable program or batch file", try reading these: How do I set or change the PATH system variable? and PATH and CLASSPATH.

Carlos
  • 2,503
  • 26
  • 29