Back to Top

Sunday, 15 January 2012

JAVA : public static void main(String args[]) - Explanation.

public - public means everyone can access it.That means it's in global scope. As, main method is called by JVM [Java Virtual Machine], which is actually out of the project scope, the access specifier of this method is public.


static - Java environment should be able to call this method without creating an instance of the class , so this    method must be declared as static.

void - the return type of this method is void means there's no return value.



main( ) - the name of the method, main because it's the main method.

String args[] - arguments to this method. This method must be given an array of Strings, and the array will be called 'args'.



RELATED POST ~ JAVA INTERVIEW QUESTIONS

Anijit Sarkar

83 Responses to “ JAVA : public static void main(String args[]) - Explanation. ”

Mubarok said...
14 April 2012 at 13:00

thanx


Anijit Sarkar said...
15 April 2012 at 08:49

@Mubarok
you r welcome my friend!!
thanks for commenting!! :)


Java ArrayList tutorials said...
18 April 2012 at 15:10

Good explanation. Why main is made public static in Java is also a popular question where this explanation can be used.


Bharath said...
15 July 2012 at 22:42

excellent explanation about usage of static in main method......


Anijit Sarkar said...
15 July 2012 at 23:15

@Bharath....
...Thanks a lot my friend!!


Anonymous said...
19 July 2012 at 18:54

THNX..


Anonymous said...
27 July 2012 at 11:59

shukriya boss...really worthy explanation


Unknown said...
1 September 2012 at 13:50

it was helpful


cse siva said...
5 September 2012 at 14:57

i not satisfy with the main() explanation , pls give clearly


prasad said...
14 September 2012 at 06:17

thanks ,it is really helpful............


sudhanshu said...
15 September 2012 at 00:17

We can also use
public static void main(String ...args) instead of

public static void main(String args[])



Anonymous said...
3 October 2012 at 13:41

yeas Sudhanshu (String args[]) is as same as (String...args)


Unknown said...
11 October 2012 at 12:22

thanks friend,very useful info..
public static void main(String []args) this is also one of the method to declare string array.


zaid said...
12 October 2012 at 18:49

Than,s FRND


Anonymous said...
30 October 2012 at 22:55

what if declare main() as private or protected ?????


Anonymous said...
5 December 2012 at 08:44

super explain


saitheja reddy said...
16 December 2012 at 22:16

can we define main as private or protected?


Unknown said...
19 February 2013 at 20:05

main() method tell us the begin of the program execution


Unknown said...
17 March 2013 at 17:18

we can define main() as private or protected and ofcourse The program compiles properly but at runtime it will give “Main method not public.” message.


Anonymous said...
23 March 2013 at 10:23

why should "s" be capitals in "String args[]" ?


Anonymous said...
6 April 2013 at 21:41

instead of String can we use datatypes like int,char....???


Anonymous said...
23 April 2013 at 12:39

's' in "String agrs[]" is capital beacause String is the name of class we are using and it should be capital


Sunkara Krishna Teja said...
18 July 2013 at 10:33

What do you mean by public-every one can access it


Anonymous said...
9 August 2013 at 09:08

can i use private instead of using public


Anijit Sarkar said...
9 August 2013 at 23:16

No!
Main is call by JVM [Java Virtual Machine],
which is actually outside the project,
so, the access specifier of this method must be public.


Anonymous said...
8 September 2013 at 19:36

Main - JVM has to know the name of the method it is going to run. It could have been called "lollipop"for all the JVM cares as long as it is known and constant.

String[] - running a program from the command line means you can pass arguments to it. This is where those arguments get placed so that your program can handle them.



Anonymous said...
8 September 2013 at 23:10

Hi, Have one question..
Why the parameter of String[] needs to be passed in the main method, do we use it by somehow?
Please reply.. waiting to hear you soon..


Anijit Sarkar said...
8 September 2013 at 23:40

The parameter of String[] is for for command-line arguments in Java.
Check this link for command-line arguments : http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html

Or, in Eclipse also, you can simply try this:

Code:
public class TestMain {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.err.println(args[i]);
}
}
}

