HELLO WORLD

in java •  6 years ago 

If you are here, then probably you've just begin learning java

... or you are stalking me
...or you are CIA/FBI
...
...anyways, Here I present you the starting line of this marathon

TADA!! THE A-B-C of JAVA.

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

The "Hello World!" application consists of 2 primary components:

  • the HelloWorldApp class definition, and
  • the main methods

The HelloWorldApp Class Definition

The following text begins the class definition block for the "Hello World!" application:

class HelloWorldApp {
 . . .
}

As shown above, the most basic form of a class definition is:

class name {
 . . .
}

The keyword class begins the class definition for a class named name, and the code for each class appears between the opening and closing curly braces marked in bold above. For now it is enough to know that every application begins with a class definition.

The main Method

The following bold text begins the definition of the main method:

public static void main(String[] args) {
    System.out.println("Hello World!");
}

In the Java programming language, every application must contain a main method whose signature is:

public static void main(String[] args)

The modifiers public and static can be written in either order (public static or static public), but the convention is to use public static as shown above. You can name the argument anything you want, but most programmers choose "args" or "argv".

The main method is similar to the main function in C and C++; it's the entry point for your application and will subsequently invoke all the other methods required by your program.

The main method accepts a single argument: an array of elements of type String.

public static void main(String[] args)

This array is the mechanism through which the runtime system passes information to your application. For example:

java MyApp arg1 arg2

Each string in the array is called a command-line argument. Command-line arguments let users affect the operation of the application without recompiling it. For example, a sorting program might allow the user to specify that the data be sorted in descending order with this command-line argument:

-descending

The "Hello World!" application ignores its command-line arguments, but you should be aware of the fact that such arguments do exist.

Finally, the killer line:

System.out.println("Hello World!");

uses the System class from the core library to print the "Hello World!" message to standard output.

That's "Hello World!" for you guys. I have kept the article brief because I believe that most of the learning happens via interacting rather than reading. So let the questions flow...

All questions/edits/suggestions are welcomed.
Source: docs.oracle.com

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Source
Copying/Pasting full or partial texts without adding anything original is frowned upon by the community. Repeated copy/paste posts could be considered spam. Spam is discouraged by the community, and may result in action from the cheetah bot.

More information and tips on sharing content.

If you believe this comment is in error, please contact us in #disputes on Discord

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://docs.oracle.com/javase/tutorial/getStarted/application/index.html