Getting Started with Java First program: Hello World!__java

Source: Internet
Author: User

Before you write your program, recommend a handy online compiler:

https://www.shucunwang.com/RunCode/java/


Code:

Import java.io.*;
Class Test  
{public
	static void Main (string[] args) throws Java.lang.Exception
	{
		System.out.println (" Hello world! ");
	}


Run Result:

Hello world!

Analysis:

(1) Here test is a class that represents an abstract collection of objects of a class. For example, "person" is a class, "John" is a specific object.

(2) In Java, the main () method is the entry method for a Java application, that is, when the program is running, the first method to execute is the main () method, which is very different from other methods, such as the name of the method must be main, and the method must be public static void type, the method must receive arguments for a string array, and so on.

Note: The method in the Java language is the same as the function in C, except that it is called a different word.

(3) The function of System.out.println () is to output the result in the console and wrap the line. println represents print line.

The effect of Sytem.out.print () is to enter the results in the console without wrapping.

Compare the following two programs

A

Import java.io.*;
Class Test  
{public
	static void Main (string[] args) throws Java.lang.Exception
	{
		System.out.println (" Hello world! ");
		System.out.println ("123");
		SYSTEM.OUT.PRINTLN ("Hi");
	}


Run Result:

Hello world!

123

Hi

Two

Import java.io.*;
Class Test  
{public
	static void Main (string[] args) throws Java.lang.Exception
	{
		System.out.print ("Hello world!");
		System.out.print ("123");
		System.out.print ("Hi");
	}


Run Result:

Hello World!123hi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.