+ 1

Help in Java...

In school we were taught to start programs with "public static void main(String[] args)" and now we start them using "public void display()". Can someone explain to me what both of these mean and what's the difference?

23rd Dec 2017, 3:00 AM
anshul_p24
anshul_p24 - avatar
3 Answers
+ 2
public static void main() it is method that, in each Java program is considered as a starting point, this is how Java Virtual Machine witch runs your program know where to start. You can have other methods and classes in your program, but only one main. There are few separate words in it declaration here what does they mean: 1 public it is access modifier it means that this method visible to every other class in your program. 2 static this means that your method can be accessed by JVM without creation of object of this class. 3 void it means that method after execution doesnt return anything. For example if you need method witch will calculate sum of two simple numbers(integers) return type of this method should be int so it will return sum and return number of int type. Since you dont need to return anything from main method it has void return type.
23rd Dec 2017, 4:49 AM
Dima Makieiev
Dima Makieiev - avatar
0
public void display() means it has no return value. public static void main is the main function which is like your screen.In there, what you want to show on screen that functionality happens. 👏😰
23rd Dec 2017, 3:19 AM
NabiL
NabiL - avatar