Dark Horse programmer _java Basic knowledge

Source: Internet
Author: User
Tags arithmetic operators array definition bitwise operators

                                    

Basic Java Knowledge

1. DOS command:

Dir: List all files and folders in the current directory

MD: Creating a Directory

RD: Deleting a directory

CD: Enter the designated MUL

Cd\: Return to the root directory

CD: Back to Parent directory

Del: Delete Files

Exit: Exit DOS command line

*: Wildcard characters

Help: Assistance commands

2. Path system variable: The path to the application in your system

How to temporarily configure environment variables: complete with the SET command

Set: information for viewing all environment variables in this machine

Set Variable name: View the value of a specific environment variable

Set Variable name =: Empties the value of a variable

Set Variable name = specific value: Assignment

  Add a new value based on the original environment variable

Set path= new value;%path%;

4. Classpath: Specify where the JVM executes

Set classpath= "Path", first to the specified path, in the current path to find, so do not ";" better.

Set classpath=., "path" first to the current path, and then to the specified path to find

5. The difference between path and classpath

Path is the next Java file running the current path under the current path, and the performer is the Windows

The CLASSPATH implementation is a class file under the current path that runs under a non-current path, and the performer is the JVM

6. Main ()

A, the entrance of the procedure

B, called by the JVM

C, to ensure the independent operation of a class (other classes also have main () can also run)

Comments

1. Special notes in Java:

/** Document Comments */

2. Function:

A. Explanatory notes

B, file debugging

3, note is not through the bytecode file, so annotated Java file compiled size unchanged.

Key words

Characteristics:

Keywords all letters are lowercase

Identifier

1, the name of their own place are identifiers

Composition: 26 Letters in case, numbers: 0-9,_ and &;

Rule: Numbers cannot start

Case sensitive

Cannot use keywords

2. Class/interface

Big HUMP: When there are multiple words, the first letter of each word is capitalized

Method name/variable name

Small hump: When there are multiple words, the first letter is lowercase, the second word is capitalized

Constant

1, the Classification of constants:

A: Literal constants

A: Integer constants

B: The real number (here refers to the decimal) constant
12.5,-65.43
C: Character Constants
' A ', ' a ', ' 0 '
D: String Constants
"Hello"
E: Boolean Constants
True,false
D: null constant: Not type, is a numeric value
Null
B: Custom Constants
(3) Constants can be output directly.

In-process

Convert decimal to other binary:

Divided by the binary, until the quotient is 0, to the remainder

Convert other binary into decimal

number on each digit * binary ^ weights, added

    

Data type

1. Basic data types provided by Java:

Four types of eight types:

Integer: Byte,short,int, Long

Floating point type: float,double

Character type: Char

Boolean Type: Boolean

Reference data type:

Class, interface, array

2, each basic data type occupies the byte and the Representation range

Type Space occupied by Representation Range
Byte 1 bytes -128~127
Short 2 bytes -32768~32767
Int 4 bytes -2^31~2^31-1
Long 8 bytes -2^63~2^63-1
Float 4 bytes -3.403e38~3.403e38
Double 8 bytes -1.798e308~1.798e308
Char 2 bytes 0~65535

Note: The Boolean data type has a bit of packet information, but its size is indeterminate, if it is not to say its size, it is said to be a byte.

  

Integers are exact numbers, and floating-point types are approximate numbers;

Types of conversions

1, when the type of byte, short, char is automatically promoted to int type, the integer default is int, floating-point type is double by default;

Displays the assignment, which can be directly judged at compile time in the data range of the variable. If it is, the compilation succeeds.

BYTE b=100;//succeeded

BYTE b=200;//failed

The display assignment is floating point, then the default must be double accepted. Otherwise the error. If you want to assign a float type, you need to add F.

float f=100.0//failed;

Double f=100.0//Success

Float f=100.0f//Success

2, Boolaen type can not be converted to other data types;

3, for the long variable, the display of the assignment, will first determine whether in the range of int, and then assign a value to long. The reason is the integer default int type. So if the data is too large, it is usually added L or L after the long variable.

Long s=100;//Success

Long s=88888888888;//failed

Operator

1. Arithmetic operators:

+

A, the addition in mathematical sense

B, specify a number as positive

C, you can concatenate strings

Two strings can be added directly

A string directly coupled with a number is the number type that becomes a string in the connection.

A number can be added directly to a string, and the number type becomes a string and then concatenated.

strings are not direct and numeric connections, see arithmetic rules

% modulo operation

Matches the same as the divisor (the first number)

When calculating with floating-point data, HI appears an approximate number

/Divide operations:

Divide two integers to get the integral part of an integer

Divide with fractions, it is in mathematical sense

/and% with floating-point operations it is best not to change the data type

2, Byte b=100;

b+=10;//success. Operators such as +=,-=,*=.%= have one-step hidden casts: b= (Byte) (B+10);

b=b+10;//failure

3. Logical operators:

Short circuit and (&&), short circuit or (| |): In the case of judging the result, it is no longer judged.

4, Bitwise operators:

For the following four kinds of operators:, directly 0 is considered false,1 as true, the law of calculation is the same as the law of logical operators;

& has 0 0;

| There were 1 1;

^ Same fetch 0, different fetch 1;

~ All 1 changes 0,0 to 1;

Move left <<: Moves all the numbers to the specified number of digits, which is the equivalent of multiplying the corresponding binary number

Move right to >>: Contains the movement of the symbol, the front is a few, the left after the vacated bits to fill a few, equivalent to divide by the corresponding number of binary

