I'm trying to run a simple java test code. I'm getting a "can not find or load main class file "(something like that)
The tutorial I'm following uses this command
-> javac name.java (javac doesn't work, using ->java ..)
-> dir (shows the classname as a file)
> java classname
> outputs "hello world"
I can't seem to get past the ->java running.java
class apples //everything begins with a class - need this to do anything
{
public static void main(String args[])//method
{
System.out.println("Hello World");
}
}
4 Answers 4
(削除) There could be a few problems here. Check the following:
- Are you saving the file as the name of the class plus .java, e.g.
apples.java - When you execute it, are you typing the name of the class or the name of the class file? you should be typing
java apples, notjava apples.classorjava apples.java. (削除ここまで)
EDIT:
I Noticed you haven't compiled the program using javac, which makes the progrm unrunnable by java [program_name]. You need to run javac [java_sourcde_file_name] to generate a .class file. If javac doesn't work, maybe:
- You don't have the JDK (Java Development Kit) installed and should download it from Oracle
javacis not in your PATH - unlikely but possible - see http://www.apl.jhu.edu/~hall/java/beginner/settingup.html.javacruns properly but your program doesn't compile properly. this seems unlikely given the program you posted looks fine.
10 Comments
dir "D:\Program Files (x86)\Java\jre7\bin". is javac.exe listed?class Apples //- need this to do anything
{
public static void main(String args[])//everything begins with a method
{
System.out.println("Hello World");
}
}
Make sure you are in current directory of java file
compile as
javac Apples.java
Run as
java Apples
Before working in it , should need to know the coding convention it would be better to work java
Comments
Well. All you have to do in Jaca is navigate you where your class files are stored and then use java "class name". You DO NOT need to put .java or .class. Just the name.
3 Comments
change your class name from apples to Apples (naming convention for java class names): http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java
also recommend you to change the file name accordingly...
then recompile and run it
javac Apples.java
java Apples
cheers
*.javafile into*.classfile withjavac. It is called "compiling".