Does main need to be public?

I'm a little confused as to why the following code works...
public class FirstClass {
    //public static void main( String[] args ) {
    //    System.out.println("Public main()");
    private static void main( String[] args ) {
        System.out.println("Private main()");
}This is being run on 1.2.2. I was under the impression that main needed to be public for the system to call it. But when I run this it prints 'Private main()' to screen. This is also true if I make main protected.
Any ideas as to why this still works?
Thanks
Ade

It seems that the main signature does matter, but the
access modifier doesn't.Both the JLS and the JVM specs require that the main method to be public (note however that you are allowed to have a private, static, void method that takes a single String-array argument, but it should not be considered an application entry-point).
This was a bug introduced into Sun's VMs with early 1.2 releases; Originally there was no intention to fix it, but eventually they decided to do so, and it was fixed for 1.4.
If you do not declare your main methods public, static and void, you will find that your applications stop working one day when you switch Java versions, or when you roll the code out to clients using a different version to that which you developed and tested the apps on.

Similar Messages

  • Why does main() need to be static?

    Hi all,
    I am trying to understand why
    public static void main(String[] args)needs to be static?
    I know that it needs to be available before the JVM creates an instance of the class containing the main method, but why is this the case? Is there some reason why the JVM cannot create an instance at that point?

    Hi all,
    i shall try to explai you this puzzle.
    for a class as follows:
    ========================================
    class abc{
    abc(){ ..... }
    public static void main(String[] a){
    ========================================
    when i compile it it runs perfectly but if i remove the static modifier from main it throws an exception.
    that is beacuse jvm lies outside the bounds of the class(opr default pacgage) and so if i want to call any method from there (or basically from outside the package) it has to be declared public.There should be no arguments here as this is the very idea of access protection.
    Now simce main returns nothing so it has to be void.The String array argument is place holders for command line arguments (thats for compatibility for users comming from c++)
    Now static why????
    in java when we call a classes constructor or when a class is instantiated all the prop[erties of that class are created with values or behaviour specific to that object and in general defined by the class.This you may agree with i suppose.Now if i need to call a method print of class abc then i need to first make an object of class abc (lets say ABC ) and call print as ABC.print("ddd"). This call shall execute the logic specifically defined in the behaviour of the particulay object ABC of class abc and this not necessarily  can be same as the default call behaviour.
    But suppose i have a method that always returns the sum of two integers no matter what object it resides in, I would make it statis because this method would not be a copy in all the objects created rather one master copy that all the objects would use.So now ABC.add() would return same as BCD.add(). But the thing is what do i need to do when i am calling this method for somewhere outside the package.(e/g jvm calling main)Since i don't have the object i cannot call the method.
    using static i can have an entry point into the jvm as static methods are executed using classname.methodname().
    Once the entry poinjt is loaded(main here) i can call the constructor ,make the object and proceed.
    hope this helps,
    waliv.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • HT5100 does all content need to be publicly available

    If I have a itunes U site does all the content need to be publicly avalible? Or can I restrict who can see it?

    Hi!
    AppleTV will sync with 1 dedicated computer (iTunes instance), the first one you configure, and stream from 5 others. Ad those in the Source menu on AppleTV.
    In my case I configured an iTunes with just a little content to sync with and to stream from my "main computer". There was no way that I could fit all that content on the AppleTV. One advantage with the synced data is that AppleTV can show this without being connected to any computer since it has a local copy. It will start a bit faster to but it's not a big difference.
    /Mikael

  • Do I need to deploy Public Synonym in Target Schema?

    Hi,
    I need to develop and deploy a mapping. I need to use source table in source schema but a Public Synonym for a terget table. This destination table for the public synonym is not target_schema where mapping is to be deployed. Do I still need to deploy the public synonym into my target schema where mapping is or not? I was 3wandering since its a public synonym and the actual destination table is already in database I may not have to deploy this synonym. Thanks for the help in advance..

    OWB does not currently directly support public synonyms. You will have to deal with these synonyms outside OWB and if you use the synonym from a mapping you can trick OWB to use it by creating and using a dummy table in the mapping.
    Regards:
    Igor

  • Trial Version not working - does it need "My Documents"?

    Hi Everyone
    I am currently evaluating the trial version with view to
    purchase for my workplace (not for profit public health service).
    On my computer at home the product installed and runs perfectly.
    However I have installed it on two computers at work. Both seemed
    to install fine with no error messages however whenever I try to
    run Captivate, after choosing to run as a trial and clicking
    continue it just stops working.
    The only reason I can think of is the "My Documents" folder
    at work points to a network drive and I have only read only
    permissions to the root of it (full permissions to some subfolders
    though). My question is "Does Captivate need full access to the My
    Docs folder to install properly?" I tend to recall that there was a
    folder called My Captivate or something that it wrote to this
    location.
    Thanks
    Brett Kinross
    P.S. If not are there any other ideas as to why it won't
    work? I have already uninstalled/reinstalled.

    The answer is definitely "YES". I had to get the IT
    consultants that the company use to create a "My Adobe Captivate
    Projects" sub folder in "My Documents" and then it worked fine.
    It would be nice if Adobe actually gave the user the option
    of where it wants this folder created; it could default to "My
    Documents" if they want but could allow a user to designate another
    folder if required. Have the same problem with Adobe Bridge which
    is really annoying. Thanks aplumb for your time.
    Cheers
    Brett

  • I am about to buy a 13" MacBook Pro with 256 GB SSD drive.  I want a i am about to buy a MacBook Pro Windows partition set up.  How large should it be, and can I use XP Pro or does it need to be Win 7 or 8?

    I am about to buy a 13" MacBook Pro with 256 GB SSD.  I want a Windows partition set up.  What size should it be, and can I load Win XP Pro or does it need to be Win 7 or 8?

    You can use XP but it has to be in a Virtual Machine and OS X as the host instead of as a dual boot system with XP in its own partition. That is how I run Windows on my Mac, in a Virtual Machine.
    Take a look at VritualBox from Oracle. It's free and works very well.

  • Reporting Services Add-in for Sharepoint- does it need an SQL Server license?

    In a new project we will be creating an SSRS in Sharepoint integrated mode. For this we'll need SQL Server and Sharepoint on that box.
    We'll also have one or more SharePoint Web Front End (WFE) servers. To allow them to connect to the SSRS-in-sharepoint-mode box, and to present the user with the right user interface for doing so, I believe we can install the Reporting Services Add-In for
    Sharepoint on the WFE servers.
    The question is, do we need to have  SQL Server license for each WFE server where we use the Reporting Services Add-In, or is it free to use?
    We've had advice that we need to buy a SQL Server license everywhere we use the add-in, but I am not sure this is correct.
    Thanks in advance,
    Rich

    Hello there,
    The Reporting service Add-in for SharePoint can be downloaded free on Microsoft Download site. That means it does not need any license on the add-in.
    Regards,
    Edward
    Edward Zhu
    TechNet Community Support

  • Does everyone need to use the same Apple ID/password for iTunes & App Store in iOS 8 Family share?

    I just set up Family share on my 5S and my wife's 5, both running iOS 8. I am the organizer.
    In order for my wife's purchases to be charged to my CC (per Family Share setup), does she need to be signed in under my Apple ID and password under Settings -> iTunes & App Store? Or, can she use her Apple ID (that she used with her previous App Store purchases)? Additionally, if she makes purchases in iTunes or the App Store under my Apple ID, does she need to enter my password?
    If she's logged into "iTunes & App Store" on her phone, using her Apple ID, will it work?

    Well thanx to your answer I sure did just sign out of my old id, & now it's working! Thanx a lot IIIaass, you saved me from having to deal with anymore frustration! Thanx IIIaass!

  • Our granddaughter has a ipod. She's getting a iphone and a mini idpad.  what is the best way to set them up. Does she need a new apple id and password or would she use the same one she has for her ipod

    our granddaughter has a ipod. She's getting a iphone and a mini idpad.  what is the best way to set them up. Does she need a new apple id and password or would she use the same one she has for her ipod

    Just use the same one on all devices.

  • If my wife wants to buy an ipad II what does she need to do shopping for hours at a time on the internet while driving

    My wife wants to do internet searches and shop for hours on end while I'm driving.  What does she need if we get an Ipad 2?
    Some people here at the office say I need Wi-Fi.  Some say 3G.  Some say I need to sign up with a carrier on some type of monthly plan to get the internet.
    Help!!
    I need this while we drive from state to state and not for getting on the internet through some hotel Wi-Fi Connection.
    Thanks,
    BaylinerKing

    3G coverage and overall performance between Verizon and AT&T varies depending on where you are, and depending on where you are you may have no 3G service at all with any carrier.
    The other consideration is the price-points of various data plans, they differ between size and cost.
    But all plans are month-to-month, meaning that you can turn the service off anytime you want, and for as long as you want, but when you activate 3G service you pay for 30 days of service regardless if you turn 3G off (so turn it off on the 29th day if you won't need 3G next month).  You can do all of this right from the iPad, and you don't have to set anything up at the time of purchase (other than choose your carrier).  I bought a Verizon 3G iPad 6 weeks ago and have not yet activated 3G, but will do so soon while travelling.

  • My iPhone 5 is not catching up my website, although having a big screen... What does it need to get the pages in auto mobile queries converting?

    my iPhone 5 is not catching up my website, although having a big screen... What does it need to get the pages in auto mobile queries converting?

    You need to code your web site to recognize the mobile browser and send a page that's actually usable when it does.

  • Why does Bridge Need Illustrator to Save as PDF compatible file?

    1. Why does Bridge need Illustrator files to be saved as PDF files? "PDF Compatible File" ticked in the save menu.
    2. Why does saving with this info take so long, even on decent fast modern systems?
    3. Why does Bridge not consistently render the Illustrator files in FULL RESOLUTIONS, seemingly shooting for half resolution much of the time, and simply stopping at that?
    4. Why does "clicking" on the preview inside Bridge bring up the full resolution?
    5. How do I shortcut this process so that every file is previewed in Full RESOLUTION, instantly?
    What is the point of Bridge?  What's its reason for existence?
    First time user of Bridge.

    Since someone is bound to say that this should be asked in the Bridge section... it already is.  And has been referenced back over here.
    You can find it here:
    http://forums.adobe.com/message/5655632#5655632
    Answer wherever you see fit, if you're up to the task of dealing with someone attempting to have a broader view, perhaps also suffering from somewhat objective analysis that sometimes contains direct criticism of the way Adobe does things.

  • FMS on Amazon Web Services License. Does it need enter License(Serial Key)?

    FMS on Amazon Web Services License. Does it need enter License(Serial Key)?
    After Subscribe on adobe.com(Adobe Flash Media Server 4.5 on Amazon Web Services)
    I build the Amazon EC2 successfully.
    In amazonpayments, the amazon show me an Activation Key.
    On  Application Activation:
    The screen give me following information.
    Generate an Amazon Activation Key  
    An activation key may be required as part of an application's registration process. If your application requires it, follow the steps below:
    Step 1: Click on the Generate Key link to generate an activation key for an application.
    Step 2: Copy the activation key.
    Step 3: Click on Go to Application to access the application.
    Step 4: Paste the activation key if and where the application specifies.
    But in Adobe Flash Media Administration console, It is missing the License(Serial Key)
    Does it need enter License(Serial Key)?
    How can I use the  Activation Key?

    Hi,
    This Activation Key is only for identification purposes. In most cases, you will not have to use it. Once you subscribe to FMS on AWS, you are ready to go and use FMS AMI's.
    Also, FMS on AWS does NOT require any License or Key. It works on a separate Licensing model.
    Thanks!

  • How to create an OAF page that does not need login to access

    We have a lot of Oracle users, and everyday there are some users forget there username or password and need reset. I really want to use a web page to let them reset their passwords automatically. The web page will call the API to reset password if it found the user request is legible.
    So based on the situation, the users should not need a login to get to this page, can I do this using OAF?
    And idea is welcome, thank you for your help!
    -Bill
    Edited by: billzheng2004 on Jun 18, 2009 12:12 PM

    Srini,
    Thank you for your response, I think we need to go back to my original question, is it possible to create an OAF page that does not need login, how can I do that.
    I think I said too much and led us to go to a different direction I did't want to. But I am still glad to texplain why I need a custom password reset process, that is all about business requirement, here it is:
    ----I am not sure that "company issues" (such as what you described) can be solved by software -
    I already have a solution for that. Create a custom OAF page, ask user to input his SSN / Date of Birth.... then I can figure out what his real username easily. And I can reset his password as his SSN or something which only this particular user knows. Then he can login.
    ----you may have to impart training to end users.
    As I mentioned, most of our users use only Benefit self service. They only login several times a year, even they are trained this year, most of them will forget next year, this is just human nature. And because the nature of our business, thousands of employees may change at the end of a year. It does not make any business sense for company to prepare trainers every year.
    ----In any case, the functionality you require is already built into the product.
    I guess the reason most companies hire Oracle Developers is that some functionality Oracle Applications provide is not exactly the companies needed. When there is Oracle Apps product, there is alway customization.

  • Which sort of HDMI cableis recommended for connecting Apple TV to aTelevision?  Does it need to be a normal HDMI cable or one which support Ethernet capabilities?

    Which sort of HDMI cableis recommended for connecting Apple TV to aTelevision?  Does it need to be a normal HDMI cable? or one which supports Ethernet capabilities?

    no need to go for an expensive HDMI cable as Varjak Paw rightly suggests.
    Pretty much all of them come with 1.4 standard these days.
    The difference in price is made by additional shielding and material used for the wire - hardly ever needed at home installations - unless you get interference from other devices.
    on the other note.
    one HDMI in your TV is obviously not ideal as well as using HDMI splitter or hub - but it should work.
    Also I know cases that some LG TV models do not work with Apple TV - which was confirmed by LG technical support.
    Those are rare cases and i do not want to worry you at this stage.

Maybe you are looking for

  • DB Diagram: Modality Difference between NOT NULL and check constraint

    Hi, I am using jdev 11g (11.1.1.10) I am trying to create a db diagram from two tables. I have a FK that is NOT NULL (defined on the column). When i try to display these two tables modality, it does not show up in the diagram. I noticed that there ar

  • How do i restore synching between Treo 650 and iCal & Address Book

    prior to installing 10.4.7, i was able to sync my treo 650 with iCal and Address Book; iCal and Address Book syncs with .Mac and Entourage; Entourage syncs with Outlook on my office pc; and Outlook syncs with my Blackberry 8700. therefore, all i need

  • Wat is the difference in following 3 codes??

    wat is the difference in following 3 codes?? 1) <b>using write stm in select/endselect block</b> tables: vbak. data: begin of t_ernam occurs 10,       ernam type ernam,       end of t_ernam. select ernam from vbak into t_ernam where vbeln = '00000000

  • Correlation Problem

    Hi guys .. M having a little problem with the correlation sets here ...here's my situation 1. Created three Async Processes A,B and C 2. The Reply from C should go to A directly and not through B. 3 .This is the same thing as the Tutorial in the Samp

  • Pic links not working in FF but are In IE8 on HTML page

    Hi, I have an Html page that has a bunch of small pic images on it. When you click on one it display a larger version in the center of the page. For some reason they all work fine in IE8 but not Firefox only the bottom row work. The rest act as they