Java SE02 Java language Fundamentals: keywords, identifiers, annotations

Source: Internet
Author: User
Tags float double modifiers try catch

    • Keywords: Some words that have been given Java meaning,class public static void

      Keyword that defines the access permission modifier

      Private protected public

      Defining classes, functions, variable modifiers

      Abstract final static synchronized

      Keywords that define relationships between classes and classes

      Extends implements

Define an instance, reference an instance, and judge an instance

New This super instanceof

Handling Exceptions

Try Catch finally throw throws

Keywords for the package

Package Import

Keywords for other modifiers

Native STRICTFP transient volatile assert


    • Identifiers: Some of the names that you customize in your program, such as defining classes. Try to make it meaningful and enhance the reading of the program

26 English letter case, 0-9 digits, _$ two symbols. But cannot start with a number and cannot use the keyword

    • Notes for easy reading, interpretation of program language

Single-line note the Yellow River into the ocean in the daytime


/*

Multi-line comments, can also be used to narrow the scope of the troubleshooting!

The day depends on the mountain

The Yellow River into the ocean

*/


/**

Document annotations, which can be extracted using Java Javadoc

Used as a program manual

*/

    • Constants and variables

Constants are values that cannot be changed (integers, decimals, Boolean Boolean constants, character constants ' strings "" null)

A variable is a storage area in memory that has its own name and type

    1. byte short int long//integer type

    2. float Double//floating-point type

    3. char//character type

    4. Boolean//Boolean type

    5. Class//Classes

    6. interface//interface

[]//array

Class vardemo{public static void Main (string[] args) {byte b=126;//character test int x=327899;//test int length    System.out.println (b);    SYSTEM.OUT.PRINTLN (x); }}

Execution results

D:\lab\java>javac 0908.java
D:\lab\java>java Vardemo
126
327899

Lass vardemo2//automatic type promotion with coercion type conversion {public static void main (string[] args)/* {byte x=9;     int y=65535; Y=x+y;    Add x y to System.out.println (y);    } */{byte b=100;      B= (Byte) (b+30);//coercion type conversion System.out.println (b); }}

D:\lab\java>javac 090802.java
D:\lab\java>java VarDemo2
-126


The ASCII code and the GBK code of a single letter or kanji will also be corresponding to the code table in memory to produce corresponding values

{System.out.println (' I ' +0); }

D:\lab\java>javac 090802.java
D:\lab\java>java VarDemo2
25105


An interesting case.

{byte b=4;      BYTE b1=3;      BYTE b2=5;      B=B1+B2;          System.out.println (b); }}

D:\lab\java>javac 090802.java
090802.JAVA:20: Error: Possible loss of precision
B=B1+B2;
^
Required: Byte
Found in: int
1 errors

Cause: B1 B2 is a variable, although the above defines a value, but not always fixed, such as the next time to assign a value b1=127? If the byte load range is exceeded, the precision is lost. Here is a concept that lets us understand the variables.

B=B1+B2//Right is not fixed, there is no way to judge

But int does not have this problem (only 32-bit cast high-level full discard is reserved)


    • Operator

    • Statement

    • Function

    • Array


This article is from "The Old artisan" blog, declined reprint!

Java SE02 Java language Fundamentals: keywords, identifiers, annotations

Related Article

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.