java primitive types, arrays, and enumerated types

Before you start Tucao about, Xueyibujing, the interview would be disastrous, come out to mix sooner or later have to repay.
Among other things, review the basics from scratch

1, identifiers, and keywords

Meaning: an identifier used to name variables, classes, and methods. Identifier naming specification can improve readability of the program.

Definition: The identifier is in addition to any keyword to channeling a legal letter, underscore, a string of legal letters, numbers, underscores, dollar symbols that begin with a dollar sign.

Reference: alibaba class name specification

2, Keyword

abstract assert boolean break byte case catch char class continue default do double else enum extends final finally float for if implements import
instanceof int interface long native new package private protected return strictfp short static super switch synchronized this throw throws transient try
void volatile while

Java is more common keywords

3, the data type of the script

Java basic data types fall into two categories
basic data types + type reference data
base data type number type = + char (char) + Boolean (boolean)
reference data type = type (class) + interfaces (interface) + Array ( ARRY)
digital type = integer types floating point +
integer type = byte + short + int + long
float = float + double

There are eight kinds of basic data types.

3.1, and a Logic are two types of true to false
int type represents a four-byte integer
type long integer 8 bytes
byte 1 byte integer type
short integer type 2 bytes

3.2, character type
char a character represented by two bytes, rounded 0-65535

3.3, floating point type
float float single precision (32-bit)
Double double double (64) bit
single precision type declarations identifying which should join f

3.3 Basic data type conversion
assignment operator = symbolic
expression to the right assigned to the expression on the left, consistent with the data type requirements of both sides.
Cast data type format is as follows:

(数据类型)变量名或者表达式

Precision type to the type of low precision, accuracy is lost,
how to understand, and the java virtual machine to open up space in memory corresponding species, because of the number of bytes occupied by different types of different lead into other types of time will the occurrence of loss of accuracy and loss of information,

4, the input and output data

4.1, the input data INPUT
the Java JDK classes have special scanner input process data,
scanner java.util.Scanner located in class
constructor:
(. 1) Scanner (File Source)
Constructs a new Scanner, the data source is specified file
(2) Scanner (InputStream source)
Constructs a new Scanner, the data source is specified input stream
(3) Scanner (String source)
Constructs a new Scanner, the data source is specified character channeling
example:
Scanner iNPUT = new new Scanner (the System. in);
to create a scanner object is entered from the keyboard

4.2 Basic data types
Java system classes in JDK
System.out.println ()
System.out.print ()
directly to the output string

% d: Output the data values of type int
% c: char Output Data Type
% f: Output floating-point type data values, bit Reserved 6 mice partially
% s: data output string
% md: int type accounted output column m
% m .nf: floating-point type data output accounted for m columns, n bits after the decimal point.
system.out.println ( ''% d,% f, 12,23.43 ''); system.out.println ( ''% d,% f, 12,23.43 '');

5, an array of
the array is an ordered collection of data

Declare an array
of data type array of array name [];
data type array [] array name;

5.1 create an array of
arrays allocated memory space when the array to use the new keyword description

Name = new Array array type [array length];
MyArry [] = new int [. 4]

Array common methods
package com.company;

public class Test {
public static void main(String args[]){
int i;
int a [] = new int[5];
for(i=0;i<5;i++)
a[i]=i;
for(i=a.length-1;i>=0;i--)
System.out.println(a[i]);
}
}

Guess you like

Origin www.cnblogs.com/qianxiaoruofeng/p/11489830.html