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

KaranGuptaAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
C:\Program Files\Java\jdk1.7.0_07\bin should be in your PATH variable. And then you should do

D:\Karan_work\JavaP>javac MainClass.java

Open in new window

0
 
Bill BachPresidentCommented:
Should be "String", not "string"?
0
 
KaranGuptaAuthor Commented:
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

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Ken ButtersCommented:
Specify your error.
0
 
Bill BachPresidentCommented:
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?
0
 
KaranGuptaAuthor Commented:
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
0
 
Ken ButtersCommented:
Try putting path in double quotes:

javac "D:\Karan_work\JavaP\MainClass.Java"
0
 
Tomas Helgi JohannssonCommented:
Hi!

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

Regards,
   Tomas Helgi
0
 
Pramod KumarCommented:
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
0
 
CEHJCommented:
:)

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
0
 
Pramod KumarCommented:
@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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.