Important Concepts Java Programming

String args in Java

A Java program may consist of several parts in its structure, but the most important part of any Java program is it’s main() function and it is compulsory to write it in all the programs. You may learn more about Java programming structure via this article – Structure of Java Program. In this post, I will try to explain the “String” concept in the main function.

Use of String arguments in main

To get a complete concept of the use of string arguments in main() function, firstly we should have to get a deep understanding of the main function in Java.

The main() function consists of 5 major parts & each one has some different meanings i.e.,

  • public
  • static
  • void
  • main
  • String arguments

The basic syntax of the main function in Java is,

public static void main(String args[])

Explanation of the main function

public

Here the keyword public is for access specifier. An access specifier tells about the scope of any function or data members. Here we have to assign the main function as public which means that this main function may be visible or usable outside the main function. In Java, there are two access specifiers are available i.e., public & protected.

In main() function, we must have to use the access specifier as public because the main function has to designed in such a way that it may be used outside the class.

static

static is a keyword which confines that the main function is static and here we have to use this static keyword to states main() function that, it must have to take the fixed amount of memory.

void

Since main() function in Java do not return any value that’s why we need to declare our main() function as void. Here void is a keyword which indicates that main() function will not return any value.

main

Declaration of the main function. We must have to use the main() function in our program because the execution of any program will start from the main() function. The main function may contain a group of statements and we call also call other functions in our main() function.

String arguments

This is the most important part of the main() function where many of you might gets confused. Firstly understand here, What is a String?

Here in Java, String is a predefined class which is stored in the language packages. Here the most important thing is, String is a case-sensitive keyword i.e., The first alphabet of String is always written in capital letter.

Now, Why we use String arguments in main?

The answer is simple, it works as arguments for the main function. It may accept float or int data type and at the time of execution, it will implicitly convert it.

 

You may also refer –

-> Structure of Java Program

-> Introduction to Java Programming

-> Variables in Java ( Easy Concept )

-> Data Types in Java ( int, float, char )

Leave a Reply