can somebody tell me the line:
public static void main(String[] args) {}
especially the highlighted ones in detail.
why do we need to use static? public?

Recommended Answers

All 3 Replies

public is so any class can use it.
static is so you don't have to instantiate the class before calling that method.

Public: So that your class will be accessed by others
Static: This tells that this or your main method class won't be instantiated.

you need to save your program with the class name which contains your main method (public).

String args[] : is an array of command line arguments..

Save this program as hello.java

class hello {
public static void main(String args[]) {
System.out.print("Hello World");
}
}

Cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.