A few getting started applets for Java

Source: Internet
Author: User

1. First the most classic Hello world!

 Public class Hello {    publicstaticvoid  main (String args[]) {         System.out.println ( "Hello world!" );     }}
Hello world!

The difference between 2.print and println

 Public class Hello {    publicstaticvoid  main (String args[]) {        System.out.print ( "Hello world!" );         System.out.println ("Hello world!" );        System.out.println ("Hello world!" );     }}
Hello World!hello world! Helloworld!

Apparently println ended up with a newline and print no, so it's better to use println.

Usage of 3.PRINTLN

 Public class Hello {    publicstaticvoid  main (String args[]) {        int x= 2;        SYSTEM.OUT.PRINTLN (x+ "*" +x+ "=" + (x*x));}     }
2*2=4

The number to be output here is connected with the "+" number.

4. Declaration of Constants

 Public class Hello {        staticfinalint year=365;          Public Static void Main (String args[]) {        System.out.println ("Two years equals" +2*year+ "Day");}     }
Two years equals 730 days.
 Public class Hello {        publicstaticvoid  main (String args[]) {        final int year=365;        System.out.println ("Two years equals" +2*year+ "Day");}     }
Two years equals 730 days.

Constant assignment Syntax final+ data type + variable name = variable value, when constant is used for a member variable of a class, you must assign a value to the constant.

5. Declaration of variables

 Public class Hello {        publicstaticvoid  main (String args[]) {        int Num=3;         Char ch= ' a ';        SYSTEM.OUT.PRINTLN (num+ "is an integer");        SYSTEM.OUT.PRINTLN (Ch+ "is character");}     }
3 is the integer A is the character

These programs are extracted from the Java book, the code in the book itself with the compiler run again, for beginners like me very good.

A few getting started applets for Java

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.