Basic grammar of Java Learning Notes (i)

Source: Internet
Author: User

The 1.java language is based on keywords, identifiers, annotations, constants, and variables, operators. Statements, functions, and arrays.

2.1 Key Words

Definition: Words that are given special meaning by the Java language

Feature: All letters in the keyword are lowercase.

2.2 Keywords to define the data type

Class, interface, Byte, short, int, long, float, double, char, Boolean, void

2.3 Keywords for defining data type values

True, FALSE, NULL

2.4 Keywords to define Process Control

If, else, switch, case, default, while, do, for, break, continue, return

2,5 keywords for access rights modifiers

Abstract, final, static, synchronize

2.6 Keywords to define the relationship between classes and classes

Extends, implements

2.7 To define keywords that create instances and their reference instances

New, this, super, instanceof

2,8 for the exception

Try, catch, finally, throw, throws

2.9 Keywords for the package

Package, Import

2.10 Other modifier keywords

Native, Assert

3. Write code specification

The first letter of the class name is capitalized, one of the naming conventions, and the name is known.

4. Identifiers

Definition: Customize some names in your program

Rules: Numbers cannot be started, keywords are not used, and special characters are not available. "I don't feel like a normal naming problem."

5.java Name Specification:

Package Name: Read a word make up all the letters are lowercase

Class name and Interface name: Capitalize the first letter of all words

Variable name and function name: First lowercase, followed by the first letter capitalized.

Constant name: All letters are capitalized

6. Define the class, because the Java program is defined in the class, the Java program is formed in the form of a class, the form of the class is actually a byte-code file final embodiment.

The main function is to allow the class to run independently.

7 Constants

Definition: A value that cannot be changed by a constant

Categories of constants: Positive constants, Decimal constants, Boolean constants, character constants, string constants, and null constants.

8. Binary: Binary, octal, decimal, Hex.

9. Variable: A storage area in memory that has its own name and type, and that the data for that region can change continuously within the same type range. Variables are actually storage of uncertain data, that is, the need to open up a space in memory.

Use steps for variables: Define variables, assign values to variables, and use variables.

Declaration of variable: data type variable name = value;

Or

Data type variable name;

Variable name =value;

Data types for 10.java languages: Byte (1 bytes), short (2 bytes), int (4 bytes), Long (8 bytes), Float (4 bytes), double (8 bytes), char (2 bytes).

The data type of the 11.java language includes 8 basic data types, and 3 introduces the types. Reference type: Class, interface, array.

12. A variable name can only be defined once;

int's integer type cannot exceed the range of int data, then an error is escalated, and using the Long data type requires L to be added at the end of the data.

Decimal By default is a double type, assigned to the float data type variable, will lose precision, it is necessary to pass the compiler's audit. If you want to have a float data, you need to add an F at the end.

Uninitialized variables cannot be manipulated.

The scope of the variable.

13. Data type: Cast, and auto-convert.

Automatic conversion: When a table range of small direct volume or variable directly assigned to a large range can be automatically converted.

Cast: Convert large into small, direct conversion.

14. Operators:

Operator classifications in the Java language: arithmetic operators, assignment operators, comparison operators, logical operators

The "+" operator can be used not only as an arithmetic operator, but also as a string join operator.

The "-" operator can be used not only as a subtraction operator, but also as a negative operator.

The "/" operator divisor is not 0, two integers, the result is two number of quotient, if two or a number is floating point type, then the result is floating point type

15. Automatic conversion of data types: variables of type int are 4 bytes, and when a variable of type byte is added to it, the data type is first promoted to int and then added.

The value of the data if a byte value is added to the data type of an int, the result is not given to byte, and the responsibility is an error.

This has a usage: converting positive numbers to negative numbers, first using int, and then a byte to intercept, you can get negative numbers.

Automatic conversion of data type manipulation data types:

All byte type, short and char conversions to int

If one of the operands is a long data conversion to a long type

If an operand is float-type data converted to float type

If one of the operands is a double type, the data is converted to double

16. Execute the short s;s+=4 statement, the compiler at compile time, the default is forced type conversion, that is, the int type of data conversion to short type of data.

Short s=0; S=s+4 error, because when the compiler is compiled, the default does not cast, S is short,4 is the int type, S is automatically converted. The addition is the int type, the assignment to the short variable, the loss of precision, it is necessary to cast: s= (short) (s+4);

Basic grammar of Java Learning Notes (i)

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.