• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Main method Signature

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI friends,
can main method method have a parameter other than String[]?

I tried the follwing code...



it gave to following error:



and when i modified the code to be...


now this code is of generics...and the parameter of main only accepts String. but this gave the following error



Can anyone explain me about this?

Thanx
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the API for class Object. You will see that Object is not a parameterized type, so Object<String> is meaningless.

The main method must have a signature of main(String[] <identifier> ) , and must have modifiers public and static, and a return type of void. It can have additional modifiers and a throws clause.

It seems that you can also use an argument list of String... <identifier>, but that is just "syntatical sugar" for String[] <identifier>.
[ September 11, 2005: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Instead of posting a new topic I am using the same topic again regarding the main method.
just a small question:

in the statement


i want to know whether any object is created? if an object is created is it a String object? and if no object is created then how is the line commented as 1 printing the value [Ljava.lang.String;@10b62c9, it should print null;

Thanx
Sandy
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you run it, are you passing it any arguments?

My guess is that you are not. so, (and again, this is a guess), an ARRAY object is created, that happens to hold nothing. you then tell it to print the array, which calls the default toString method every object inherits from the Object class, thus giving you that output.
 
anand phulwani
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Mr Sandeep,

Here is a simple explaination for it

1)Yes,an object is created.
2)Its an Array Of String Object
which is created ,in the same way as
String b[]=new String[0];
so its printing the class and its hashcode
3)And in Array it prints null only when
we access an Array Element

String b[]=new String[1];
System.out.println(b[0]);//this will print null

heres a code for your help

this results into
[Ljava.lang.String;@10b62c9
[Ljava.lang.String;@82ba41


apart from this Mr Sandeep,
One Small Doubt of mine,i would like to ask that
4)As this is an Member Variable ,it does implicitly initialize a default value, so should it print null if no object is created???,as far as i have learned it is that Member Variables are needed to initialize explicitly otherwise it gives a Compiler Error, that the variable might not have been initialized.

Please Correct Me If I am Wrong.
 
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic