Udemy coupon 100 off 2017 ::Udemy coupon code free :: Get 100+ Free Udemy coupons Here

Run First Program of Java

How to run 1st Java program. 

Before starting,make sure you have running java on your pc.

It is a suggestion use text editor and command prompt only to run your java programs at this level.
Once you have achieved grip on programming ,You can use tools like (Eclipse,Net beans etc) to create  your program.

Suppose you want to run a java application.
following are general steps:

  1. Open Notepad
  2. Write your code
  3. Save file.  File name will be classname.java (Class having main method)
  4. Open CMD
  5. Go to apporopriate directory
  6. Compile programe with command:       javac filename.java
  7. Run programe with command:         java filename

Now lets have above steps with example:

  • Open Notepad:
  • Write following code:
          class Example1 
                public static void main(String args[]) 
      System.out.println("My first Java program.");
        class aClass  // Another class in same source file if required

  • Save the file with name Example1.java 
       Example1 class is having main method.So save the file with           name  Example1.java 

     Suppose we have saved our java file at location D:\java      

    (You can choose location as per your convenience

    • open CMD(Command Prompt)
    • Give command :    d:      

    Will move to D drive. 

    Give command as per your drive in which you saved your example program.

    • Give command :    cd java     
    Will move to java folder in D drive.
    Give command as per your folder in which you saved your example programs.
    • Give command :    javac Example1.java
    Will compile program.At this level you can check there is another file Example1.class at location d:\java.
    • Give command :    java Example1 
    Will run the program.Out put will be given on the same cmd screen 

      No comments:

      Post a Comment