Skip to main content

Why public Static void main(String args[]) in java

Well Everybody knows that java has grown exponentially .Its been used every where right from the mobile phones to the servers.
It has got the largest set of libraries you can find a library for almost everything.
Every one know what i've just written but very few know why always we need to write the signature of main method as above
public static void main(String []args)
we declare the method public because its been called by someone outside the class.That someone is JVM the java interpreter
  1. We declare the method as static because JVM has no means no instantiate a class but by the very defination of the static is that there is no need for the instantiation of a class if the class contains static methods.


    1. for calling static methods there is no need to instantiate the class
    2. we can call static methods directly by using class_name.method name
    it is because of this reason that we declare the method as static since JVM has no way of instantiation of a Class.


  2. void is the return type of the main method .we know that every method has to have a return type in java and this is it void.
  3. main is the name of the method .One very important observation is that since java is strongly typed language you can't write Main instead of main .Although it will not give you a compile time error but a run time exception will be invoked when you try to run it .Why?


    1. jvm call a method with signature :public Static void main(String args[]) nothing else so it gives an exception main method not found.


  4. and finally string[]args its the parameter to the function what every command line arguments to pass while running the java class will the present in the args array.
  5. NOTE:the parameter can be either string []args or String ...a anything other than that will  compile but again run time exception would come because jvm knows only one signature of the string.
hope that helps!

Comments

  1. Actually,...in java main() method (function) is called by JVM...and it is not meant for accepting or returning values to program and hence main() return type void.

    ReplyDelete
  2. yes that is correct so since jvm does not accept can we leave that return type empty?
    no we can't because java needs to have a return type even though one is not intrested in accepting the values from program

    ReplyDelete

Post a Comment

submit your comments here

Popular posts from this blog

How to: Check the status of Registration of Vehicle in Andhra Pradesh/Telangana

Greetings to one and all. I recently bought a new vehicle and did the registration of the vehicle. But When I wanted to get the status of the registration of my vehicle I found the task daunting because the RTA site : http://aptransport.org/index.htm made it difficult to find the link. Also nobody took  the pain to write a post on this so far, so I decided let us write a post on How to check the status of the registration of vehicle in Andhra Pradesh, India. First step --> Click on this Link: Updated the New Link  For Telangana: https://tgtransport.net/TGCFSTONLINE/Reports/VehicleRegistrationSearch.aspx For Andhra Pradesh: https://aptransport.in/APCFSTONLINE/Reports/VehicleRegistrationSearch.aspx You get below screen: Vehicle Registration Search Step 2 : As you can see in the screen shot above, you have to select one field from the drop down " Select Search Element " and enter data against that element in " Enter Select Element Text "

[Updated] How to Pay Telangana Electricity Bill (TSSPDCL)

Greetings to Everybody! This is post is updated on 18/12/2018. Today, I am going to write a post on what are the various options by which you can pay your TSSPDCL/Telangana electricity Bill. Hi Guys, Updated the below post as we have a new service PayZapp, through which we can pay our electricity bill payments. Official Website of Telangana Government. Official Link is  Click Me Here you can choose your preferred payment options to pay the bill. You can also use android app  Click Me  to do payments from the mobile. PhonePe . An APP acquired by Flipkart. This the best app right now to pay the electricity bill simply because of its ease to connect with UPI. Use my referral link to earn more benefits. Link :  https://phon.pe/ru_phonma74 Meeseva . This used to be the best offline option. HDFC PayZapp . Use the Referral Code:  ragl23  to get more benefits. PayTM FreeCharge . Also, use the Referral Code : r50njyj while signing up to get more benefits. PayUMoney . U

How To Apply For Extra New Light Meter in Hyderabad

Greetings of the day! Today we are going to write about how should one go about applying for a new electricity meter. This post of course is applicable only for Hyderabad. One of the many reasons as to why everybody wants a new meter these days is because of the slabbed costing scheme government has recently introduced. So let us say you are staying in a building which has 3 different residents. The building has only one light meter. So what would be the problem now ? Since there is only one meter and 3 different families are going to share it the cost of bill would be much when compared to each family having their own electricity meters. The obvious reason is that together they would be reaching higher cost per unit slab than they would reach individually. So below is the procedure to get your own electricity meter: (Thanks to Abhishek for compiling this) Take application form from light office(Each house can apply for max resident 4 meters). Fill the form with required op