Subscribe to my Youtube channel

Tuesday, August 3, 2010

Writing a simple Java Program

            Java Programming is easier for who understands the programming languages C and C++. We all know that Java is Object Oriented Programming language. The reason for this is, the entire java programming is based on the objects.
            Java program is simply treated as a class or collection of classes. Class concept is similar to C++ classes. We discuss more concepts about java programming in further articles.
            In this article we mainly concentrated about the how to write a simple java program, compiling and executing java program. You can write java program in any text editor but you must save the file with extension “.java”.
                 You have to type the above code in any text editor and you must save the file as Welcome.java. According to java specification each java program has saved with name of the class name in the java program.( it is not compulsory). If java code contains more than one class, file saved with name of the class which is declared as public.


  •  In the above code, class name is Welcome, so we are saving the file with the name Welcome.java.
  •  Another important java convention is that class name always start with capital letter and starting letter of each word is capital.
  •  After saving the file, now you have to compile the program before executing. For compilation we  use “javac”  command in the command line.
  • For the compilation, in command line you need to change directory to the directory where you placed   Welcome.java. 
  • Now write the following command at the command prompt
                     > javac Welcome.java

  • Upon successful compilation Welcome.class file will be generated.
  •  To execute the java file, we use java command .
                   >  java Welcome
  •  you must be noted that , you no need to provide extension (.java) to execute java file.

  See the following demonstration:

      
 

         

No comments:

Post a Comment