In our last chapter, we have seen the hello world program. Again let's create a simple hello world program and understand line by line.
Now I am creating a new file JavaApplication in the filename must match the class name JavaApplication And put the following code
JavaApplication.java
public class JavaApplication {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Output:
Hello World! |
The things you need to remember
- Class Names − For all class names, the first letter should be in Upper Case.
- Method Names − All method names should start with a Lower Case letter.
- File Name − The name of the program file should exactly match the class name.
Example explained
Java is all about class and methods, in Our example, We named the class JavaApplication. A Class always starts with an uppercase first letter.
Note: Java is case-sensitive: "JavaApplication" and "aavaApplication" is different .
The main() Method
Just learn that every Java program has a class name that must match the filename and that every program must contain the main() method.
System.out.println()
It is used to print text on a console. We can use inside any methods to print text.
Java Modifiers
We can protect our methods and class by using an access modifier See the example above how I have used it.
- Access Modifiers − default, public , protected, private
- Non-access Modifiers − final, abstract, strictfp
I hope above the Useful information will help you to understand the Java basic program