Java Syntax Basics One

Source: Internet
Author: User

Java Grammar Foundation One

    • Java Code Basic Format

All program code in Java must exist in a class, define classes with the Class keyword, and have some modifiers before class. The format is as follows:

Modifier Class class Name

{

Program code

}

Note: 1, Java is strictly case-sensitive .

2. A sequential string in a Java program cannot be written separately in two lines.

    • Java notes for the program

There are three types of annotations in Java:

1. Single-line Comment

Add "//" in front of the comment, in the following format:

Code Comment Content

2, multi-line Comment

Starts with a slash and an asterisk, ending with an asterisk and a slash.

3. Documentation Comments

Starts with a slash and two asterisks, ending with an asterisk and a slash.

The content that is annotated in this way is interpreted as a formal document of the program and can be included in a document generated by a tool such as Javadoc to illustrate the hierarchy of the program and its methods.

    • Java the identifiers in

The names of packages, classes, methods, parameters, and variables in Java can be made up of any order of uppercase and lowercase letters, numbers, underscores (_), Dollar signs ($), but cannot start with a number and cannot be reserved keywords in java.

Note: The name of the package, class, method, parameter, variable in Java is recommended when the camel type is used. such as: HelloWorld

    • Java the key word

1. Declarations for classes and interfaces: Class, extends, implements, interface

2. Package introduction and Packet Declaration: import, Package

3. Data type: Byte, Boolean, char, double, int, long, float, short

4. Literal values for some data types: flase, ture, NULL

5. Process Control: Break, case, continue, default, does, else, for, if, return, switch, while

6. Exception handling: Catch, finally, throw, throws, try

7, modifier: Abstract, final, native, private, protected, public, static, synchronilzed, transient, volatitle

8, Operator: instanceof

9. Create object: New

10. Citation: This, supper

11. Method return Type: void

12. Reserved word: const, goto

    • Java The data type:

The underlying data type of 1.Java is not related to a downlevel operating system or platform, and the numeric values are signed, both in

Storing a positive number can also store negative numbers, the char type is 16 bits, and there are no symbols, and the Boolean type can only contain

True and False for these two values.

2. Integer literal values are by default int type, to use a long type, you must add L or L to the end of the

The floating-point literal value defaults to the double type, and if you want to use the float type, you must add F or F to the end of it.

3. The reference does not contain the actual data of the object it refers to, but instead points to the location of the object in memory, and the object

Contains the actual data, in Java, the reference either points to an object, or it points to null. This is also the Java

One of the security features: The programmer is not allowed to access memory directly.

The commonly used escape characters are:

\r--means to accept keyboard input, which is equivalent to hitting the ENTER key.

\n--indicates line break

\t--represents a tab, which is equivalent to the TAB key

\b--represents the Backspace key, which is equivalent to the back space key

\ '--denotes single quotation marks

\ "--denotes double quotation marks

\\--= backslash "\"

Java Syntax Basics One

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.