How to load .java file to compiler?
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 开发者_Go百科run it, but I can not do it. What's wrong? Thank you.
You will need to compile it first using javac
:
javac YourClass.java
And then run:
java YourClass
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 :
- javac documentation
- java documentation
On the same topic :
- Compiling multiple packages using the command line in Java
- Compiling/running a java program in a different directory.
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.
精彩评论