yllee
asked on
can't find class name/class
I know there is a question with same subject but the solution
doesn't work in my case.
I have jdk ver 1.1.6 and installed in PC with Win98 2nd edition.
I able to compile source file to name.java. But,
java name.java, always give this error message : can't find
class name/class.
Pls help me solve this problem.
doesn't work in my case.
I have jdk ver 1.1.6 and installed in PC with Win98 2nd edition.
I able to compile source file to name.java. But,
java name.java, always give this error message : can't find
class name/class.
Pls help me solve this problem.
hi,
While compiling you have to give
javac name.java,
and while running the program you have to give
java name,
not java name.java.
The other thing is,in the name.java program suppose you have a class with different name like this:
name.java
class hello
{
public static void main(String []args)
{
System.out.println("hello" );
}
}
In this case compile the program with
javac name.java which will create hello.class.And if u want to run the program give java hello,it will work out.
But the above case wont work if i am declaring the class hello as public since public class should be decalared in the file which should contain the same name.And ensure that CLASSPATH is set or not.
While compiling you have to give
javac name.java,
and while running the program you have to give
java name,
not java name.java.
The other thing is,in the name.java program suppose you have a class with different name like this:
name.java
class hello
{
public static void main(String []args)
{
System.out.println("hello"
}
}
In this case compile the program with
javac name.java which will create hello.class.And if u want to run the program give java hello,it will work out.
But the above case wont work if i am declaring the class hello as public since public class should be decalared in the file which should contain the same name.And ensure that CLASSPATH is set or not.
ASKER
Sorry,
there is a typing mistake, it should be java name.class & the error message is : can't find class name/class.
In fact, I'm in Java programming. I simply follow the example in the book. So, I'm not really understanding your answer.
Here, below is one of the sample :
class Root {
public static void main(String[] arguments) {
int number = 225;
System.out.println("The square root of "
+ number
+ " is "
+ Math.sqrt(number) );
}
}
I save it as test.java. After javac test.java, root.class created.
According the book, output is : The square root of 225 is 15.0.
But, error message of java root : can't find class root ; error message of java root.class : can't find class root/class.
Here is my autoexec.bat for your reference :
C:\SBCD\DRV\MSCDEX.EXE /D:MSCD001 /V /M:8
SET BLASTER=A220 I5 D1 H5 P330 T6
SET CTSYN=C:\WINDOWS
C:\PROGRA~1\CREATIVE\SBLIV E\DOSDRV\S BEINIT.COM
C:\TVLITE\chgport 2DC
PATH C:\jdk11\bin;
set CLASSPATH=.;%CLASSPATH%;
rem PATH c:\PAGEMGR\IMGFOLIO;C:\PAG EMGR;C:\PR OGRA~1\ULT RAEDT;%PAT H%
Please let me know where goes wrong?
Thank you very very much.
there is a typing mistake, it should be java name.class & the error message is : can't find class name/class.
In fact, I'm in Java programming. I simply follow the example in the book. So, I'm not really understanding your answer.
Here, below is one of the sample :
class Root {
public static void main(String[] arguments) {
int number = 225;
System.out.println("The square root of "
+ number
+ " is "
+ Math.sqrt(number) );
}
}
I save it as test.java. After javac test.java, root.class created.
According the book, output is : The square root of 225 is 15.0.
But, error message of java root : can't find class root ; error message of java root.class : can't find class root/class.
Here is my autoexec.bat for your reference :
C:\SBCD\DRV\MSCDEX.EXE /D:MSCD001 /V /M:8
SET BLASTER=A220 I5 D1 H5 P330 T6
SET CTSYN=C:\WINDOWS
C:\PROGRA~1\CREATIVE\SBLIV
C:\TVLITE\chgport 2DC
PATH C:\jdk11\bin;
set CLASSPATH=.;%CLASSPATH%;
rem PATH c:\PAGEMGR\IMGFOLIO;C:\PAG
Please let me know where goes wrong?
Thank you very very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
will create myClass.class
SET CLASSPATH=.;%CLASSPATH%
java myClass
will execute that class