Catch us on

Sunday, March 27, 2016

running a java program

Hello guys this is Kishan Agarwal and hope you liked my old tutorial on How to set path of jdk. If you have not read the previous tutorial then please read it first (the link is given below).
  1. Create a java program and save it with .java extension.
*NOTE: you should have set the path of jdk.(Read this article to set the path permanently
http://www.hackviper.com/viper_article_page/486/java/Setting_path_for_JDK ) or you can set it temprorily by typing set path="Source of your bin folder" in cmd.
I have created a program given below
     class MyFirstProgram
  {
   public static void main(String []args)
     {
      System.out.println("This is my first program");
      }
   } 
  1. Save it anywhere with name MyFirstProgram.java
Important thing to remember is file name of the program should be same as the class name which contains main() method(here it is MyFirstProgram).
  1. After saving the file goto CMD set path if you have not done it so far.
  2. Goto the directory of your bin folder.
  3. Goto the directory where you have saved your file.
  4. After getting into that directory type :-
 javac File_Name.java (Here it will be javac MyFirstProgram

  1. Once you typed it press enter then your program will be compiled.
  2. To run the program type java FIle_Name (Here it will be java MyFirstProgram).
When I ran this program I got output as:
This is my first program 

Please like it share it with your friends.


Kishan Agarwal

Please Share


No comments:

Post a Comment