Keywords in Java are reserved words that have a predefined meaning in the language and cannot be used as variable names, method names, or identifiers.These keywords help define the syntax and structure of Java programs.
Here i'm presenting commonly used few keywords in java,
- public (Access Modifier)
public is an access modifier that makes the method or class accessible from anywhere
If a method or class is public, it can be used by other classes, even if they are in different packages.
- static (Modifier)
The static keyword means that a method or variable belongs to the class itself rather than to any specific instance of the class.
In the case of main, it means the method can be called without creating an object of the class.
- void (Return Type)
void is a return type that specifies that a method does not return any value.
Since the main method is the entry point of the program, it doesn't return anything, so its return type is void.
- class (Class Declaration)
class is a keyword used to define a class which is a blueprint for creating objects
- main (Method Name)
main is the entry point of every Java application.
The JVM (Java Virtual Machine) calls the main method to start the execution of the program.
- String[ ] args (Command-Line Arguments)
String[ ] args is an array of String values that store command-line arguments passed to the program when it's executed.
Example: If you run java MyClass hello world, args[0] = "hello" and args[1] = "world".