Java Basics under Chapter I (Java format, base type, operator)

Source: Internet
Author: User
Tags arithmetic operators java format

First, Java basic format

public class demo1{//class name to be the same as the file name

public static void Main (string[] args) {//wrap each line, four spaces indent

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

End of statement ends with a semicolon

}

}

II. Basic data types

Integral type:

1.byte: Between byte-type 8-bit -128~127.

2.short: Short integer 16-bit -32768~32767.

3.int: Integer 32-bit.

4.long: Long integer 64 bits//end preferably plus l

Floating point type:

1.float: Single precision 32 bits//end preferably plus f.

2.double:64 bit double precision.

Character type:

Char: Character type//' single quotation mark contains example: char a = ' a ';

Boolean type:

Boolean: The Boolean value is: True/false.

Three, implicit conversion (from small to large conversion)

Byte,short,char-->int-->long-->float-->double

Example: int a = 10;

Long B = A;

B is implicitly converted to a long type.

Iv. Casting (conversion from large to small)

Format: (cast type) variable or value.

Note: The use of casts is generally not recommended.

Example: int a = 10;

byte B = (byte) A;

Five, type compatible

Char is only compatible with shaping

Example: char a = "a";

int b = A;

B-->65

Vi. operators

1. Arithmetic operators

+ +,--, +,-, *,/,%

2. Relational operators

, <,! =, = =, >=, <=

3. Logical operators

&&, &, | |, |,!

&&, | | Differences with &, |

&&, &--> When the result of the first expression determines the overall result, it is not executed at a later time.

&, | --regardless of whether the first expression is true/false, the last expression is executed.

Example: int a = 1;

int b = 2;

int c = 3;

int D;

D = b > A | | b > C;

Since B > A was established, B > C was not executed.

Java Basics under Chapter I (Java format, base type, operator)

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.