and now -> Right click -> run as -> run configurations -> select this class -> go to Arguments tab -> write some thing on Program arguments text area -> click apply -> clcik run

your inputs will be printed on eclipse console


Anonymous said...
3 July 2014 at 21:01

how can jvm enter in default class
in packages if a class is default its public methods cant be acccessed from outside
so if our class is default and we have public static void main(String arg[]){} in it how does jvm accesses this method


Unknown said...
26 March 2017 at 12:52

Awesome article thanks a lot for this


lingmaaki said...
23 May 2017 at 15:00

The main() method is the starting point of an application. When a program starts running, it has to start execution from somewhere. That somewhere is called main. Without it, there is no place to start running a Java program.

How the main Method Gets Called?

When the Java interpreter executes an application, it starts by calling the class's main() method. The main method then calls all the other methods required to run your application.

More...Java Interview Questions

Ling


Unknown said...
31 May 2017 at 17:05


Welcome Post very usefull informatation.and iam expecting more posts like this please keep updating us........


anurag singh said...
7 September 2017 at 18:58

thanks for sharing this information Java main method .


Unknown said...
19 January 2018 at 17:01

I have read your blog its very attractive and impressive. I like it your blog.
Best Java Course in Chennai


Krishna kumar said...
20 April 2018 at 17:48

Hi Mate,

Love it absolutely! So crystalline. No mumbo jumbo. No non-sense. Straight and simple. You guys need a standing ovation for your good work.
I have performed the following steps as a preliminary experiment.
1. Run the program with the jar as is. The program works.
2. Extract a .class file from a jar using 7-zip.
3. Delete that class file from the .jar using 7-zip.
4. Add back the class file extracted above using 7-zip.
5. Run the program with the modified jar. The program does not work.

What is the reason the program does not work after the final step? Is this surprising?
But nice Article Mate! Great Information! Keep up the good work!


Regards,
Krishna kumar


Anonymous said...
20 June 2018 at 12:37

thanks for sharing the more valuable information.
Indian Cyber Army credibility in Ethical hacking training & Cybercrime investigation training is acknowledged across nation as we offer hands on practical knowledge and full assistance with basic as well as advanced level ethical hacking & cybercrime investigation courses. The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hacking/ cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure.


Unknown said...
28 July 2018 at 17:20

Great and really helpful article! Adding to the conversation, providing more information, or expressing a new point of view...Nice information and updates. Really i like it and everyday am visiting your site..java training


NDA Coching in Meerut said...
6 October 2018 at 15:33


Hey, I am really glad I have found this information
NDA Coching in Meerut
Best Colleges in Up
Best Colleges in India
Latest Technology Updates
travel the stunning world
Latest Online Forms


Classboat said...
9 October 2018 at 16:47 This comment has been removed by the author.

Classboat said...
10 October 2018 at 11:26

Learn java from top training institute of java in Pune Top java training Institute in Pune and get professional java certificate


Praveen H said...
28 October 2018 at 17:28 This comment has been removed by the author.

Praveen H said...
28 October 2018 at 17:53

Thanks for the information
For java interview programs visit: Java programming


Jaweed Khan said...
17 January 2019 at 09:47

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.Java Course In Hyderabad


unicsol said...
9 May 2019 at 11:19

Learn java training in unic sol pvt ltd
I Found this article useful same as your. you can visit by clicking java training in Hyderabad


Kapil Rawat said...
10 September 2019 at 12:23

Great post. Thanks for putting it out. For readers who are interested, LifePage has the most exhaustive Career List.


aditya said...
25 October 2019 at 12:28

Thanks for sharing valuable information in on aboutcyber security course.


ashish malik said...
15 February 2020 at 17:08

Excellent job, Positive thoughts, I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Please keep posting and sharing.

Digital Marketing Company near me


neurotouchtherapy said...
31 March 2020 at 19:24

The thoughts while reading the article is amazing. Thanks for sharing this blog with us.


Deep tissue massage


Madhu said...
16 April 2020 at 17:55

click here to read more


Livewell Hospital said...
2 December 2020 at 16:56

Thank you for sharing this useful article with us. This blog is a very helpful to me in future. Keep sharing informative articles with us.

