wood burning stoves*
The moose likes Associate Certification (OCAJP 7) and the fly likes main method passing of arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7)
Bookmark "main method passing of arguments" Watch "main method passing of arguments" New topic
Author

main method passing of arguments

naveen patil
Greenhorn

Joined: Feb 26, 2012
Posts: 7
main method has String arguments as its parameter , but it works fine even when we dont pass any arguments to main method at command prompt. How is that?

Thank You.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Because they are optional.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
naveen patil
Greenhorn

Joined: Feb 26, 2012
Posts: 7
optional in the sense? Can you please tell something more
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

There is no need to enter any arguments. No error will occur; the string array will simply be empty,
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
naveen patil wrote:main method has String arguments as its parameter , but it works fine even when we dont pass any arguments to main method at command prompt. How is that?

Thank You.

Not passing any argument basically means that you are passing zero arguments and that is what you will get in the String[] parameter of the main method i.e. a String array of length 0. I wouldn't call it "empty", which could be misconstrued to mean that all its elements are null.

HTH,
Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 248
    
    9
Naveen,

Java runtime passes to the main method a String array with 0 elements, if you don't pass any runtime arguments to it.




With respect,
Mala


Author of Manning's OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
naveen patil
Greenhorn

Joined: Feb 26, 2012
Posts: 7
Mala Gupta wrote:Naveen,

Java runtime passes to the main method a String array with 0 elements, if you don't pass any runtime arguments to it.




With respect,
Mala

Thank you much clear now . Am reading your book for OCA JP 7 exam preparation.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: main method passing of arguments
 
Similar Threads
concat 2 strings using constructor
var access
about overloading
Why we pass string object to main?
String Problem