Unsigned right shift >>>: does not include the movement of symbols, that is, regardless of the preceding is a few, are 0;

5, how to exchange the value of 2 numbers, using the displacement operator

In a displacement operation, the result is the number 2 times the number of different or another number.

int x=10,y=20;

X=x^y;//x=x^y=10^20 y=y=20;

Y=x^y;//x=10^20 y=10^20^20=10;

X=x^y;//x=10^20^10=20 y=10

Process Control of the program

1. Select the structure:

Multiple nesting of IF statements:

Consideration should be given to the problem of boundary merits;

Do not have duplicate parts in each case;

Switch statement:

The variable data type for the parentheses following the switch statement has 6 types: Byte, short, char, int, String, enumeration

When a break is encountered in a switch statement, it jumps out of the loop, otherwise, continues until the switch statement ends, or it encounters a break;

Break put in the end is not recommended to omit, put in front, must have break;

A value must be used in parentheses after the case, and no interval can be used, nor can it be separated by commas;

2. Cyclic structure:

Usage scenarios for different loops:

When you clear the number of loops, you typically do not use the For loop

Use the while loop when the number of cycles is not determined;

Do-while loops are generally not used because of data security issues.

3. The difference between break and continue:

Break is jumping out of this layer loop

Continue is jumping out of the current cycle and into the next loop.

4. Cyclic marking:

Can be in the loop out of a label.

The format is:

Identifier: loop

Using labels, you can jump the break of the inner loop directly into the outer loop. (continue, but less used)

Function

A separate piece of function code block.

The relationship between functions and functions is equal, and they are usually defined directly in a class, unless an inner class is present, otherwise it is not defined inside another function.

Benefits of functions: defining functions to encapsulate functional code and improve code reusability

In a function of the void return value type, return can be omitted or written as a "return;" form.

Overloading of functions:

1. Concept:

The number of arguments differs from the type of the parameter, and the function name must be the same, regardless of the return value type.

2. Precautions:

A, when calling an overloaded function, the function is called according to the type of the parameter

If no exact match type is found, the Kingston type is matched. If not, then an error.

When looking for approximate type matching, the implicit type conversion principle is followed: byte,short,char>long>double

B, the overloads of the function are also the same as the order of the parameters.

C, in function overloading, only the parameter name is different, that is not the overloaded function, they are the same function.

D, judge whether the function is overloaded, only see if the function name is the same, the parameter list is different, and the return value type is independent.

Memory structure

Heap Memory:

Arrays and objects, stored in memory by an instance created by new;

Each entity has a memory address value

The variables in the entity have default initialization values

When an entity is no longer in use, it is reclaimed by the garbage collector at an indeterminate time.

Stack Memory:

Variables defined within a method are local variables

Local variables are in the stack memory, the memory space occupied after use is automatically released

Array

1, the format of the array definition:

data type [] array name ={specific content}; int[] arr={1,3,5,6};

element type [] Array name =new element type {element number or array}; int[] arr=new[13];

element type [] Array name =new element type [] {element 1, element 2, Element 3}; int[] Arr=new int[]{1,24,5};

2, the length of the array: arr.length;

3. Multiple references point to the same object, that is, multiple variables point to the heap memory address of the same instance object. When the instance object is modified by one of the references, the corresponding value is also modified when the other variable accesses the object.

4, the common array definition way:

A, int [] arr=new int[5];//correct, not recommended

B, int arr[]=new int[5];//Correct, strongly not recommended

C, int[] arr=new int[3]{1,2,4}//error. Because the length of the array is specified and the assignment is displayed, different array lengths may appear.

D, int[] arr=new int[];//error. Because you do not specify the length of the array, you do not know how much memory space is opened.

E, int[] arr;//error, because there is no initialization.

Int[] Arr2=null;

System.out.println (ARR2);//correct, arr2 have value, only empty

F, int[] arr=new int[5];

System.out.println (arr[3]);//correct

G, int[] arr=new int[5];

Arr=null;

System.out.println (arr);//correct

SYSTEM.OUT.PRINTLN (null);//Error

H, int[] arr=new int[5];

System.out,println (arr);//Correct, result is an address value

I, string[] str=new string[]{"1", "2", "3"};

System.out.println (arr[3]);//error, array angle label out of bounds exception.

J, int[] arr=new int[5];

Arr=null;

System.out.println (arr[3]);//error, NULL pointer exception

 

Two-dimensional arrays

1. Format:

A, int[][] aarr=new int[3][2];

3 represents how many one-dimensional arrays are in a two-dimensional array, and 2 represents the length of a one-dimensional array.

B, int[][] arr=new int[3][];

System.out.println (arr[1]);//null.

C, int[][] arr=new int{{1,3},{2,4},{5,3}};

2. Precautions:

A, when assigning a value to a one-dimensional array inside a two-dimensional array, this format cannot be used: Arr[1]=new int[] {n};

B, using the first format requires that all one-dimensional arrays have the same length

C. The length of a one-dimensional array in a two-dimensional array can also be traced

Int[][] Arr=new int{{1,3},{4,6},{9,7}};

arr.length=3;

arr[0].length=2;

D, int[] x,y[];//defines a one-dimensional array x and a two-dimensional array y.

SYSTEM.OUT.PRINTLN (x);//error, not initialized

System.out.println (y);//error, not initialized

X=new Int[3];

Y=new int[3][];

E, int[][]arr=new int[][2];//does not specify the length of the two-dimensional array, compilation cannot pass.

Dark Horse programmer _java Basic knowledge

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.