2 Primitive type arrays and enumeration types--Re-picking Java

Source: Internet
Author: User
Tags java keywords

2.1 identifier and Keyword 2.1.1 identifier

Identifier: A valid sequence of characters used to flag the class name, variable name, method name, type name, array name, and file name is called an identifier. Simply put, an identifier is a name.

Java syntax rules for identifiers

Identifiers consist of letters, underscores, dollar signs, and numbers, and are not limited in length.

The first character of a marker cannot be a numeric character.

Identifier cannot be a keyword

The marker cannot be true,false and null (although True,false and null are not Java keywords)

Letters in identifiers are case-sensitive, and hello and hello are different glyphs

2.1.2 Keywords

Keywords are words that have been given a particular meaning in the Java language. You cannot use keywords as identifiers. Here are 50 keywords for Java

Abstract, Assert, Boolean, break, Byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, Final, finally, float, for, Goto, if, implements, import, instanceof, int, interface, long, native, new, package, private, Protect, public, return, short, static, STRICTFP, super, switch, synchronized, this, throws, Transitent, try, void, volatile , while

2.2 Basic data Type 2.2.1 Logical type


2.2.2 Integer type
Serial number Type Range
1 Int

-2 of the 31-time Square of 31 square-1

2 Byte -2 of the 7-time Square of 7 square-1
3 Short -2 of the 15-time Square of 15 square-1
4 Long -2 of the 63-time Square of 63 square-1

2.2.3 Character types

Escape characters:

Serial number Character Meaning
1 \ n Line break
2 \b Backspace
3 \ t Horizontal tabulation
4 \‘ Single quotation marks
5 \" Double quotes
6 \\ Back slash

2.2.4 Floating-point types
Serial number Character Meaning
1 Float A constant must be followed by F or F
2 Double Constants can be followed by D or D

2.2.5 Conversion of basic data types

When the value of a low-level variable is assigned to a variable of high level, the system automatically completes the conversion of the data type

When a variable of high level is assigned to a variable of low level, the display type conversion operation must be used

3 Entering output data from a named row 2.3.1 entering basic type data

Scanner reader = new Scanner (system.in);

Reader.nextdouble ();

2.3.2 Output Basic type data
Serial number Describe Description
1 %d output int type data
2 %c Output Char type data
3 %f Output floating-point data, the fractional part retains up to 6 bits
4 %s Output string data
5 %md output int data, in M-column
6 %m.nf Output floating-point data in M-column, decimal point reserved n-bit

2.4 Array 2.4.1 Declaration array

float boy[];

Char cat[][];

2.4.2 Creating an array

float boy[] = new FLOAT[4];

int mytwo[][] = new int [3][4];

Use of 2.4.4 length for 2.4.3 array elements

float a[]=new float[12];

Initialization of the 2.4.5 array

Float boy[] = {21.3f,23.89f};

2.4.6 references to arrays

Array is a reference type

2.4.7 Presentation format

Arrays.tostring (a);

2.4.8 Copying an array

(1) Arraycopy method

(2) copyof and Copyofrange

2.4.9 sorting and two-point search


2.5 Enum Types

Enum season{

Spring, summer, autumn, winter


2 Primitive type arrays and enumeration types--Re-picking Java

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.