Here is the code which we will explain now:
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello, World!");
// this is a comment
}
}
In this program there are three primary components.{
public static void main(String args[])
{
System.out.println("Hello, World!");
// this is a comment
}
}
- Comment
- Class-definition
- main-method
1.Comment:
In java there are three types of comments
- Single line comment
- Multiline comment
- Documentation comment
A single line comment is defined by // and till end of the line
// this is a comment
Multiline comment is defined by /* till */.
/* this is a long comment or we call
it as the multiline comment.
*/
Doc type comment is also same as multiline comment but it is different in its syntax as:
/** This
* is
* a doc-type comment
*/
2.Class Definition
To declare a class we first type: class together with the name of the class and then between the curly brackets we put our code.
dd
class name{
....
}
....
}
3.Main-method
public static void main(String[] args)
{
....
}
{
....
}
In every java program there must be a main method as it is the point where the compiler starts executing the program so without it a java program is of no use. So to declare main method we first write modifiers
public and static which can be written in any order. But the convention is to use them both. After that this method accepts a single argument of type String.