Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

SCJPs would it be an error...

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if one types in :
public static void main(String[] args)
if correct main method signature is asked to be typed in?
should the access modifiers be omitted and the signature be typed in as :
void main(String[] args)
?
please comment on this type of questions.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're talking about method signature, I even wonder you don't need the return type. But I still don't sure the right answer. Or the answer Sun wants, to be exact.
 
Ranch Hand
Posts: 1902
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They're looking, if I recall correctly, for some variation on:
public static void main(String[] args)
for the signature of the method. You can move the brackets for the array around, and switch around static and void, but...
If you don't declare it as 'public', it has default visibility which I think is a no-no. Likewise, I'm fairly certain it has to be static, and have a return of void. (And yes, it needs a return type.) I have, as far as I've ever seen in my programming, never seen a reason to omit the 'public' and 'static' from the main method in an application and believe it's incorrect form to do so.
------------------
Theodore Jonathan Casser
Sun Certified Programmer for the Java2 Platform
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer for exam should be:
public static void main(String[] args)
thats what i think. correct me if I am wrong.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theodore and Rakesh are right. You need to use the full, conventionally accepted, signature.
I'm going to move this over to the Certification Study forum.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sweekriti Engineer:
if one types in :
public static void main(String[] args)
if correct main method signature is asked to be typed in?
should the access modifiers be omitted and the signature be typed in as :
void main(String[] args)
?
please comment on this type of questions.


Hello,
Most of the time, you would declare main() as follows:
public static void main(String[] args)
But let's see what we can drop:
- void - We cannot drop void since return type is required.
- static - We cannot drop static since no object exits yet at application invocation time.
- public - Maybe if we put everything in the same package.
So my answer would be:
static void main(String[] args)
with a caveat, all classes are in the same package.
Regards,
Lam
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to java documentation & JLS & seeing the source file containing main method in Java language the correct signature of main method is
public static void main(String[] args){}
this is wat sun has written & this is wat u ahve to use & this is wat u have to answer if they ask the question in an exam about the currect method signature of main.

Note:- Java is open source so u can check out everything every class every method about hos it is made my Java or sun microsystem .
take care
------------------

[This message has been edited by Amitabh Yadav (edited April 07, 2001).]
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lam,
If you do a search on main() in the forum you'll find dozens of previous threads covering this topic
For some reason, <code>main()</code> will compile ok with numerous variations on the access modifier, etc; however, as Amitabh pointed out, for purposes of the exam the correct answer ie the standard declaration is:
<code>public static void main(String[] args)</code>
Although the following are also legal (for exam purposes) permutations:
<code>static public void main(String[] args)</code>
<code>public static final void main(String[] args)</code>
Note:

  • that the modifiers 'public' and 'static' can be reversed.
  • 'void' must precede main
  • 'args' can be any variable name you choose ie argc, s, param, etc but must be of type String[ ]

  • Hope that helps.

    ------------------
    Jane Griscti
    Sun Certified Programmer for the Java� 2 Platform
    [This message has been edited by Jane Griscti (edited April 07, 2001).]
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane, did you mean that void needs to precede main IMMEDIATELY? Also, in spite of JLS, access modifier is kind of ignored by JDK I think. Even private static void main(String [] args) will run OK, adding much to our woes.
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe this is a trick question. I referenced two of my favorite textbooks for help.
----
1. Just Java 2, page 70
Looking at the signature(1) of <code>main()</code>, which is the method in which every application starts execution, we see the following:
<code>
public static void main( String args[ ] )
{
// ....
}
</code>

(1) Strictly speaking, the signature doesn't include the access modifiers or return type.
----
2. A Programmer's Guide to Certification, page 38
The main() method has the following signature:
<code>
public static void main( String args[ ] )
</code>
----
I think the correct answer should include public static void. Just Java 2 complicates the discussion by including the post-script reference for the strictest interpretation of a method signature. Since main() is a special type of method it seems reasonable that it would be treated differently than a genericmethod().

Mike
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic