Java Syntax Basics

Source: Internet
Author: User

Java Syntax Basics

1. Key words

Some words have special meanings to the compiler and cannot be used as identifiers, all lowercase letters

Java language keywords

Abstract

Boolean

Break

Byte

Case

Catch

Char

Class

Try

Do

Default

Continue

Double

Else

Extends

Assert

Final

Finally

Float

For

If

Implement

Import

instanceof

Int

Interface

Long

Native

New

Goto

strictfp

Package

Private

protected

public

return

Short

static

void

Switch

This

Synchronized

Throw

Throws

Transient

Const

Super

Volatile

While

Three reserved characters: Goto, FALSE, NULL

Main is a special name used to describe the starting method of a Java program, but it is not a keyword

2. Identifiers

Naming rules: can only be numbers, letters, underscores, $

Cannot start with a number

Strictly case-sensitive

cannot be a keyword

3. Data type

Basic data type:

Data type

Key words

Size

BYTE type

Byte

8 Guests

Short-integer

Short

16 Guests

Integral type

Int

32 Guests

Long integer type

Long

64 guests

Single-precision

Float

32 Guests

Double-precision Type

Double

64 guests

Character type

Char

16 Guests

Boolean type

Boolean

Not sure, determined by the JVM

Reference type: Class, interface, array

The difference between a reference type and a base type: The reference does not contain the actual data of the object it points to, but instead points to the location of the object in memory.

Basic types of variables, Java virtual machines put them in the Java stack

A variable of a reference type, the reference type itself is placed in the Java stack, and the object pointed to by the reference is placed in the Java heap

4. Variables

Data type variable name

For example: int A;

Assignment method: 1.int a = 3;

2.int A;

A = 3;

5. Constants

Use the final keyword in Java to indicate that a variable is actually a constant

Programmers often capitalize all the letters of a constant

6. Operators

Operator classification

Operator

Pre-or post-increment/decrement

+ + 、--

Unary operators

+ 、-、 ~,! (cast)

Multiplication/Division/Modulus

*、/、%

Add/subtract/String connections

+ 、-、 +

Shift Operators

<<, >>, >>>

Comparison operators

<, <=, >, >=, instanceof

Equality operators

= =,! =

Bitwise operators

&, |, ^

Condition And,or

&&, | |

Trinocular operator

?:

Assignment operators

=

Extended assignment operators

*=,/=,%=, + =,-=, <<=, >>=, >>>=, &=, ^=, |=

7. Comments

Single-line Comment: Peer text with two forward slash "//" comment out Slash

Multiline Comment: the "/*" and "* *" symbols are used for comments on multiple lines of code. Open the comment with "/*" and "*/" to close the comment. So the text will be commented out between the two.

Javadoc notes: "/**" and "* *" are a pair of special types of annotation symbols that are used with the Javadoc tool to generate HTML files that contain comments. These generated HTML pages are provided to the programmer along with the Java code to help the programmer understand the purpose and usage of the code. In Java, this feature is widely used.

Java Syntax Basics

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.