KaranGupta
asked on
issue in java program
What is the issue in this program?
class MainClass
{
public static void main(String aa[])
{
string ABC = "Test";
ABC = "test123";
System.out.println(ABC);
}
}
Should be "String", not "string"?
ASKER
Still I am getting the same error
class MainClass
{
public static void main(String aa[])
{
String ABC = "Test";
ABC = "test123";
System.out.println(ABC);
}
}
Specify your error.
Try this one:
public class MainClass
{
public static void main(String[] aa)
{
String ABC = "Test";
ABC = "test123";
System.out.println(ABC);
}
}
Can you at least post the result you are getting?
ASKER
C:\Program Files\Java\jdk1.7.0_07\bin >javac D:\Karan_work\JavaP\MainCl ass.Java
javac: invalid flag: D:\Karan_work\JavaP\MainCl ass.Java
Usage: javac <options> <source files>
use -help for a list of possible options
javac: invalid flag: D:\Karan_work\JavaP\MainCl
Usage: javac <options> <source files>
use -help for a list of possible options
Try putting path in double quotes:
javac "D:\Karan_work\JavaP\MainC lass.Java"
javac "D:\Karan_work\JavaP\MainC
Hi!
Make sure you have CLASSPATH pointing to the correct java class library
in the windows environment (ENV).
Regards,
Tomas Helgi
Make sure you have CLASSPATH pointing to the correct java class library
in the windows environment (ENV).
Regards,
Tomas Helgi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
First, the way you are compiling, no need to set the PATH variable as "javac" is found and you are getting java compiler generated error and not the 'invalid javac command'. But for easy work it is a good idea to have PATH variable set for the java install location.
Second, The javac expect a java file/path without a space. As per your post I do not see a space in the file path. Be sure that you do not have any space in the file path. But to be in safe side keep the whole path enclosed in double quotes as below:
(As buttersk (ID: 38418717))
Compile
C:\Program Files\Java\jdk1.7.0_07\bin >javac "D:\Karan_work\JavaP\MainC lass.Java"
Run
C:\Program Files\Java\jdk1.7.0_07\bin >java -cp "D:\Karan_work\JavaP" MainClass
(As buttersk (ID: 38418717))
Compile
C:\Program Files\Java\jdk1.7.0_07\bin
Run
C:\Program Files\Java\jdk1.7.0_07\bin
Again, the above solution is solving the issue in your way which is not standard and actually not suggested
:)
It would be found ;) - buttersk is working in the bin directory, which s/he shouldn't be doing
First, the way you are compiling, no need to set the PATH variable as "javac" is found
It would be found ;) - buttersk is working in the bin directory, which s/he shouldn't be doing
@CEHJ,
Yes, thats why at the end i wrote:
Yes, thats why at the end i wrote:
Again, the above solution is solving the issue in your way which is not standard and actually not suggestedand
But for easy work it is a good idea to have PATH variable set for the java install location.