In this tutorial, We’ll learn about class and main method in Java language.
Java is an Object-oriented language similar to C++. The class is a major part(as building blocks) of an object-oriented program. Java classes are a blueprint in Java which can be defined as a template. That describes the data and behaviour associated with instances of that class.
A class is declared by use of the class keyword
Here is the basic syntax
public class class_name{
//statements,methods,objects,constructor etc....
}
Above code is a definition in Java. It always has to be a pair of curly braces ({})
Java class definition has two keywords as public, class
Here is the basic syntax for Java class
public class class_name{
public static void main (String args[]){
//statements
}
}
Above code is the main method definition inside the class in Java. It always has to be a pair of curly braces ({})
The explanation for class and main method in Java
Example of class and user define the method in Java
Above code is a user-defined method definition inside the class in Java. It always has to be a pair of curly braces. A method contains a series of statements that bearing a denoted task.
Note 1 – Java main method is always inside the classes and defines used three keywords public, static and void.
Note 2 – the Main method is declared within the curly braces with three Java keyword: public, static and void.
In the above example in Java, We used the main method inside the class in Java for every Java program that has many words. Every word have different meanings with significant purpose within the main-method of Java.
Java main method is an entry point in Java and every Java program must contain a main-method except some unusual situations.
It is an Access modifier, which defines who can access this method. The public is a Java keyword(reserve word) thus this method is accessible by any other class or anyone.
It is a keyword which allows the main() method to be called before any objects of the class have been created.
It is a reserved word in java. It is known as a return type and all methods are required to have at least one return type. But, the void keyword denotes that this method does not return a value.
It is not a keyword but the name of the method. This method is the starting point of the program.
It is the parameter to the main method.
Then, when we add some codes to the inside of the main method, it is executed by JDK.
Suggested for you
Encapsulation in Java language
Method overloading in Java language
Method overriding in Java language
Constructor overloading in Java language
difference to constructor and method in Java
Encapsulation in Java language
How to set a path to Java language
Naming conventions in Java language
How to download and install Java
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…