Java 7 ways of declaring main in java

  • Thread starter Thread starter josephaswin
  • Start date Start date
  • Tags Tags
    Java
AI Thread Summary
In Java, the main method can be declared in various ways, primarily by altering the access modifier and the static keyword. The common declarations include "public static void main(String args[])" and "static public void main(String args[])." However, it is possible to declare the main method as private or protected, which will compile but lead to a runtime error indicating that main() isn't public. Removing the static keyword results in a compilation error. The discussion raises questions about the purpose of declaring the main method in different ways, suggesting a curiosity about the implications of such variations.
josephaswin
Messages
1
Reaction score
0
hi,

i know there are 7 ways to declare main in java
as

1.public static void main(String args[])
2.static public void main(String args[])

but what are the other ways?

but only change first two keywords
i.e. public and static
and use the required keywords.

this is the question given to me.
 
Technology news on Phys.org
Apparently you can declare main() as private or protected, too. The code will compile, but you'll get an error when you run the program saying main() isn't public. I didn't know that. Also, I don't think you can remove "static" as you'll get an error when you try to compile if you do. Why do you want to declare main() in different ways anyway?
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top