such as Peng Web Java Training Note 1 (Xiao Wei finishing)

Source: Internet
Author: User
Tags support microsoft

JDK (Java Developmet Kit)

The difference between the JRE (Java RunTime Environment):

The JRE only runs the Java program Environment, does not develop the related tool; jdk=jre+ development-related tools.

Problems with using Notepad to run Java programs:

Programs that can be executed

Class Hello

{

public static void Main (string[] args)

{

System.out.println ("Hello world!");

}

}

Why can't you write your own??

Class Hello

{

public static void Main (string[] args)

{

System.out.println ("such as Peng (www.rupeng.com), welcome you to join!" ");

}

}

Think it should be added in the same file, two class names exactly the same, so did not execute

I try to modify the class name

Class Xiaowei

{

public static void Main (string[] args)

{

System.out.println ("such as Peng (www.rupeng.com), welcome you to join!" ");

}

}

Xiaowei.java (Advanced language), Xiaowei.class (binary code)

Java is a byte-coded file-dependent

Bytecode file (xiaowei.class) binary code, cannot double-click Run, requires Java instruction

Java program runs must be dependent on the Java Runtime Environment (JRE) and cannot be run independently

The JVM in the JRE (the Java virtual Machine,java VM) is the core of the run. Class binary bytecode file.

Why don't you generate the. exe directly??

Because the JVM is responsible for translating the implementation: Compile once, run everywhere. (dealing with different systems) EXE4J package the written program into an. exe file

Programs written in C/s + + are difficult to run across platforms (mainly because Microsoft has a few packaged libraries that only support Microsoft products)

Developing Java programs with eclipse

IDE (integrated development environment): There are many Java Ides: one of the good groups is eclipse free and open source.

Eclipse is just an aid-development tool, and the run of Eclipse and the compiled program run on Java.

What did eclipse do for us?

A: The src of Eclipse stores the source code folder and bin holds the. class file

Eclipse Personalization Settings:

Windows, Preferences, general (Java style)

Practice One:

Workspaces (workspace): Related projects are placed in a workspace that avoids too many projects in one space and is not easy to manage.

Ways to switch workspaces:

Exit restart, if "Use this value as initial value and ask", "File", "Switch workspace (Switch workspace)", select (previously opened) from the workspace list, or the browser selects the workspace root directory (contains. Metadata)

How to import someone else's project into the workspace:

"Import", "Package Explorer", "General", "Existing project to workspace (Existing project Directory)", ". Browse "and" Select the project's root directory (containing the. project file) or workspace, select the imported project.

Comments

1. The commented code compiler ignores.

The role of annotations: Explain the role of the code, add the appropriate comments in the program, and mask the useless code.

2. Use "//" to comment a line of code,//after which the code compiler ignores

3./* * * Comment Multiple lines of code

4. Comments cannot be too many, nor can they be commented at all.

5. Multi-line Comments (/*/) cannot be nested

Application of Annotations:

Key words:

1.Java defines a number of keywords (public, static, void, int), which are used to form the basic Java syntax, and these keywords do not need to be back, while learning, while on the master. These keywords are color purple in the eclipse environment.

2. Goto in C, Const does not make sense in Java, but is still reserved, the names of variables and classes cannot be used in these two, they are also called "Reserved Words".

3. The main, String, System, and so on are not keywords.

Identifier:

1. Identifiers are used to name classes, methods, variables, etc. '

2. Naming rules:

1) by letter (including large, lowercase), Chinese (not recommended), numbers, underscores, $ composition;

2) cannot begin with a number;

3) cannot be a keyword

The 4.java language is case-sensitive: name and name are two different variables.

5. Hump naming method: Capitalize the first letter of each word

6. The identifier should make sense: the naming convention for identifiers is not mandatory, but "unspoken rules"

Class name: Uppercase start;

Variable name, method name: Lowercase start

Variable:

1. The data is usually put in memory. To manipulate memory, use an address, usually a pointer to memory to manipulate memory, and the variable is to access a name within that paragraph. I'm going to tell someone how to use this memory. You need to give this area a name, such as: Price, which is called the variable name.

2. We can change the value of the price variable to 3, 5, 10, but could we change to "Tom"? Obviously it is not possible!!!

