This content has been marked as final. Show 3 replies
Iam new to this language. I installed jdk in my system. And i have set the classpath in environment variablesUnnecssary
in PATH system variableNecessary, but you do realize that CLASSPATH is different from PATH?
1) C:\Documents and Settings\Archana>javac ..\..\pgms\Hello.javaWhat's the package statement inside Hello.java?
Compilation is working.
The directory containing the first part of the package name is where you should be running javac and java from.
Thanks for your reply.
The program is executing successfully when giving its command from its current directory. Suppose the file is in C:pgrms directory and iam executing from C:\pgms> it is fine. If i try to compile the program by giving the command C:\>javac pgms\Hello.java it is getting compiled but when i execute it by giving the command C:\>java pgms\Hello it is giving java.lang.NoClassDefFoundError.
Archana1604 wrote:The required argument for the java.exe application launcher is the fully qualified (and case sensitive) class name. It is not a file or path. Fully qualified class name means the package name plus the class name. If your source code starts with for example "package some.pack;" then the fully qualified class name is some.pack.Hello but if there is no package statement, then the fully qualified class name is the same as the class name - Hello.
If i try to compile the program by giving the command C:\>javac pgms\Hello.java it is getting compiled but when i execute it by giving the command C:\>java pgms\Hello it is giving java.lang.NoClassDefFoundError.
If you go here [http://java.sun.com/javase/6/docs/technotes/tools/index.html] and go to General Information, you can find links for setting Classpath and How Classes Are Found. It is recommended to to use the -cp command line switch to tell java where to look for classes. In your case, assuming no package name, "java -cp pgms Hello" or "java -cp c:/pgrms Hello"
There's a tutorial on packages here [http://java.sun.com/docs/books/tutorial/java/package/index.html]