First/Basic Program Description and Execution Steps

First Java Program:
class Hello
{
  public static void main(String[] args) 
  {
     System.out.println ("Java By Kiran");
  }
}
  • class : class keyword is used to declare classes in Java
  • public : It is an access specifier. Public means this function is visible to all.
  • static : static is again a keyword used to make a function static. To execute a static function you do not have to create an Object of the class. The main() method here is called by JVM, without creating any object for class.
  • void : It is the return type, meaning this function will not return anything.
  • main : main() method is the most important method in a Java program. This is the method which is executed, hence all the logic must be inside the main() method. If a java class is not having a main() method, it causes compilation error.
  • System.out.println : This is used to print anything on the console like printf in C language
  • Step 1: Open a text editor (Notepad) and write the code as above.
  • Step 2: Save the file as Hello.java
  • Step 3: Open command prompt and go to the directory where you saved your first java program assuming it is saved in D:\
  • Step 4: Type javac Hello.java and press Return to compile your code. This command will call the Java Compiler asking it to compile the specified file. If there are no errors in the code the command prompt will take you to the next line.
  • Step 5: Now type java Hello on command prompt to run your program.
  • Step 6: You will be able to see Hello world program printed on your command prompt.