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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: My Java program is failing to run in command prompt

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My Java program is failing to run in command prompt

    My Java program is failing to run in command prompt and no result is produced.I am currently using windows 8 and I have changed my Environmental variable to C:\Windows\system32;C:\Program files\Java\jdk\bin.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    What error do you get? What code are you trying to run?
    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!

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Java program is failing to run in command prompt

    public class MyFirstJavaProgram{
    public static void main(String[]args){
    System.out.printIn("Hello World");
    }
    }
    When I click enter to run,nothing is happening

  4. #4
    Junior Member Tjones787's Avatar
    Join Date
    Jan 2014
    Location
    Lagos, Nigeira
    Posts
    16
    My Mood
    Asleep
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: My Java program is failing to run in command prompt

    What error did you get when you try to run the program.
    Tjones787

  5. #5
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: My Java program is failing to run in command prompt

    What conmmands did you use to compile and run?

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Java program is failing to run in command prompt

    No error but simply its not producing the output hello world.When I press enter the cursor moves to the next line

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    System.out.printIn != System.out.println()

    Upper-case I != lower-case l.

    That should generate a compiler error. What IDE are you using? I *highly* suggest using the command line to compile your code until you have a better understanding of what's going on.
    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!

  8. #8
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

  9. #9
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Java program is failing to run in command prompt

    I used C:\'javac MyFirstJavaProgram.java'
    and then C:\'java MyFirstJavaProgram'

  10. #10
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: My Java program is failing to run in command prompt

    If you are running this program from command prompt, please can you type commands "javac" and "java" and check if its showing some output?
    Thanks and regards,
    Sambit Swain

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    You need to post the full text of your command prompt, starting with the javac command. Just copy any paste it here.
    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. #12
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Java program is failing to run in command prompt

    okay I wil try this.I am using jdk 1.6.0_35

    --- Update ---

    Microsoft Windows [Version 6.2.9200]
    (c) 2012 Microsoft Corporation. All rights reserved.

    C:\Users\Attache Students>C:\'javac MyFirstJavaProgram.java'
    'C:\'javac' is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\Attache Students>

    Now its failing to recognize javac

  13. #13
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    You need to make sure your jdk bin is on your path. Recommended reading: Lesson: Common Problems (and Their Solutions) (The Java™ Tutorials > Getting Started)
    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. #14
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Java program is failing to run in command prompt

    okay Kevin thanks

  15. #15
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: My Java program is failing to run in command prompt

    As per the above comment by KevinWorkman, if path is set correctly then you java program will execute successfully. Post here if you find any further issues.
    Thanks and regards,
    Sambit Swain

  16. #16
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    Quote Originally Posted by Sambit View Post
    As per the above comment by KevinWorkman, if path is set correctly then you java program will execute successfully. Post here if you find any further issues.
    The program he posted contains compiler errors, as I pointed out.
    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!

  17. #17
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: My Java program is failing to run in command prompt

    Sorry, I missed that. it has to println() method and import is missing.
    Thanks and regards,
    Sambit Swain

  18. #18
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: My Java program is failing to run in command prompt

    There is no import missing.

  19. #19
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: My Java program is failing to run in command prompt

    Yes, import statements are not required for this.
    Thanks and regards,
    Sambit Swain

  20. #20
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    Quote Originally Posted by Sambit View Post
    it has to println() method and import is missing.
    It's great that you're trying to help, but please make sure your advice is accurate before you post.
    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!

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: My Java program is failing to run in command prompt

    C:\Users\Attache Students>C:\'javac MyFirstJavaProgram.java'
    Leave off the "C:\". That tells the OS to look in the C:\ folder for the javac command.
    If the bin folder is on the PATH, you should be able to enter javac without a path:
    C:\Users\Attache Students>javac MyFirstJavaProgram.java
    If you don't understand my answer, don't ignore it, ask a question.

  22. The Following User Says Thank You to Norm For This Useful Post:

    KevinWorkman (January 23rd, 2014)

  23. #22
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My Java program is failing to run in command prompt

    Quote Originally Posted by Norm View Post
    Leave off the "C:\". That tells the OS to look in the C:\ folder for the javac command.
    If the bin folder is on the PATH, you should be able to enter: javac without a path
    C:\Users\Attache Students>javac MyFirstJavaProgram.java
    Good catch. My brain just absorbed that as part of the command prompt path. I must be getting old...
    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!

  24. #23
    Junior Member
    Join Date
    Jan 2014
    Posts
    23
    My Mood
    Mellow
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: My Java program is failing to run in command prompt

    there is problem with ur java,,
    just open command prompt and
    set path of your bin

    i know it wont make any change as you have added the path to envt. variable .. but just check..

    if the same error proccedes i suggest you to use netbeans.

  25. #24
    Junior Member
    Join Date
    Jan 2014
    Location
    Zimbabwe
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: My Java program is failing to run in command prompt

    I think its now working.I have opened blue j and its running after I have installed a new jdk

    --- Update ---

    import java.io.*;
    public class DeductionRecords{
    string DeductionRecords="DED";
    string Transactiontype;
    static final short ADCODE=4360;
    string Payeecode;

    double Amountincents;

    public DEDUCTION RECORDS(string name){
    this.name=name;
    }
    //Assign payee code to variable payee code
    public void recpayeecode (String recpayeecode){
    payeecode=recpayeecode;
    }
    /*Assign Amount in cents to variable amount in cents*/
    public void recamountincents(double recamountincents){
    amountincents=recamountincents;
    }
    /*Assign policy ref number to variable policy ref number*/
    public void recpolicyrefnumber(string policyrefnumber){
    policyrefnumber=recpolicyrefnumber;
    }
    //Print the deduction records details
    public void print DeductionRecords(){
    system.out.printIn("name:"+name);
    system.out.printIn("ec number:"+ec number)
    system.out.printIn("Transaction type:+Transaction type)
    system.out.printIn("AD CODE:+AD CODE)
    system.out.printIn("payee code:"+payee code)
    system.out.printIn("policy ref number:+policy ref number)
    system.out.printIn("From date:"+From date)
    system.out.printIn("To date:"+To date)
    system.out.printIn("Amount in cents:"=amount in cents)
    }
    }
    My code is failing to compile on line 23 where its written public void print DeductionRecords(){
    I am using Blue J.May you examine my code

    --- Update ---

    import java.io.*;
    public class DeductionRecords{
    string DeductionRecords="DED";
    string Transactiontype;
    static final short ADCODE=4360;
    string Payeecode;

    double Amountincents;

    public DEDUCTION RECORDS(string name){
    this.name=name;
    }
    //Assign payee code to variable payee code
    public void recpayeecode (String recpayeecode){
    payeecode=recpayeecode;
    }
    /*Assign Amount in cents to variable amount in cents*/
    public void recamountincents(double recamountincents){
    amountincents=recamountincents;
    }
    /*Assign policy ref number to variable policy ref number*/
    public void recpolicyrefnumber(string policyrefnumber){
    policyrefnumber=recpolicyrefnumber;
    }
    //Print the deduction records details
    public void print DeductionRecords(){
    system.out.printIn("name:"+name);
    system.out.printIn("ec number:"+ec number)
    system.out.printIn("Transaction type:+Transaction type)
    system.out.printIn("AD CODE:+AD CODE)
    system.out.printIn("payee code:"+payee code)
    system.out.printIn("policy ref number:+policy ref number)
    system.out.printIn("From date:"+From date)
    system.out.printIn("To date:"+To date)
    system.out.printIn("Amount in cents:"=amount in cents)
    }
    }
    My code is failing to compile on line 23 where its written public void print DeductionRecords(){
    I am using Blue J.May you examine my code

  26. #25
    Member
    Join Date
    Oct 2013
    Location
    United Kingdom
    Posts
    62
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: My Java program is failing to run in command prompt

    If you check the compilation error, you can easily understand the issue. Check the syntax of method defination..
    Thanks and regards,
    Sambit Swain

Page 1 of 2 12 LastLast

Similar Threads

  1. Problem In Accessing User Machine Command Prompt From Java Program Which Runs On Server
    By AbhijitFromBangalore in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 10th, 2013, 10:50 AM
  2. Java program not running in command prompt
    By Padmahasa in forum Computer Support
    Replies: 1
    Last Post: August 10th, 2012, 07:22 AM
  3. Java command prompt
    By Tanmaysinha in forum Java Theory & Questions
    Replies: 2
    Last Post: August 30th, 2011, 09:30 AM
  4. Java command prompt
    By Tanmaysinha in forum Java Theory & Questions
    Replies: 1
    Last Post: August 29th, 2011, 03:05 PM
  5. [SOLVED] can't run javac directly from command prompt
    By epezhman in forum Java IDEs
    Replies: 7
    Last Post: January 12th, 2011, 07:38 PM