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.

7
  • Darin's answer might help you, but if not, consider telling what "I can not do it" means exactly. And also how did you try to run it. Commented Sep 5, 2010 at 21:11
  • Based on your answer to Colin: Do you have Java JDK installed and is it in your path? Commented Sep 5, 2010 at 21:42
  • I have installed it and what a heck means is it in my path?! Commented Sep 5, 2010 at 21:46
  • @hey, there are basic things that you should learn about a computer before starting to program. If you don't know what a path means I would strongly suggest you learning this before starting to write code. Commented Sep 5, 2010 at 21:49
  • I know what path means, it is C:\program files\etc... But what did he mean asking me "is it in my path"? Commented Sep 5, 2010 at 21:52

3 Answers 3

6

You will need to compile it first using javac:

javac YourClass.java

And then run:

java YourClass
Sign up to request clarification or add additional context in comments.

Comments

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 :

4 Comments

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.
I agree, I was just implying that manual compilation isn't the only way to compile.
'javac' is not recognized as an internal or external command, operable program or batch file
You may not have defined the JDK bin folder as a part of your $PATH (or %PATH%) environment variable. See download.oracle.com/docs/cd/E17824_01/dsc_docs/docs/javacaps/…
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.

1 Comment

I wasn't angry, frustrated at most. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.