Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Entry point
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Java=== [[Java (programming language)|Java]] programs start executing at the main [[method (computer science)|method]] of a class,<ref name="Oracle">{{cite web | title=The Java Language Environment | website=Oracle | url=https://www.oracle.com/technetwork/java/simple-142339.html | access-date=2020-03-14 | quote=Within the HelloWorld class, we declare a single method called main() which in turn contains a single method invocation to display the string "Hello world!" on the standard output. The statement that prints "Hello world!" does so by invoking the println method of the out object. The out object is a class variable in the System class that performs output operations on files. | archive-date=2019-04-20 | archive-url=https://web.archive.org/web/20190420152142/https://www.oracle.com/technetwork/java/simple-142339.html | url-status=live }}</ref><ref name="Schildt 2019 p. ">{{cite book | last=Schildt | first=Herbert | title=Java : a beginner's guide | publisher=McGraw-Hill Education | location=New York | year=2019 | isbn=978-1-260-44022-5 | oclc=1061561931 | page=46 | quote=A JAVA program begins with a call to main ().}}</ref><ref name="Learn Java">{{cite web | title=Hello, World! - Free Interactive Java Tutorial | website=Learn Java | url=https://www.learnjavaonline.org/ | access-date=2020-03-14 | quote=In Java, every line of code that can actually run needs to be inside a class. "public class Main {}" declares a class named Main, which is public, that means that any other class can access it.}}</ref><ref name="Learn Java II">{{cite web | title=Hello, World! - Free Interactive Java Tutorial | website=Learn Java | url=https://www.learnjavaonline.org/ | access-date=2020-03-14| quote="public static void main(String[] args) {} " is the entry point of our Java program. the main method has to have this exact signature in order to be able to run our program.}}</ref> which has one of the following [[method heading]]s: <syntaxhighlight lang="java"> public static void main(String[] args) public static void main(String... args) public static void main(String args[]) void main() </syntaxhighlight> Command-line arguments are passed in <code>args</code>. As in C and C++, the name "<code>main()</code>" is special. Java's main methods do not return a value directly, but one can be passed by using the <code>System.exit()</code> method. Unlike C, the name of the program is not included in <code>args</code>, because it is the name of the class that contains the main method, so it is already known. Also unlike C, the number of arguments need not be included, since arrays in Java have a field that keeps track of how many elements there are. The main function must be included within a class. This is because in Java everything has to be contained within a class. For instance, a [["Hello, World!" program|hello world]] program in Java may look like: <syntaxhighlight lang="java"> public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } } </syntaxhighlight> To run this program, one must call <code>java HelloWorld</code> in the directory where the compiled [[Java class file|class file]] <code>HelloWorld.class</code>) exists. Alternatively, executable [[JAR (file format)|JAR]] files use a [[manifest file]] to specify the entry point in a manner that is filesystem-independent from the user's perspective.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)