CodeGym
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
CodeGym/Help with Java Tasks/Can anybody provide me with crystal clear difference betw...
Dinesh
Level 7
Delhi
  • 10/30/20
  • 741views
  • 4comments

Can anybody provide me with crystal clear difference between method's parameter and argument. How both of them work ?

Under discussion
0
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa , United States
30 October 2020, 16:17
They are used interchangeably, and no one except the most pedantic of people will chastise you for using them to refer to the other. But, here are the correct usages of each: Take this bit of code for example:
public static void main(String[] args){
    m1(4, "test");
    m2('A', 5.6);
}

public void m1(int number, String string) {
}

public void m2(char character, double decimalNumber) {
}
In this bit of code you have 3 methods (main, metho1, method2). Each method declares its parameters inside the parentheses where they are declared (lines 1, 6, and 9). Matching these parameters is absolutely required to correctly call the method. Now on lines 2 and 3 is code that calls the m1 and m2 methods. To correctly call a method you must use the method name and pass arguments inside parentheses that match the method parameters. So the parameters of m1 are (int, String) and on line 2 i pass in (4, "test") (and int and a String) which match the method parameters. This code works, however if I changed that line to:
m1(4);
The code would fail because the arguments passed into the method of an (int) do not match the parameters of (int, String). On line 3, where I call m2 I pass the arguments ('A', 5.6) which are a char and a double, and this code works because those arguments match the parameters of the method which are (char, double). So: Parameter(s) - these are inside the parentheses of a method declaration Arguments(s) - these are inside the parentheses when a method is called and MUST match the method's parameters.
+1
Dinesh
Level 7 , Delhi , India
30 October 2020, 17:24
Thanks a lot. Now, I got it I have one question. Please make me understand that too. 1. public static void mian(string []args) is a method declaration at line 1 of the code 2. execution of program starts from main() in java 3. what arguments gets passed in main() method when execution starts? I think in that case the argument that get passed in main() is the name of file with .java extension suppose i have my file abc.java than abc will be passed in main() thorough the command java abc Am I right ?
0
Guadalupe Gagnon
Level 37 , Tampa , United States
30 October 2020, 17:51
The main method uses command line arguments (from outside the java code) which are passed in when starting the program from the command line. IntelliJ and pretty much all IDE's do this for you behind the scenes, though the top of the output window when you run code shows the command line arguments that start your code. For example, when I just run a test class that I have this is printed to the top of the output window before any of my code is run: "C:\Program Files\Java\jdk-12.0.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\lib\idea_rt.jar=65114:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Programming\CodeGymTasks\October 2019\CodeGymTasks\out\production\1.JavaSyntax" Test.Solution The main method uses a special type of argument called varArgs (short for variable arguments) meaning that they can contain any amount including none. You will learn how to make methods with varArgs later on.
0
Dinesh
Level 7 , Delhi , India
30 October 2020, 18:55
Fine. Thank You
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym