[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

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

0
KaranGupta
Asked:
KaranGupta
  • 2
  • 2
  • 2
  • +3
1 Solution
 
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
 
Ken ButtersCommented:
Specify your error.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
CEHJCommented:
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now