class Example { //program begins here. public static void main(String args[]){ System.out.println(“Hi, This is my first Java program.”); } }
This is a simple program to print a line “Hi, This is my first Java program.”
There are some key points that should be known to you:
- Here ‘class’ is a keyword that is used for creating new class and first letter of every class name should be capital. The whole class definition, including all of its members i.e. variables & methods will be defined in between of curly braces ({ }).
- // is used for a single line comment. and for multi-line comment we use /**/.
- public static void main(String args[]),is a public method from where every program starts to run.
- Here public is a keyword that shows that method is public used from everywhere.
- static is also a keyword, that gives power to the method to be called by class name. There is no need to create a object call. Because of this feature, the main() is also called by the Java virtual machine before any object is instantiated.
- void is keyword, is shows that method is not going to return anything.
- main is the name of the method.
- String is class name. we are not going to discuss it here.
- args is the array of argument of String type.
- System.out.println(), is calling of method println().println() is used for printing a line that is passed as the argument to the method.
- Every line should ends with the semicolon (;). It shows that line terminates here.
Output-