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 13 of 13

Thread: Java on command prompt

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Java on command prompt

    Dear Sir,
    I Tanmay Sinha reading java as a very beginner.I 've installed Java software( jdk-6u11-windows-i586-p and

    netbeans-7.0-ml-javaee-windows) on my computer.Now I want to write java program by command Prompt but I am not able

    access it.So please help me....

    I write Java program

    class HelloWord
    {
    public static void main(string args[])
    {
    system.out.println("HelloWord");
    }
    }


    and I save it in D dive(Location) as D:\mywork and then by command prompt when use it initial as d: & enter then get the information

    D:\> but from here i am facing problems to use command prompt for compilation & run.




    Thanks & regards

    Tanmay Sinha


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Java on command prompt

    Why did you install netbeans if you want to compile & run from the command prompt?

    What happens when you type 'javac' at the command prompt?

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java on command prompt

    first change the dir to the location of saved .java file using the cd on your terminal application or command prompt.
    then type javac "asdf.java" whatever, then type java "asdf" and it will run

    Keep the code coming!
    Eric

  4. #4
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Java on command prompt

    I installed netbeans for compiling java program but after knowledge of java program through command prompt then.Dear friend I saved java program in D location as D:\mywork , When I used command prompt to write d: & enter then get the information D:\> but from here i am facing problems to use command prompt for compilation & run.

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Java on command prompt

    Okay but where I save the java program has saved in D location.Shall I save the program in C drive?U please tell me all steps....

  6. #6
    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: Java on command prompt

    Duplicate thread with
    http://www.javaprogrammingforums.com...reply-plz.html


    See other thread for how to create first HelloWorld program.

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Java on command prompt

    When I use the program on command prompt then get the following statements as below.Please get me & give me reply.

    C:\Documents and Settings\Administrator>d:
    D:\>cd\mywork
    D:\mywork>dir
    Volume in drive D has no label.
    Volume serial number is B21B-4805

    Directory of D:\mywork

    08/16/2011 07:55 PM <DIR>
    08/16/2011 07:55 PM <DIR>
    08/10/2011 01:58 AM 105 Helloword.java
    1 Files<s> 105 bytes
    2 Dir<s> 88,871,649.280 bytes free

    D:\mywork>

  8. #8
    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: Java on command prompt

    When I use the program on command prompt
    What program are you using?

    Did you read the tutorial posted on post#2 on the other thread?

  9. #9
    Member
    Join Date
    Aug 2011
    Posts
    31
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Java on command prompt

    I 've installed Java software( jdk-6u11-windows-i586-p and

    netbeans-7.0-ml-javaee-windows) on my computer.When I use the program on command prompt then get the following statements as below.Please get me & give me reply.

    C:\Documents and Settings\Administrator>d:
    D:\>cd\mywork
    D:\mywork>dir
    Volume in drive D has no label.
    Volume serial number is B21B-4805

    Directory of D:\mywork

    08/16/2011 07:55 PM <DIR>
    08/16/2011 07:55 PM <DIR>
    08/10/2011 01:58 AM 105 Helloword.java
    1 Files<s> 105 bytes
    2 Dir<s> 88,871,649.280 bytes free

    D:\mywork> .
    No I didn't read till now.u send here & tell me for compilation & run on command prompt.Thanksssss

  10. #10
    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: Java on command prompt

    If you have any specific questions or problems after you read the Tutorial, please post them here.

  11. #11
    Member
    Join Date
    Aug 2011
    Posts
    86
    My Mood
    Lurking
    Thanks
    16
    Thanked 4 Times in 4 Posts

    Default Re: Java on command prompt

    Quote Originally Posted by Tanmaysinha View Post
    When I use the program on command prompt then get the following statements as below.Please get me & give me reply.

    C:\Documents and Settings\Administrator>d:
    D:\>cd\mywork
    D:\mywork>dir
    Volume in drive D has no label.
    Volume serial number is B21B-4805

    Directory of D:\mywork

    08/16/2011 07:55 PM <DIR>
    08/16/2011 07:55 PM <DIR>
    08/10/2011 01:58 AM 105 Helloword.java
    1 Files<s> 105 bytes
    2 Dir<s> 88,871,649.280 bytes free

    D:\mywork>
    first the HelloWorld needs to be in file of same name, you have Helloword.java should be HelloWorld.java
    once you have renamed it, type at the prompt
    d:\mywork>javac HelloWorld.java
    Java is case sensitive.

    next type: java helloworld
    and you should have it.

  12. The Following User Says Thank You to Spidey1980 For This Useful Post:

    Tanmaysinha (August 17th, 2011)

  13. #12
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java on command prompt

    Go in the directory where your jdk is installed.
    Place your .java file in bin folder located inside jdk folder.
    Go to command prompt and move to jdk\bin directory
    And then write javac className.java
    java className

    Or set your environment variables such as JAVA_HOME, CLASSPATH

  14. The Following User Says Thank You to Mr.777 For This Useful Post:

    Tanmaysinha (August 17th, 2011)

  15. #13
    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: Java on command prompt

    Place your .java file in bin folder located inside jdk folder.
    Only for testing. Do not leave any of your files in the JDK folder.

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

    Tanmaysinha (August 17th, 2011)

Similar Threads

  1. Run command line structure in Java
    By soheilz92 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: April 20th, 2011, 02:26 AM
  2. command prompt, acquiring input without enter?
    By kitube in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 24th, 2011, 10:14 PM
  3. [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
  4. [SOLVED] Redirect command prompt output to log file.
    By goldest in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: November 24th, 2010, 05:26 AM
  5. Strange launch problem using command prompt
    By Asido in forum Java Theory & Questions
    Replies: 2
    Last Post: September 15th, 2010, 07:52 AM

Tags for this Thread