No. 02 Day of Java Learning (Language basics: keywords, identifiers, comments, constants, and variables)

Source: Internet
Author: User
Tags binary to decimal modifiers

Java language Base composition

1. Keywords

Refers to some of the words, these words are given a special meaning of Java, it is no longer called the word.

For example:

class   demo{   publicstaticvoid  main (string[] args) {      System.out.println ("Hello world!" );   }}

The class, public, static, void are keywords in

Definitions and features of keywords

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

2. Feature: All the letters in the keyword are lowercase

Keywords to define the data type

Class

Interface

Byte

Shot

Int

Long

Float

Double

Char

Boolean

void

Keywords to define data type values

True

Flase

Null

Keywords to define Process Control

If

Else

Switch

Case

Default

While

Do

For

Break

Continue

Return

Keywords used to define access rights modifiers

Private

Protected

Public

Keywords for defining classes, functions, variable modifiers

Abstract

Final

Static

Synchronized

Keywords used to define the relationship between classes and classes

Extends

Implements

Used to define instance and reference instances, and to determine the keywords

New

This

Super

instanceof

Keywords for exception handling

Try

Catch

Finally

Throw

Throws

Keywords for the package

Package

Import

Other modifier keywords

Native

Stricfp

Transient

Volatile

Assert

2. Identifiers

(1) Some names that are customized in the program

(2) written in 26 English letters, number: 0-9, symbol: _$ composition

(3) Define legal identifier rules

A. Numbers may not begin.

B. Keywords cannot be used.

(4) Strict case sensitivity in Java

(5) Note: In the name, in order to improve the reading, to try to make sense.

(6) Main as the name of the entry function, it is not a keyword, but it is more special, the virtual machine only recognize this function.

3. Notes

(1) For single-line and multiline comments, the annotated text is not interpreted by the JVM (Java Virtual machine).

(2) for the document comment, is a Java-specific note, where the content of the note can be provided by the JDK tool Javadoc, to generate a set of Web files as a description of the program's documentation.

(3) A comment is a good programming habit that a programmer must have.

(4) Beginners to write a program can develop habits, write comments before writing code.

(5) Put your thoughts through the comments first, and then use the code to reflect.

(6) Because the code is merely a form of reflection of thought.

Example:

/*Requirements: Contact a Hello World program ideas: 1. Define a class, because Java programs are defined in the class, Java programs are in the form of classes, the form of a class is actually a byte-code file is finally embodied. 2. Define a main function, in order for the class to run independently. 3. Because you want to demonstrate Hello world, you see the typeface on the console, so you need to use the output statement to complete the steps: 1. Use the class keyword to complete the definition of classes, and a read-strong class name. 2. Main function: public static void Main (string[] args) This is a fixed-format, JVM-aware. 3. Use the output statement: System.out.println ("Hello World"); The code is merely a form of reflection of thought. */classdemo{/*define a main function, in order to ensure the independent operation of the program*/     Public Static voidMain (string[] args) {System.out.println ("Hello world!");//This is an output statement that prints the data in parentheses to the console, where LN can break the line at the end of the data.     }}    

4. Constants and variables

(1) A constant indicates a value that cannot be changed.

The concept of constants:

A. A storage area in memory

B. The region has its own name (variable name, space name found in memory) and type (data type, constraint data type)

C. Data in the region can be constantly changing within the same type of range

Why do you define variables:

It is used to keep constant of the same type, and it is important to use

Use variables Note:

The scope of the variable (a pair of {valid})

Initialize value

To define the format of a variable:

A. Data type variable name = initialization value

B. Note: The format is fixed, remember the format, status quo.

Understanding: Variables are like unknowns in mathematics.

(2) Classification of constants in Java

A. Integer constant, all integers.

B. Decimal constant, all decimals.

C. Boolean (Boolean) constant, more specific, with only two values, true and false.

D. Character constants, which identify a number, letter, or symbol in single quotation marks (' ').

E. String constants, which identify one or more characters in double quotation marks ("").

F. NULL constant, only one value is null.

(3) for integers: There are four forms of expression.

    1. Binary: 0-1, full 2 in 1
    2. Octal: 0-7, full 8 in 1, denoted by the beginning of 0.
    3. Decimal: 0-9, full 10 in 1
    4. Hex: 0-9,a-f, full 16 in 1 is indicated by the beginning of 0x.

(4) Basic conversion of the binary

1byte (bytes) = 8 bits, each called a bit.

A. Decimal Binary Interchange

Decimal is converted to binary divided by 2 to take the remainder

Binary to decimal multiplied by power of 2

For example: 10111011, if the number of binary every 3 bits together (the number of bits is not enough in front of 0), so long became 8 binary. If each of the 4 bits is put together (the number of bits is not 0), then it becomes 16 binary.

Octal number: In fact, it is bits 3 binary units of an octal bit.

Hex: In fact, the binary four bits is a hexadecimal bit.

B. Decimal Octal Interchange

C. Decimal Hexadecimal Interchange

D. Binary representation of negative numbers

The positive number of the corresponding positive binary is reversed, plus 1.

For example: The number 6 corresponds to the binary number is 0000-0110, the inverse (1 to change 0,0 1) after 1111-1001, plus 0000-0001 is 1111-1010.

Any decimal negative number, the highest bit of its binary is 1.

(5) Data type

The Java language is a strongly typed language that defines specific data types for each type of data, and allocates memory space of different sizes in memory.

Data types are divided into basic data types and reference data types.

Basic data type:

A. Numeric type

Integer type: Byte (1 bytes, 8 bit bit,-128--+127), short (shorter shaping, 2 bytes, 32768--+32767), int (4 bytes, 231-231-1), long (length shaping accounted for 8 bytes, -264– 264-1), in general, integers are represented by Int.

Float type: Float (single-precision), double (double-precision)

B. Character type: char (2 bytes, one Chinese is stored using 2 bytes. )

C. Boolean type: Boolean

Reference data type:

A. Classes: Class

B. Interface: interface

C. Arrays: []

(6) Data type conversion

A. Automatic type conversion (also known as implicit type conversion)

B. Coercion of type conversions (also called explicit type conversions)

C. Principle of type conversion

D. When to convert with coercion type

E. The data type of an expression is automatically promoted

All the values of byte, short, and Char will be promoted to the int type.

If an operand is a long type, the calculation is added as long.

If an operand is of type float, the result is a float type.

If an operand is of type double, the result is a double type.

F. Analysis

the difference between System.out.println (' a ') and System.out.println (' a ' +1) int x1 = integer.max_value; The maximum value is 231-1

Teaching Video Address:https://chuanke.baidu.com/v1867921-123914-300152.html

No. 02 Day of Java Learning (Language basics: keywords, identifiers, comments, constants, and variables)

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.