https://www.ahmedabadcomputereducation.com/course/laravel-training-course/


Livewell Hospital said...
7 January 2021 at 18:11

Awesome content for reading as well as knowledge. Thank you for sharing this informative article with us.

https://www.sdsfin.in/about-us/


Ekku2324@ said...
14 April 2021 at 17:58

Thank You for sharing this informative article.

https://web30india.com/


training institute said...
1 September 2021 at 08:17

Excellent effort to make this blog more wonderful and attractive.
data science course in malaysia


Reshma said...
2 September 2021 at 13:17



Amazing post.Thanks for sharing.........
Best way to learn java programming for beginners
Best Way to Learn Java


sam said...
12 October 2021 at 15:02

Thanks for sharing..

Job hiring in chennai.


Job hiring chennai said...
12 October 2021 at 15:03

Thanks for sharing'


taranstech said...
14 October 2021 at 17:10

This blog is so cool. I am learning Java Training online. This blogs helps me find out better understanding about salesforce training. Thank you for this blog!


hirededicatedresources said...
3 March 2022 at 12:02

Android Mobile App Development in Ahmedabad
Web 3.0 India is the most trusted Web3 Blockchain Development and NFT Development Company in USA. We also provides ICO, STO development for cryptocurrency.
https://web30india.com/


Anonymous said...
30 March 2022 at 16:29

Java : Public Static Void Main(String Args[]) - Explanation.
~
Java Interview Questions >>>>> Download Now

>>>>> Download Full

Java : Public Static Void Main(String Args[]) - Explanation.
~
Java Interview Questions >>>>> Download LINK

>>>>> Download Now

Java : Public Static Void Main(String Args[]) - Explanation.
~
Java Interview Questions >>>>> Download Full

>>>>> Download LINK


Livewell Hospital said...
26 July 2022 at 17:34

Thank you for this knowledgeable article.

Blockchain Development Company in Ahmedabad
Web3 Development Company
Mobile Application Development


Konrates said...
29 September 2023 at 04:48

Ankara
Bolu
Sakarya
Mersin
Malatya
SHG7F1


CosmicNomadXY123456789OIWEST said...
20 October 2023 at 06:09

istanbul evden eve nakliyat
zonguldak evden eve nakliyat
adıyaman evden eve nakliyat
bilecik evden eve nakliyat
ankara evden eve nakliyat
Q7G


SpaceSonsuzluk29 said...
1 November 2023 at 17:15

hatay evden eve nakliyat
ısparta evden eve nakliyat
erzincan evden eve nakliyat
muğla evden eve nakliyat
karaman evden eve nakliyat
KR7


OceanSesçisi14 said...
2 November 2023 at 06:25

muş evden eve nakliyat
çanakkale evden eve nakliyat
uşak evden eve nakliyat
ardahan evden eve nakliyat
eskişehir evden eve nakliyat
NDAGGW


07712Wilson8AEA2 said...
13 November 2023 at 23:34

1E939
Muş Lojistik
Raca Coin Hangi Borsada
Bayburt Şehirler Arası Nakliyat
Eryaman Parke Ustası
 Kırklareli Şehirler Arası Nakliyat 
Bilecik Parça Eşya Taşıma
Muş Evden Eve Nakliyat
Hamster Coin Hangi Borsada
Çerkezköy Çilingir


E72CBBrandon9CD97 said...
14 November 2023 at 09:57

CB159
Zonguldak Şehir İçi Nakliyat
Kalıcı Makyaj
Kilis Şehir İçi Nakliyat
Kocaeli Parça Eşya Taşıma
Denizli Parça Eşya Taşıma
Diyarbakır Lojistik
Çerkezköy Fayans Ustası
Yalova Lojistik
Adana Evden Eve Nakliyat


5D752MichaelD4EF3 said...
17 November 2023 at 01:10

D2811
Batman Şehir İçi Nakliyat
Niğde Lojistik
Batıkent Fayans Ustası
Isparta Parça Eşya Taşıma
Tekirdağ Parça Eşya Taşıma
Bilecik Lojistik
Keçiören Parke Ustası
Çerkezköy Ekspertiz
Iğdır Evden Eve Nakliyat


