Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    IN THIS SIMPLE CODE THE CMD DOES NOT ABLES TO FIND "A.CLASS"
    I COMPILE THIS BY- javac a.java and run by- java a

    class a
    { public static void main(String ar[])
    {
    System.out.println("hello rahul");
    }
    }


  2. #2
    Member samfin's Avatar
    Join Date
    Dec 2010
    Location
    Manchester UK
    Posts
    37
    Thanks
    1
    Thanked 5 Times in 4 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    The Main method should read
     public static void main(String[] args)
    Try that and see if that helps
    If not, what error are you getting?

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    change the class name 'a' to 'A' it will wrks

    class A

  4. #4
    Junior Member iCoder's Avatar
    Join Date
    Jan 2011
    Location
    127.0.0.1
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    The error is due to the ar it must be args. -As samfin said.
    Correct it, ur code will be working even if its class a or class A or class whatever

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,172
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by iCoder View Post
    The error is due to the ar it must be args. -As samfin said.
    Correct it, ur code will be working even if its class a or class A or class whatever
    This is absolutely not true. All of the following work fine:

    class Main  {
        public static void main(String[] ar){
        	System.out.println("Works");
        }
    }

    class Main  {
        public static void main(String[] iLikeCats){
        	System.out.println("Works");
        }
    }

    class Main  {
        public static void main(String... a){
        	System.out.println("Works");
        }
    }

    Run them and see. Seriously, what's with posting help that is actually completely wrong?

    Chances are, the OP was trying to compile a class with the wrong name- such as A.java instead of a.java, or vice versa.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. The Following 3 Users Say Thank You to KevinWorkman For This Useful Post:

    copeg (January 20th, 2011), javapenguin (January 20th, 2011), JavaPF (January 20th, 2011)

  7. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    lol @ iLikeCats

    rahul dixit, please post the error you are getting or attach a screenshot.

    Thanks
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  8. #7
    Junior Member iCoder's Avatar
    Join Date
    Jan 2011
    Location
    127.0.0.1
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    then y did his code didn't compile if it's correct ??

    By the way thanks i dnt knw that we can give anything after String[].

  9. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,172
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by iCoder View Post
    then y did his code didn't compile if it's correct ??

    By the way thanks i dnt knw that we can give anything after String[].
    His code didn't compile because, presumably, he was trying to compile a class that didn't exist.

    Say his file was named a.java- Putting aside the fact that class names should start with a capital letter and be more meaningful than a single character.

    He then tried to compile A.java. That's not the same as a.java. A != a. Just like he couldn't compile iReallyLikeCats.java, if his file was actually named iLoveCatsSoMuch.java.

    Simple as that.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #9
    Junior Member iCoder's Avatar
    Join Date
    Jan 2011
    Location
    127.0.0.1
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    But he has stated that

    I COMPILE THIS BY- javac a.java and run by- java a

    so probably it must work. rite ??

  11. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,172
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by iCoder View Post
    But he has stated that

    I COMPILE THIS BY- javac a.java and run by- java a
    He also typed the error message in all caps, eliminating any assurances that the error is talking about a.java and not A.java or A.JAVA or A.jAvA.

    There is also the likelihood that he didn't copy and paste the error, or the file names, into the forum editor exactly. There is just too much uncertainty, which is why we're waiting on clarification from the OP. But until (if) that happens, I'd be willing to bet that he spelled the file name wrong, probably by using the wrong case.

    Because the error he's talking about isn't a compiler error. It's an error saying that the specified file could not be found, let alone compiled. Even if the main(String [] args) error you guys erroneously came up with was real, the compiler didn't even get a chance to see that yet, since it has not been given a valid file name.

    Quote Originally Posted by iCoder View Post
    so probably it must work. rite ??
    If it worked, why would he have posted in the first place?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #11
    Junior Member iCoder's Avatar
    Join Date
    Jan 2011
    Location
    127.0.0.1
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    so probably it must work. rite ??

    What i meant is if he had ran the prg using the correct classname it would have worked.

    Assumptions apart. Lets wait if he provides any OP. From that we can conclude what went wrong.

  13. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,172
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by iCoder View Post
    so probably it must work. rite ??

    What i meant is if he had ran the prg using the correct classname it would have worked.

    Assumptions apart. Lets wait if he provides any OP. From that we can conclude what went wrong.
    Ah. Assuming he has no other problems, then yeah, it should work as long as he compiles and runs the correct file.

    I'd still be willing to bet that he was using the wrong file name. I wouldn't hold your breath on getting any more updates from the OP.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #13
    Junior Member iCoder's Avatar
    Join Date
    Jan 2011
    Location
    127.0.0.1
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Then lets conclude he had used a wrong file name

  15. #14
    Member samfin's Avatar
    Join Date
    Dec 2010
    Location
    Manchester UK
    Posts
    37
    Thanks
    1
    Thanked 5 Times in 4 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by KevinWorkman View Post
    Seriously, what's with posting help that is actually completely wrong?
    It wasn't my intent to deliberately post something that was wrong. Admittedly I could have checked the fact before posting but in every code example I've ever seen it is put as public static void main(String args[]) and seeing it differently there seemed wrong and it never occured to me that it could be something else.
    Anyway, I've learned something today which is why I joined this forum in the first place.

  16. #15
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by samfin View Post
    It wasn't my intent to deliberately post something that was wrong. Admittedly I could have checked the fact before posting but in every code example I've ever seen it is put as public static void main(String args[]) and seeing it differently there seemed wrong and it never occured to me that it could be something else.
    Anyway, I've learned something today which is why I joined this forum in the first place.
    Well said
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  17. #16
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    I think the thread creator should go through this.
    How to ask question ?l

    and i request admin to create a page for which question should be answer ?
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  18. #17
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,172
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by DanBrown View Post
    and i request admin to create a page for which question should be answer ?
    What does that even mean?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  19. #18
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Exclamation Re: WHY THE CMD DOES NOT ABLE TO FIND "A" IN THIS SIMPLE PROGRM

    Quote Originally Posted by KevinWorkman View Post
    What does that even mean?
    He wants permission to create a page to decide which type of questions should be even allowed to be answered.

Similar Threads

  1. Replies: 13
    Last Post: October 13th, 2010, 11:20 AM
  2. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM
  3. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  4. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 07:35 AM