Running a Java File using Command Prompt


  • To execute a .java file u have to have installed JDK.
    Make sure, u have JDK (Java Development Kit) installed in ur pc
    if u don’t have it, then u can download the latest version of JDK from (http://java.sun.com/javase/downloads/index.jsp)
    download and install it.

  • create a .java file using a text editor ( like Notepad, Wordpad )

    Test.java

    Test.java

  • give a name (Example : Test) with .java extension [Test.java]
    remember the file type must have the extension .java (not .txt)

  • Copy this file and paste it in ‘bin’ folder.
    U will get it where u installed ur JDK.
    By default it should be, C:\Program Files\Java\jdk1.6.0_13\bin

  • Running Command Prompt :
    1. Start menu > All Programs > Accessories > Command Prompt. Or,
    2. Start menu > Run… > (type) cmd > click ok.

  • In Command prompt :
    type the key word “cd” .. which means change directory (cd)
    give a space and type the full path of ur JDK (bin) folder
    By default it should be, C:\Program Files\Java\jdk1.6.0_13\bin
    press Enter

    Command Prompt

    Command Prompt

  • Now type : javac Test.java
    press Enter
    a file named (Test.class) will be created automatically after this command, in bin directory. Check it.

    Command Prompt_2

    Command Prompt_2

  • Now type: java Test
    press Enter

    Command Prompt_3

    Command Prompt_3

  • A dialog box will appear
    write a name input box and click ok.

    Input_Dialog

    Input_Dialog

  • A message will be showed, displaying the name
    click ok.

    Message_box

    Message_box

  • Now go back to the command prompt and type ‘exit’
    press Enter.

    Command Prompt_4

    Command Prompt_4

  • Congratulation !!!
    u have successfully executed a Java file using command prompt.

One thought on “Running a Java File using Command Prompt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s