C0FF1BryanBD81E said...
1 December 2023 at 10:03

2C70D
binance komisyon indirimi


74987BrendenCF00A said...
4 December 2023 at 22:00

EE13A
referanskodunedir.com.tr


273A8Geraldine75B87 said...
10 December 2023 at 05:10

03A48
Bitcoin Mining Nasıl Yapılır
Binance Hangi Ülkenin
Bitcoin Madenciliği Nedir
Bitcoin Çıkarma
Bitcoin Nasıl Kazanılır
Gate io Borsası Güvenilir mi
Kripto Para Nasıl Çıkarılır
Binance Yaş Sınırı
Btcturk Borsası Güvenilir mi


641D3Andrew3A4D1 said...
5 January 2024 at 11:31

1D0D8
kırklareli canli sohbet bedava
istanbul görüntülü sohbet yabancı
sohbet uygulamaları
kırşehir yabancı canlı sohbet
ığdır yabancı görüntülü sohbet siteleri
Afyon Yabancı Görüntülü Sohbet
bolu telefonda kadınlarla sohbet
kırşehir canlı sohbet sitesi
maraş sesli sohbet sesli chat


D1E77Reginald871B4 said...
5 January 2024 at 13:04

60025
eskişehir görüntülü sohbet siteleri ücretsiz
Çankırı Ücretsiz Sohbet Sitesi
sohbet odaları
ığdır görüntülü sohbet kızlarla
adana ücretsiz sohbet odaları
random görüntülü sohbet
niğde ücretsiz görüntülü sohbet uygulamaları
bayburt sohbet odaları
istanbul canlı görüntülü sohbet odaları


D92BDPaytonB161A said...
5 January 2024 at 13:05

980D2
sivas rastgele görüntülü sohbet ücretsiz
bartın görüntülü sohbet uygulamaları ücretsiz
kadınlarla rastgele sohbet
canlı görüntülü sohbet uygulamaları
Adana Rastgele Sohbet
urfa sohbet
hatay görüntülü sohbet canlı
tekirdağ mobil sohbet odaları
isparta canlı sohbet et


6884BLitzy5D7C4 said...
7 January 2024 at 00:26

86D5E
Likee App Beğeni Hilesi
Binance Hesap Açma
MEME Coin Hangi Borsada
Bitcoin Nasıl Üretilir
Binance Ne Zaman Kuruldu
Instagram Beğeni Hilesi
Arg Coin Hangi Borsada
Görüntülü Sohbet
Expanse Coin Hangi Borsada


__Takipci Satin Al said...
18 February 2024 at 23:28

2572B
en eski kripto borsası
en düşük komisyonlu kripto borsası
binance ne demek
okex
paribu
bitcoin seans saatleri
en güvenilir kripto borsası
poloniex
canlı sohbet uygulamaları


--Takipci_satin_al said...
24 February 2024 at 23:11

7DCA0
kripto para nasıl alınır
bitcoin nasıl oynanır
bitmex
vindax
canlı sohbet ucretsiz
paribu
probit
binance
bitcoin ne zaman yükselir


_Takipci said...
27 February 2024 at 06:58

3EF1D
bitcoin nasıl üretilir
mobil proxy 4g
canlı sohbet
https://toptansatinal.com/
ilk kripto borsası
kripto ne demek
kripto para telegram
referans kimligi nedir
bingx


Anonymous said...
14 August 2024 at 15:11

zxgdvdxfhgbfdhfthju
صيانة افران الغاز بجدة


B9A186C6F6Andre5FE781C69A said...
11 October 2024 at 18:57

547EAD1329
ücretli şov sitesi


Anonymous said...
17 October 2024 at 17:29

تنظيف مجالس JWbf3Hj5Ig


Anonymous said...
6 November 2024 at 16:32

شركة مكافحة النمل الابيض 4YcSO2Jcq4


CCE91FCF66Lane08F42FCD1F said...
25 November 2024 at 11:05

981E12FCB6
show


Anonymous said...
8 December 2024 at 20:20

شركة تنظيف شقق بجازان Jp0KDdUa3w


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar