0
When to Public statci void main method??
Hi everyone.. I'm new in learning java. at first sololearn used class Myclass{ public static void main.... then other codes }} but from then input section , sololearn start using import java.util.Scanner before the class Myclass{ .. now I'm confused that where to write the public static void main and why import java.util.Scanner used before everything else? thanks in advance.
3 ответов
+ 10
Each programming language has an entry point.
In case of Java, it is "public static void main" that tells the compiler that this is entry point of the program.
If it's not present in the code, then your code won't compile and run.
void is the return type of the function, which means this function will return nothing.
main is the name of the function.
public and static are little bit difficult for you to understand now since you are a new programmer. So when you dive deeper in Java, you'll get to know that what are they and why they are used. They are also told in Sololearn course.
But for now remember that public static void main is entry point of your code and you have to write it in your every Java program.
+ 9
Scanner is a utility provided by the Java to take input either from the user or any other input device.
In order to use the scanner, we need to import the scanner utility .
And yes it's written on the top of all classes.
0
Thanks bro. so the import need to write first . but when exactly to write
public static void main(...){ } . I'm very new here. sorry for the messy question.