So what type of data can be placed in this memory is limited, which is the "variable type".

3. Define a variable in the following format:

(variable type) (variable name) = (initial value)

Scope of the variable:

1. Variables defined within the {} range cannot have duplicate names, define an int b=3;

An int b=10 is defined, and a compilation error occurs.

2.int b=3;b=5; Yes, because it is re-assigned to B.

Note: Use the existing variable B. There is no type before the variable, it is the use of variables;

A variable has a type before it, which is defined as a variable, and the variable cannot be defined repeatedly within scope.

3.int b; then direct println (b); No, because the initial value is not assigned. The local variable must be assigned to the initial value before it is used.

You can assign a value at declaration or use a pre-assignment

Mode one: int a=5; Mode two: int A;

a=5;

Numeric type:

1. Integer type: (based on 32-bit operating system)

Byte (byte) occupies 1 bytes (1*8 bit)

Short (stub) occupies 2 bytes (2*8 bit)

int (integer) (default) occupies 4 bytes (4*8 bit)

Long (length integer) occupies 8 bytes (8*8 bit)

2. Decimal type:

Float (single-precision floating-point number) occupies 4 bytes (4*8 bit)

Double (dual precision floating point number) (default) occupies 8 bytes (8*8 bit)

1 bytes (byte) equals 8 bits (bit)

A 1-bit (bit) can only represent a state of 0 or 1 (that is, a binary)

Under the Eclipse Environment:

Integer Changshime think: int type

Decimal Changshime think: Double type

Note: When choosing a data type, you can save resources by selecting the minimum range type after taking into account the possible extent of the data.

long>int>short>byte;

double>float;

Integer type conversions (type cast):

1. Byte b=3;

int i=b;//implicit type conversion

2.int m=9;

BYTE k=i;

Byte k=m;//cannot be converted from int to byte type

byte k= (byte) m;//an explicit type conversion

Decimal Data type:

Double d1=3.14d;//default to double, so do not write D normally

Double d2=3.14;

Double d3=3;

Float f1=3.14;//cannot be converted from double to float.

The decimal number defaults to double, instead:

float f2=3.14f;

Conclusion:

1. "Large range" = "small range": implicit conversion

2. "Small Range" = "Large Range": explicit conversion (forced type conversion)

3. All integers participate in the multiplication operation, the result is an integer, and the integer constant participates in the multiplication calculation, and the F is declared as the decimal type, avoiding the loss of precision.

eg

System.out.println ((1/3));//0 call in the same type

System.out.println (1.0/3);//1.0 call Double type

System.out.println ((1/3) *3f);//0.0

System.out.println (1/3f);//1.0

Common data types:

1.boolean:true/false (only two selectable values)

Int i=true; is not valid in Java

2.String: "* * * * *"

Escape character: "\ n" line wrapping

"\ \" Output "\" (slash)

"\" "Output" "" (quotation marks)

System.out.println ("My name is called \" Xiao Wei \ "\\n");

How do i display the "\ n" character? You can enter "\\n".

int: Maximum value: integer.max_value;

Minimum value: integer.min_value;

convert int to String:Integer.toString (i);

or for: string.valueof (i);

The string is converted to Int:Integer.parseInt ("33");

An explicit type conversion is limited to integers and decimal types.

Double converts to String:Double.toString (d);

Convert string to double:Double.parseDouble (s);

Char differs from string: Single quotation mark (char type), one character

Double quotation marks (string type), a stack of characters, and the core "+" as the end-of-string flag.

Base operator:

1. Operator is add (+), minus (-), multiply (*), divide (/) and other symbols

2. Calculate the remainder operator (%): 5%4 is 1, 5%5 is 0, 22%7 is 1.

3. Self-increment (+ +): is the self-increment operation of a variable ()

4. Self-reduction (--):

SYSTEM.OUT.PRINTLN ("abc" +5+6);//The result is "ABC56"

"ABC" is a string, so +5 is still a string, and then +6 is still a string

SYSTEM.OUT.PRINTLN (5+6+ "abc");//result is "11ABC"

5+6 is the integer data, the result is 11, and then the string is stitched together

SYSTEM.OUT.PRINTLN ("abc" + (5+6));//The result is "ABC11"

Summarize:

In Java, expressions are scanned from left-to-right, and once a string is encountered, the subsequent operation becomes a string.

Assignment operators:

1. int i=5;

It should be understood as: "Declare the int type variable i, and assign 5 to I".

    1. int x=10;  x=x+5; Therefore: X + + is equivalent to x=x+1;
    2. x+=5; equivalent to x=x+5;
    3. Similar to:-= *=%=, etc.

Extended Knowledge:

When you see "145" This number, you will not think immediately know is "145", but in the computer programmer's opinion, if you learn binary and hexadecimal, it may be more than just a number, but as a number of code.

Usually we use the most is the decimal:

Summed up can summarize the following rules:

① Decimal Use number 0-9

The ② bit is a power of 10:1, 10, 100, 1000, and so on.

③ if the third digit is 100, then two digits can represent the maximum number of 99.

Extended to the general situation:

The number of digits from 0 to (-1) can be represented by the N-bit number. Therefore, a three-digit number can be expressed from 0 to 0 to 999.

The problem of conversion of numeral

1. The commonly used numbering

Decimal 0-9

Octal 0-7

Binary 0-1

Hex 0-f

2. Decimal to each of the binary

Method: Divide by the base to take the remainder inverse

3.2 binary 8 binary 16 decimal

Binary

___________________________

2^3 2^2 2^1 2^0

1 0 0 1 X

=8+ 1 = 9

Octal

———————————

8^1 8^0

1 7

=1*8 + 7*1 = 15

hexadecimal is similar.

4. Binary to hexadecimal octal

Two-turn eight

Three bit a set of results and together

Two-turn 16

Four-bit a group of results are merged together

5. Integer in-memory storage, using a binary

Sign bit

Original code Positive 0

Negative 1

Inverse code positive is the same as the original code

Negative numbers on the basis of the original code, the sign bit is unchanged, the individual bits take the inverse

Positive complement and same source code

Negative number on the basis of anti-code, the sign bit unchanged, the last +1

Case ↓↓↓↓↓↓

————————————————————————————

Original code anti-code complement

5 0000 0101 0000 0101 0000 0101

-5 1000 0101 1111 1010 1111 1011

6. Machine number and truth value

Use the "+","-" plus the absolute value to denote the size of the value, in this form the value is called " truth " in the computer

After the symbol is digitized, the highest bit "0" of the binary number representsa positive sign, and"1" denotes a minus, and the value represented in this form is called " machine number" in the computer. "

Number of machines decimal points implied non-placeholder

Number of machines signed pure integer points after the lowest bit

The pure decimal point precedes the sign bit, the highest bit.

Unsigned pure integer points after the lowest bit

Pure decimal point before the highest bit

7. Storage of decimals

The small number of computers is stored in binary (floating point) format.

The first is a decimal decimal form, converted into a binary calculation case.

————————————————————————————————

0.8125 conversion to Binary

In fact, this situation is who happened to get an exact value.

————————————————————————————————

But for some special cases, that's it.

8. Causes of error in floating-point numbers

There are two conditions, which can cause errors.

1) to save the floating-point number in binary, so some decimal places of the original finite bit, according to the above method operation, may become an infinite loop of decimals.

————————————————————————————————

(decimal)0.9 to 2 binary is infinite loop decimal 0.1110011001100110011 ...

————————————————————————————————

2) The computer has limited precision in saving floating-point numbers, such as float , which retains a valid number of 7 digits (binary bits ) in decimal . Double you can keep the decimal 15~16 bit ( binary the bits) valid numbers. The valid number is ignored.

Why use binary?

The power of the binary can correspond clearly to what the computer expresses. The computer actually doesn't know any letters, numbers, instructions or programs. In its core is just some circuit, at a given node there is either a lot of electricity, or almost no electricity. To keep the logic clear, the engineer simplifies it to "yes" or "no". "Yes" and "no", or "true" and "false" can all be represented by 1 or 0. According to the Convention, 1 means "yes" or "true", but this is only an agreement, so it is equally easy to say "no" or "true".

Computers encode everything they do in 0 and 1 modes. Machine instructions are encoded into a series of 1 and 0, and are translated by a circuit.

such as Peng Web Java Training Note 1 (Xiao Wei finishing)

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.