Oop Java

Class and main method in Java language

Class and main method in Java  language

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 class is a blueprint in Java which can be defined as a template. That describes the data and behaviour associated with instances of that class.

definition Class and main method in Java language

A class is declared by use of the class keyword

Here is the basic syntax for Java class

public class class_name{
//statements,methods,objects,constructor etc....
}

Above code is a class 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

Java class main method

Example of class and user define the method in Java

Example for class and user define the main method

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 class 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.

public :

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.

static :

It is a keyword which allows the main()  method to be called before any objects of the class have been created.

void:

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.

main:

It is not a keyword but the name of the method. This method is the starting point of the program.

String args[]:

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

Keywords in Java language

public keyword in Java

static keyword in Java

void keyword in Java

 

How to set a path to Java language

Naming conventions in Java language

Class and main method in Java language

How to download and install Java

Encapsulation in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago