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 Check Electricity Bill of Telangana Online

Greetings of the day! Guys, today I am writing another very simple yet very useful post. I am going to write how one can easily check their electricity bill amount online. Please note that this post is written specifically to check bill amount for the state of Telangana. Below are the steps: Click on this link.  TSS Souther Power Link Once you click on the above link, you will be shown the below web page. Now, as you can see from the image above, we  are having two options to fetch our bill amount. Enter the District, ERO & Service Number  OR Enter the Unique Service Number.  This Unique service number ,is the most common way to both fetch the electricity bill amount and also to pay the bill. It will be written on your Bill under the short cut name of USCNO, as shown below.   Below is the image of the sample electricity bill explaining all the components along with USCNO. Source :  tssouthernpower Now, that you know how to find you electricity bill amoun