Java basic syntax Summary 1. java syntax Summary

Source: Internet
Author: User

Java basic syntax Summary 1. java syntax Summary

1. identifier and Character Set

The Java language requires an identifier to start with a letter, underscore "_", or dollar sign "$", followed by a string of numbers, letters, underscores, or dollar signs. Java identifiers are case sensitive and have no length restrictions. They can be names of any length, but keywords cannot be identifiers. To enhance program readability, Java makes the following conventions:

1. Class and interface: nouns are usually used, and the first letter of each word must be capitalized.

2. Method: usually use a verb, with the first letter in lowercase, followed by an uppercase letter to separate each word

3. constants: all uppercase words separated by underscores

4. variables: usually use nouns and lowercase letters, followed by uppercase letters to separate each word, avoiding the use of the $ symbol.

Java uses international character sets (Unicode ). The Unicode Character Set defines a set of international standard character sets. Generally, the ASCII code is 8 bits, and each character in the Unicode Character Set occupies 16 bits, that is, two bytes. The entire character set contains 65336 characters, compatible with ASCII, the first 256 characters in the Unicode Character Set are ASCII codes. In addition to 256 ASCII codes, Unicode can also represent Chinese characters, Latin, Greek letters, and Korean.

Java identifier Summary: 1. It consists of letters, numbers, _, or $ and cannot start with a number; 2. It is case sensitive; 3. It is not limited in length.

Ii. Keywords

The list of common Java keywords is as follows:

Keywords

Description

Abstract

It is used in the declaration of classes to indicate that a class cannot be instantiated, but can be inherited by other classes. An abstract class can use abstract methods. abstract methods do not need to be implemented, but must be implemented in subclasses.

Boolean

Boolean Type, only true or false

Break

Stops and jumps out of this layer of Loop

Byte

8 bits (BITs), that is, 8 1/0 represents, that is, binary

Case

It is used to define a group of Branch selection. If a value is the same as the value given in the switch, it is executed from this branch.

Catch

It is used to declare a block that runs when a runtime error occurs in the try statement block or a non-runtime exception occurs.

Char

Used to define a character type

Class

Class

Const

In Java, const is used as reserved words for expansion, and the same reserved words are used for expansion and goto. you can use the final keyword. final can also be used to declare methods or classes. Methods or classes declared as final cannot be inherited. Generally, the const in C corresponds to the final in java.

Continue

It is used to interrupt the current loop process and re-execute the process from the end of the current loop. If there is a tag behind it, it is executed from where the tag corresponds.

Default

The statement is output or followed by default when the switch and case are used, but no matching is found in the case.

Do

Used to declare a loop. The ending condition of this loop can be set using the while keyword.

Double

Used to define a double Type Variable

Else

If the conditions of the if statement are not met, the statement is executed.

Extends

The extends inheritance Class X adds functions through the extend class Y, or adds variables, or adds methods, or overwrites the method of class Y. One interface extends another interface to add methods.

False

False

Final

A keyword in Java. You can only define an object once and cannot change or inherit it later. More strictly speaking: A final-modified class cannot be subverted, a final-modified method cannot be overwritten, and a final-modified variable cannot change its initial value.

Finally

It is used to execute a piece of code, regardless of whether an exception or runtime error occurs in the try Statement defined earlier.

Float

Used to define a floating point variable

For

Declare a loop. Programmers can specify the statements to be cyclic, introduce conditions, and initialize variables.

Goto

Although it is a Java keyword, it is only used in the C language. Java does not provide a Goto statement.

If

A keyword of Java programming language used to generate a condition test. if the condition is true, the statement under if is executed.

Implements

A keyword of the Java (TM) programming language is optional in the class declaration to specify the interface implemented by the current class.

Import

A keyword of Java (TM) programming language. It specifies a class or the entire package to be referenced later in the start part of the source file, so that the package name does not need to be added during use.

Instaceof

The Java (TM) Language keyword of a Two-operand is used to test whether the runtime type of the first parameter is compatible with the second parameter.

Int

A keyword of Java (TM), used to define an integer variable.

Interface

A keyword of Java (TM), used to define a series of methods and constants. It can be implemented by the class through the implements keyword.

Long

Defines a long variable.

Native

Local method.

New

Used to create a new method

Null

If the String type is not assigned a value, the value of this variable is Null.

Package

Meaning of Package

Private

Used in the sound of a method or variable. It indicates that this method or variable can only be accessed by other elements of this class.

Protected

It is used in the declaration of methods and variables. It indicates that this method or variable can only be accessed by elements in the same class, subclass, or class in the same package.

Public

It is used in the declaration of methods and variables. It indicates that this method or variable can be accessed by elements in other classes.

Return

Used to end the execution of a method. It can be followed by a value required in the method declaration.

Short

Defines a variable of the short type.

Static

Defines a variable as a class variable. The class only maintains a copy of the class variable, no matter how many instances the class currently has. "Static" can also be used to define a method as a class method. A class method is called by class name instead of a specific instance and can only operate class variables.

Super

Parent class

Switch

It is a selection statement used with case, default, and break.

Synchronized

Thread Synchronization

This

An instance that represents the class it appears. This can be used to sort class variables and class methods.

Threadsafe

Throw

Attackers can throw an exception object or any object that implements throwable.

Throws

It is used in the method declaration to indicate which exceptions this method does not handle, but is submitted to a higher layer of the program.

Transient

Indicates that a domain is not a serialized part of the object. When an object is serialized, the value of the transient variable is not included in the serialized representation. However, non-transient variables are included.

True

True

Try

Defines a block that may throw an exception. If an exception is thrown, an optional catch Block will handle the exception thrown in the try block. At the same time, a finally statement block is executed, regardless of whether an exception is thrown.

Void

The method declaration in Java indicates that this method does not return any value. "Void" can also be used to indicate a statement without any function.

Volatile

It is used in the declaration of a variable to indicate that the variable is modified asynchronously by several threads running at the same time.

While

Defines a loop statement that is executed repeatedly. The exit condition of the loop is part of the while statement.

Categories:

1. Access Control: private protected public

2. class, method, and variable modifier abstract declaration abstract class extends extension, inherit final ultimate, unchangeable implements implement interface native local new, create static strictfp strict, precise synchronized thread, synchronization of transient for a short period of volatile is easy to lose

3. program control statement break jump out of loop continue return do run while loop if else otherwise for cycle instanceof instance switch case return switch result default

4. Error Handling catch handling exception finally whether there are any exceptions execute throw to throw an exception object

Throws declares an exception and may be thrown by a try to catch the exception.

5. import package packages

6. Basic type boolean byte char character double float floating point int integer long integer short integer null true false

7. Variables reference super parent class. super class this class void has no return value

Note: 1. All java keywords are in lowercase. 2. goto and const are reserved keywords. They are not used in java. 3. strictfp and volatile are not commonly used. sizeof and then are not keywords.

4. true, false, and null are not strictly keywords, but literals.

 

(To: http://www.cnblogs.com/doit8791/archive/2012/05/26/2519545.html)

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.