-
just starting
I am just starting to learn java, I have some programs coded, but when I enter javac into the command prompt, it gives me an error saying "javac is not recognized as an internal or external command, operable program or batch file." I adjusted my environment variables (class path & path), but still no luck. What do I need to configure to get this to work?
-
Add the location of your java home to your path. Try running java -version from the command prompt. I'm thinking it'll throw an error. Once you've defined the entry correctly, the above command should work.
-
when i type in java -version it comes back fine, with a version of 1.6.0_01. what is the java home path location?
-
ok, i added the java path location, now I can compile the program but can't run it. I get an error that says "Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"
How do I fix this?
-
are you running the javac from the same directory the program is in? you can supply classpath information by:
javac -cp <classpath>
-
yes, I'm running it from the folder that my program is saved on. but still getting the same error message
-
Can you post the exact command your using to execute the code.
-
in the directory that my program is saved in I type:
javac HelloWorld.java
that comes back fine, and a HelloWorld.class file is created
then I type:
java HelloWorld
and then i receive the error:
"Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld"
-
I don't know what your doing wrong. I just wrote a quick class to that. From the command prompt where your file is at:
1. javac HelloWorld.java
2. java HelloWorld
HelloWorld.java:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
>>>>>>>>>>>>>>>>>>>>>>
output
>>>>>>>>>>>>>>>>>>>>>>
HelloWorld
-
the only thing i can think of are the environment variables, but i've tried changing them, with no luck.
-
specbailey: Working with classpath is not easy. You will need to practice about it. There are several resources to read for learning managing classpath.
But alternatively you can try to use an IDE (Eclipse or Netbeans) which will make the classpath management intuitive.
-
I am still having the same problems. I cannot compile programs or execute them. I have checked the path and the classpath. What else do I need to do to run java programs?
-
when I type javac HelloWorld.java I get an error that says:
'javac' is not recognized as an internal or external command, operable program or batch file.
which means that it will not compile so I cannot go on from there.
When I type java -version i get:
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
-
do 1 thing,just save ur programm in bin folder in ur jdk directory and then simply compile it.........javac HelloWorld.java
else tell me ur full path of java directory
-
specbailey,
Thank you for your post. It sounds as though you and I are having the same kind of problems. I infer that you are using Java 2 SDK 1.6.x.x. Is the OS WinXP? and you are trying to compile and run a "Hello World" program from Command Prompt.
The error message you get when you try javac Hello World.java is the same as I get.
So when I try to configure SDK 1.3.1_20 according to the text I am reading I need to find a file AUTOEXEC.BAT, which I cannot. Apparently the OS in play when the book was published was 2000 and NT. Not being a Windows user I asked another forum about this file and was directed to a MS instruction page where I learn that the variables once maintained by AUTOEXEC.BAT are now maintained by the Registry in XP. Going to My Computer, as you did, I found the editing feature for environmental variables under Propeerties, but I do not know what information to add so as to point to PATH and CLASSPATH for Java. What entrys did you make?
Thanks
-
Spec, can you copy your code in? Wondering if you have declared a package.
-
its not a problem with the code, in cmd u were passing arguments wrong, what i did was just right clicked on the .java and selected "open with" and opened it with javac.exe, i would also recommend downloading JKD 6.0 or higher and running it with the javac.exe in the JDK bin
:)
-
I copied my .java file into the bin folder, now I am able to compile the program and there is a .class created, but now I can't execute the program by typing:
java HelloWorld
I get an error that says:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class
even though it compiled ok.
-
what type of template is the program? hsa, applet, application?
-
I don't know what template the program is... here is the code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}