Wednesday, 5 March 2014

A simple Java program

In this blog we will start  java progamming.
TO Print A simple message in java.
before writing a program we should keep these things in mind-
  1. A java program have atleast one class.
  2. It should have main method.
  3. It should be saved as classname.java
  4. To compile it we write "javac classname.java"
  5. To run it we write"java classname"
class first
{
public static void main(String args[])
{
System.out.println("My First Java Program");
}
}
Output:-My First Java Program

In main method we have passed arguments as String args[] because without writing it the code public static void main() will be compiled but JVM will not run it .It is necessary to pass it as argument.To print any message we have to call print() method of PrintStream class.To call it we write System.out.print();



In next blog we will discuss about variables and Data Types.

No comments:

Post a Comment