First Java Program

Sample Java Program
javaproram


create the HelloWorld Java program

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

Save the file as HelloWorld.Java because in Java class name and file name must and should same.

To Compile: javac HelloWorld.java
To Run : Java HelloWorld
Out put:
Hello World
Understanding the first java program


  1. class keyword is used to declare a class in java
  2. public keyword is an access modifier which represents visibility means its visible to all.
  3. static is a keyword when we declare a method is static , it is a static method.By using static method no need to create object to invoke the static method.The main method is executed by the JVM .JVM doesn't require  create object to invoke the object to static method.
  4. void is the return type of method. It doesn't return any type of value.
  5. main represents the startup of the program.
  6. String [] args is used for command line arguments.
  7. System.out.println is used print statement.

SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

1 comments: