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

Class and main method

definition Class and main method in Java language

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

Java class main method

Example of class and user define the method in Java

Example for user define the 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 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.

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

extends keyword in Java

implements keyword in Java

interface keyword in Java

Abstract keyword in Java

 

 

Suggested for you

method in Java language

Encapsulation  in Java language

Abstraction in Java language

Method overloading in Java language

Constructor 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

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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago