What does it mean in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does it mean in java?

public static void main(String args[])

9th Feb 2021, 2:37 AM
Aman sharma
13 Answers
+ 15
Public : an access specifier Static: a keyword which allows us to run this method without making its object Void: a return type with no data type Main : name of method String []= an string array Args: name of array Details of this are given in the course
9th Feb 2021, 4:55 AM
Piyush
Piyush - avatar
+ 9
public: Access specifier, this one means that this bit of code can be accessed by any other class or object or whatever static: a keyword to mark a method as one that can run without an object instance void: return type, this case meaning that nothing is returned main: the name of a special method (standard) that acts as an entry point for code String[] args: An array of strings that are accepted as parameters for the main method.
9th Feb 2021, 5:19 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
Aman sharma I think explanation is given here https://www.sololearn.com/learning/2137/ It's a entry point of Java program.
9th Feb 2021, 3:57 AM
A͢J
A͢J - avatar
+ 3
Yes these are correct but make the function static then only you can call the function without any object otherwise you have to make an object to call the methods
9th Feb 2021, 7:33 AM
Piyush
Piyush - avatar
+ 3
Aman sharma no it will not work because main method act as a entry point for the program as stated in 👑 Prometheus 🇸🇬 answer you can see there
12th Feb 2021, 3:23 AM
Piyush
Piyush - avatar
+ 2
Aman sharma In void methods you can't use return keyword to return the values you can use the print statement as you are using in any type of methods
9th Feb 2021, 7:25 AM
Piyush
Piyush - avatar
+ 2
Yup 👍
9th Feb 2021, 7:35 AM
Piyush
Piyush - avatar
+ 1
Oh, thnx I never thought that this String https://www.sololearn.com/learning/2137 could get me what I want 😂
9th Feb 2021, 4:33 AM
Aman sharma
+ 1
₱łɎɄ₴Ⱨ 🇮🇳 If we mark function return type as void then will it be able to return all data types like if public void example(int a, int b) { int c=a+b; System.out.print("Your output is"); System.out.print(c); } will it return a int and String both
9th Feb 2021, 7:23 AM
Aman sharma
+ 1
are these correct?👇 public int sum(int a, int b) { return a+b; } sum(5,-5); And the other one 👇 public void sum(int a,int b) { System.out.print("The sum of the two numbers is:"+(a+b)); } sum(5,-5);
9th Feb 2021, 7:30 AM
Aman sharma
+ 1
Okay just I need to add a static keyword in both the functions after the access specifier 😁
9th Feb 2021, 7:35 AM
Aman sharma
+ 1
₱łɎɄ₴Ⱨ 🇮🇳 Will a program run without method main? I think No but asked for confirmation. will a program run if we make a method with this name public static void anynams(String[] args) instead of public static void main(String args[])
12th Feb 2021, 2:55 AM
Aman sharma
+ 1
₱łɎɄ₴Ⱨ 🇮🇳 yeah, I read 👑 Prometheus 🇸🇬 answer but wanted to know if we can use any name for the main method. Thank you 😁
12th Feb 2021, 6:13 AM
Aman sharma