Monday, April 21, 2014

Sample Java Program

Simple Hello Word Program to understand basic keywords

class
Manager {
public static void main(String[] args) {
System.out.println("Hello Words");
}
}

Terminology:
public:
It can be accessible from anywhere.
static:
No need to create the object to run the method.
void:
It means main method is not returning any value.
main:
It’s a method name from where execution will get started.
String[] args:
It’s an array of string type which can be filled by passing run time value if required.
System.out.println:
This statement will print the enclosed the value. In this case After execution output will be Hello Words on the screen.
class:
It tells the compiler where the class starting point with class name.

How to compile the program:
  • Save above java code under your jdk -> bin folder with "Managar.java" name.

  • Go to Command Prompt and go to jdk bin folder location. Command to go to bin location
          cd C:\Program Files\Java\jdk1.6.0\bin and then press enter.
  • javac Manager.java
  • -> It will compile the java program line by line. If there is no error it will not print anything otherwise it will print the error with line number. If program gets compile successfully. One class file will be generated with "Manager.class" name which will hold compiled code which can be executed in anywhere other system also which will hold JDK installed. That’s the reason Java is Platform independent language.

  • Java Manager
  • -> It will execute the java program which shows "Hello Word" as per the current example. It will read the class file which got generated after compilation.
    Note: Here no need to give .class while running the java program. Automatically it reads the class file only.
    

    No comments:

    Post a Comment