Basic concepts of Java-java programming

Source: Internet
Author: User
Tags java keywords

2017-10-06 15:31:39

First, the basic composition of Java programs

Ii. data types and identifiers

    • Data type

    • Identifier

The generalized set of strings used to define various object names is called identifiers, and identifiers are generally categorized as user-defined identifiers and system identifiers .

# User-defined identifiers

Naming rules:

~ Number cannot be the beginning of the identifier, can be preceded by a letter, an underscore "_" or "$"

~ Cannot have spaces in identifiers

~ Cannot use Java operators, such as "+", "-" and so on

~ Cannot use Java keywords

~ Strictly case-sensitive

# System-specific identifiers

System-specific identifiers, also known as keywords, are the special terms used by the Java compiler itself, and they have specific grammatical meanings. such as: abstract and so on.

    • Constant

A constant is the amount that the value of a program remains constant throughout the course of its operation.

~ Integer constant value has three forms: decimal number, such as 54,-74.

Octal number, in Java, the representation of the octet constant begins with 0, as 0125 represents the decimal 85.

Hexadecimal number, the representation of a hexadecimal constant in Java begins with 0x or 0X, such as 0x100, which represents a decimal 256.

integer int constants account for 32-bit memory by default, and long integer types are 64 bits, represented as numbers followed by L, or L.

~ Real constant values have two forms: the decimal number form, which consists of a number and a decimal point, and must have decimal points, such as 12.34.

Scientific notation, such as 1.75e5 or 326E3, where e or E must be preceded by a number, and the number after E or E must be an integer .

~ character and string constant values: Use single quotation marks for one character, using double quotes as strings.

~ Boolean constant Value: false and True.

~ constants are defined and used: The format is final type constant name = constant value, constant name = constant value;

The general constant names are in uppercase letters, which are defined at the time of declaration.

Maximum and minimum constants for Java integers: type int: integer.max_value,integer.min_value

Long Type: Long.max_value,long.min.value

Float type: float.max_value,float.min_value

Double Type: Double.max_value,double.min_value

Positive Infinity: float.positive_infinity,double.positive_infinity

Negative Infinity: float.negative_infinity,double.negative_infinity

0/0 non-stereotyped: Float.nan,double.nan

    • Variable

~ Integer variable A total of four types of byte (8-bit), short (16-bit), int (32-bit), long (64-bit), Java does not provide any unsigned integer type , which is the difference from C + +.

~ Real variable has float (32-bit) and double (64-bit) type

~ the type bit char (16-bit ) of the character variable, using the Unicode character set .

~ Boolean variable Value concept a total of two types of false,true, accounting for 1 bits.

Member variables in Java have default values, integers and reals are 0,boolean false, and local variables must be self-assigned.

    • Operators and expressions

In Java, the operator C + + is similar to the one in ++,--,+/. And so on

    • Array

In the process of programming to solve real problems, it is often to deal with a large number of the same type of data, and this data to be repeatedly referenced, at this time, the use of arrays such data type is a wise choice.

~ Declaration and use of one-dimensional arrays

Type array name []=new type[number of elements];

You can use the array name. length to get the length value of the array.

There are two main ways to assign an array: Assign a value directly at declaration, type array name []={< array 1>,< array 2>,< array 3> }

A loop can be used if the array element is assigned a regular value.

~ Declaration and use of two-dimensional arrays

Type array name [][]=new type[number of rows elements] [number of column elements], such as int myarray[][]=new int[5][6];

The assignment of two-dimensional array elements can also be done at the time of declaration, for example:

int array[][] = {{20,25,2,4},{2,4,5,6}};

The Declaration and use of a Java multidimensional array is very flexible, and he can allocate memory for each dimension from the highest dimension, and for creating a two-dimensional array, you can use the following more flexible declaration method:

Type arrn[][] = new type[arrnum1][];

Arrn[0] = new TYPE[1];

ARRN[1] = new TYPE[3];

Arrn[arrnum1-1] = new TYPE[8];

~ Copying of arrays

Copy the arr1 array to arr2, you can use System.arraycopy (arr1,0,arr2,0,arr1.lenght) to copy all the elements in arr1 to ARR2, and the subscript starts at 0.

    • String

~ Constant Strings String

The Declaration and initialization of string strings.

String s = "hello,world!";

You can also use a character array to initialize

Char ch[] = {' A ', ' r ', ' t '};

string s = new string (CH);

You can use ' + ' to concatenate strings.

Basic concepts of Java-java programming

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.