Java Program
1. Structure of a Basic Java Program
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
2. Detailed Explanation of Each Part
public class HelloWorld
• In Java, the program must be inside a class. Here, HelloWorld is the
name of the class.
• The public keyword indicates that the class is accessible from
anywhere.
public static void main(String[] args)
• main() is the entry point of the Java program, like in C.
• String[] args is used to accept command-line arguments.
• public allows access from other classes.
• static means this method can be run without creating an instance of the
class.
• void means that this method does not return any value.
[Link]("Hello, World!");
• This is the output function in Java, similar to printf() in C. It prints the
given text to the console.
3. Comments — Writing Notes in Code
In Java, comments are written similarly to C.
Single-Line Comment:
// This is a single-line comment
Multi-Line Comment:
/* This is a
multi-line comment */
4. Complete Example Program
public class StudentInfo {
public static void main(String[] args) {
// The following lines print name and age
[Link]("Name: Nafis");
[Link]("Age: 16");
}
}
Output:
Name: Nafis
Age: 16