Purpose of “String args[]” in the “psvm” of Java

0 votes

Why do we always pass the argument as String[args]/String[] args to the main method of Java?

May 7, 2018 in Java by misc.edu04
• 1,380 points
78 views

1 answer to this question.

0 votes

Let me give you the complete explanation of the Java main method:

public static void main(String[] args)

  • "public" is the access modifier which means main() can be called from anywhere.
  • "static" is a keyword which signifies main() doesn't belong to any specific object
  • "void" is the return type that means that main() returns no value
  • "main" is the name of a function. main() is special because it is the point from where JRE starts the execution of the program.
  • "String[]" means we are going to use an array of String type.
  • "args" is the name of the String[]. "args" is not a keyword, so you can name it anything else and it would not affect your program

public static void main(String[] parameter)

So basically, String[] args represents a collection of Strings that are separated by a space and can be typed into the program on the terminal directly.

answered May 7, 2018 by code.reaper12
• 3,450 points

Related Questions In Java

0 votes
2 answers

Get all the permutations of a string in Java

You could use recursion to do this.  Try ...READ MORE

answered 4 days ago in Java by Sirajul
• 19,670 points
82 views
0 votes
2 answers

What is the easiest way to iterate through the characters of a string in Java?

There are two approaches to this: for(int i ...READ MORE

answered 6 days ago in Java by Sirajul
• 19,670 points
52 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,050 points
388 views
0 votes
2 answers

What's the best way to check if a String represents an integer in Java?

You can also use regular expression. str.matches("-?\\d+"); It will ...READ MORE

answered Aug 9, 2018 in Java by Daisy
• 8,050 points
115 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,050 points
612 views
0 votes
2 answers

Generate an alpha-numeric string randomly

Java supplies a way of doing this ...READ MORE

answered Jul 18, 2018 in Java by Daisy
• 8,050 points
160 views
0 votes
1 answer

How do I create a Java string from the contents of a file?

If you're looking for an alternative that ...READ MORE

answered Apr 19, 2018 in Java by Rishabh
• 3,540 points
82 views
0 votes
2 answers

Counting no of Occurrence of a particular character inside a string in Java

We can find out the no. of ...READ MORE

answered Sep 7, 2018 in Java by Sushmita
• 6,870 points
227 views
0 votes
1 answer

Maximum depth of the java call stack

Well, there is no definite depth. It ...READ MORE

answered Jul 23, 2018 in Java by code.reaper12
• 3,450 points
73 views
0 votes
1 answer

Optional return type of getter() in Java 8

Well, you can do that but originally ...READ MORE

answered Oct 23, 2018 in Java by code.reaper12
• 3,450 points
36 views