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
66 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
1 answer

Get all the permutations of a string in Java

This is the recursive way of finding a ...READ MORE

answered May 10, 2018 in Java by sharth
• 3,320 points
71 views
0 votes
1 answer

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

The below code seems the easiest to ...READ MORE

answered Jul 13, 2018 in Java by scarlett
• 1,280 points
40 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,040 points
301 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,040 points
105 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,040 points
553 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,040 points
127 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
72 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,840 points
183 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
55 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
29 views