Link to home
Start Free TrialLog in
Avatar of KaranGupta
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);
   }
}

Open in new window

Avatar of Bill Bach
Bill Bach
Flag of United States of America image

Should be "String", not "string"?
Avatar of KaranGupta
KaranGupta

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);
   }
}

Open in new window

Specify your error.
Try this one:
public class MainClass
{
   public static void main(String[] aa)
   {
      String ABC = "Test";
	  ABC = "test123";
	  System.out.println(ABC);
   }
}

Open in new window

Can you at least post the result you are getting?
C:\Program Files\Java\jdk1.7.0_07\bin>javac D:\Karan_work\JavaP\MainClass.Java
javac: invalid flag: D:\Karan_work\JavaP\MainClass.Java
Usage: javac <options> <source files>
use -help for a list of possible options
Try putting path in double quotes:

javac "D:\Karan_work\JavaP\MainClass.Java"
Hi!

Make sure you have CLASSPATH pointing to the correct java class library
in the windows environment (ENV).

Regards,
   Tomas Helgi
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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\MainClass.Java"

Run
C:\Program Files\Java\jdk1.7.0_07\bin>java -cp "D:\Karan_work\JavaP" MainClass

Again, the above solution is solving the issue in your way which is not standard and actually not suggested
:)

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:

Again, the above solution is solving the issue in your way which is not standard and actually not suggested
and
But for easy work it is a good idea to have PATH variable set for the java install location.