Java Foundation (Fundamental)

Source: Internet
Author: User

Section I. Java Development Environment

1.Linux Operating System

1) Open source operating system, free, mainly as a server operating system,

Java is primarily server-side development, so the deployment environment is Linux

2) The difference between Linux and the Windows directory structure:

2.1) different file systems:

Linux: directory Windows: Drive letter

2.2) External device mapping is different:

Linux: Mount point Windows: drive letter

2.3) Different levels of security:

Linux: High Windows: Low

3) Common Linux commands:

3.1) PWD: Displays the current working directory

3.2) LS: View the contents of the current working directory

3.3) CD: Change the current working directory

Relative path: In relation to the current directory location

.: Current Directory

..: Previous Level Directory

Absolute path: The location relative to the root directory

Start with/

2.java Development Environment:

1) Compile and run the process:

1.1) Compile period:. Java, compiled to generate. Class bytecode files

1.2) Runtime: The JVM loads the. Class and runs the. class

Cross-platform, one-time programming used everywhere

2) noun Explanation:

2.1) Jvm:java Virtual machine

Load the. Class and run the. class

2.2) Jre:java Operating environment

Contains the environment that is necessary to run Java programs in addition to the JVM

Jre=jvm+java System Class Library

2.3) Jdk:java Development Kit

Contains the command tools necessary to develop Java programs in addition to the JRE

Jdk=jre+ compile, run and other tools

Minimum operating environment for JRE, development of minimum environment for JDK

3) Configure Environment variables:

3.1) Java_home: The installation path to the JDK

3.2) CLASSPATH: Represents the search path for a class, as a general shorthand.

3.3) PATH: Point to the bin directory under JDK

3.eclipse:

IBM, open source, free, just unzip

Steps:

1) Create a new Java project/project-----------Community

2) Create a new Java Package------------------building number + unit number

3) Create a new Java class------------------House

Comments: Explanatory text

1) Single-line comment://

2) Multi-line Comment:/* */

3) Documentation Note:/** */

Section II variables and Java basic Types

1. Variables: The number of stored, pronouns, refers to the number of its existence

1) Statement:

int A; Declare a variable of integer type named a

int b,c,d; Declares a variable of three integers named B,c,d

2) Name:

2.1) can contain only letters, numbers, _, and $, and cannot start with a number

2.2) strictly case-sensitive

2.3) cannot use keywords

2.4) can be named in Chinese, but not recommended

Suggestion: "See the name of the meaning", "Hump name Law"

3) Initialization: First time assignment

3.1) Simultaneous initialization of the declaration

int a = 5; Declares an integer variable A and assigns a value of 5

3.2) first declaration after initialization

int A; Declaring an integer variable a

A = 5; Assign a value of 5 to variable a

4) Use:

4.1) The use of the variable is the use of the number it has stored

4.2) The use of variables to match the data type

int a = 3.14; Compilation error, data type mismatch

4.3) variables must be declared and initialized before they are used

System.out.println (m); Compilation error, m not declared

int m;

System.out.println (m); Compilation error, m not initialized

2. Basic data type:

1) int: integer, can only be filled with integers, 4 bytes,-21 billion to 21 multi billion

1.1) Integer Direct quantity defaults to int type, but not over range, compiler error in hyper range

1.2) divide two integers, the result is an integer, the decimal place is unconditionally discarded

1.3) overflow occurs when integer operation is out of range, overflow is required to avoid

2) Long: Length integer, can only be filled with integers, 8 bytes, very large very large

2.1) Long Integer Direct volume requires a number plus L or l

2.2) If the operation is possible overflow, it is recommended to add L after the 1th number, no overflow can not add l

2.3) System.currenttimemillis () to be obtained from

1970.1.1 0 o'clock the number of milliseconds to this moment

3) Double: floating point type, can only be loaded with decimals, 8 bytes, very big very big very big

3.1) floating-point direct amount defaults to double, if you want to indicate that float requires a number plus F or f

3.2) When the double type data participates in the operation, the rounding error occurs, so the precise operation can not be used

4) Boolean: Boolean, 1-byte

4.1) Only values are true and false

5) Char: Character type, 2 bytes

5.1) Char in Java in Unicode encoded format,

One character char corresponds to one code int

The form of the expression is a char character, but essentially the int code is stored

The code can only be between 0 and 65535.

ASCII code: ' A '--97 ' a '--65 ' 0 '--48

5.2) The direct amount of characters must be enclosed in single quotes, with only one

5.3) special characters need to be escaped by \

3. Conversions between basic data types:

The basic data types are from small to large:

Byte,short,int,long,float,double,char,

1) Two types of methods:

1.1) Automatic type conversion: From small type to large type

1.2) Coercion of type conversions: from large types to small types

Syntax: (the type to convert to) variable

Strong turns are likely to overflow or loss of precision

2) Two-point rule:

2.1) Integer direct value can be directly assigned to Byte,short,char,

But not over-range.

2.2) When the Byte,short,char data participates in the operation,

Convert to int before operation

Usage of 4.Scanner:

1) under the package:

Import Java.util.Scanner;

2) in the main () method:

Scanner scan = new Scanner (system.in);

3) below the 2nd step:

System.out.println ("Please enter Age:");

int age = Scan.nextint ();

System.out.println ("Please enter the Unit price:");

Double price = Scan.nextdouble ();

Section III operator expressions and branching loops structure

1. Operators:

1) Arithmetic: +,-, *,/,%,++,--

2) Relationship: >,<,>=,<=,==,!= Boolean

3) Logic: &&,| |,! Boolean

4) Assignment: =,+=,-=,*=,/=,%=

5) String Connection: +

6) condition (trinocular) Operation: Boolean number 1: Number 2

2. Branching structure:

1) If structure: 1 paths

2) If...else structure: 2 roads

3) IF...ELSE If structure: multiple paths

4) Switch...case structure: Multiple paths

Advantages: High efficiency, clear structure

Cons: Integers, equals

If there's no break in case, go straight to the end.

5) Break: Exit switch

Can be achieved with switch, with If...else if all can be implemented

With the If...else if can be achieved, not necessarily can be implemented with a switch

3. A leap year judgment formula:

1) can be divisible by 4, and can not be divisible by 100, or divisible by 400

(year%4==0 && year%100!=0) | | Year%400==0

2) output system Current time

Long startTime = System.currenttimemillis ();

4. Cycle:

1. Looping: Repeatedly executing a code of the same or similar

2. Cyclic three elements:

1) Initialization of cyclic variables

2) Conditions of the loop (based on the cyclic variable)

3) changes in cyclic variables (toward the end of the cycle)

Loop variable: The number of changes in the loop

3. Loop structure:

1) While: first judgment after execution, it is possible not to execute at once

2) Do...while: First execution after judgment, at least once

The 1th element is preferred with the 3rd element

3) for: Highest application rate, fixed number of cycles

4.break: Exit loop

Continue: Skips the remaining statements in the loop body and goes to the next loop

5. Better application of three cycles:

1) while: "When ..." loop

2) Do...while: "Until ..." loop

The 1th element and the 3rd feature are preferred Do...while

3) for: Fixed number of cycles, highest application rate

6. Nested loops:

1) loop in the loop, generally multi-row multi-column when used,

Outer control row, Inner control column

2) Execution rules: Outer loop Walk once, inner layer cycle all times

3) Recommendation: The fewer layers of nesting, the better, can use a layer of two layers

If it has to be over three layers to achieve it, it indicates a design problem.

4) Break can only jump out of a layer of loops

7. program = algorithm + data structure

1) algorithm: process/step for problem Solving (order, branch, Loop)

2) Data structure: How to store numbers in a specific structure

Well-designed data structures can lead to good algorithms

8. Any complex program logic can be achieved through three structures:

1) Sequential structure: From top to bottom, row by line execution, every sentence must go

2) Branching structure: Conditional execution of a statement once, not every sentence must go

3) Loop structure: Conditional execution of a statement multiple times, not every sentence must go

Fourth quarter Array

1 collection of elements of the same data type

2 is a data type (reference type)

3 Definition of the array:

int[] arr = new INT[4];

4 initialization of the array:

int[] arr = new INT[4]; 0,0,0,0

Int[] arr = {1,4,5,8}; 1,4,5,8

int[] arr = new int[]{1,4,5,8}; 1,4,5,8

Int[] arr;

arr = {1,4,5,8}; Compile error

arr = new int[]{1,4,5,8}; That's right

5 access to the array:

5.1) You can get the length of the array by (array name. length)

int[] arr = new INT[5];

System.out.println (arr.length); 5

5.2) access to elements in the array by subscript

Subscript starting from 0, Max to (array. length-1)

int[] arr = new INT[3];

ARR[0] = 100; Assigns a value of 100 to the 1th element in arr

ARR[1] = 200; Assigns a value of 200 to the 2nd element in arr

ARR[2] = 300; Assigns a value of 300 to the 3rd element in arr

ARR[3] = 400; Array subscript out of bounds exception

System.out.println (Arr[arr.length-1]); Output the last element in arr

6 Traversal of the array:

(1) Direct output method

System.out.println (arrays.tostring (arr))

(2) For loop output method

int[] arr = new INT[10];

for (int i=0;i<arr.length;i++) {

Arr[i] = (int) (Math.random () *100);

}

for (int i=0;i<arr.length;i++) {//positive order

System.out.println (Arr[i]);

}

for (int i=arr.length-1;i>=0;i--) {//Reverse

System.out.println (Arr[i]);

}

7 Copying of arrays:

7.1) system.arraycopy (a,1,a1,0,4); Copy the 4 numbers from the 2nd number in the a array to A1, starting with the 1th one.

7.2) int[] A1 = arrays.copyof (a,6);

A = arrays.copyof (a,a.length+1); Expansion

8 Sorting of arrays:

8.1) Arrays.sort (arr); Ascending, high efficiency

8.2) Bubble Sort:

8.2.1) Four count three rounds

8.2.2) Each round starts with a 1th element

Every time, it's more than the next element.

8.2.3) Don't take it out of the game.

for (int i=0;i<arr.length-1;i++) {//Control wheel

for (int j=0;j<arr.length-1-i;j++) {//control secondary

if (Arr[j]>arr[j+1]) {//and its next element is more than

int T=ARR[J]; If satisfied then the Exchange

ARR[J]=ARR[J+1];

arr[j+1]=t;

}

Fifth Quarter method.

1. Methods: Functions, procedures

1) for encapsulating a specific business logic function

2) The method should be as independent as possible, and one way only to do a thing

3) method can be repeatedly called multiple times

4) Reduce code duplication, facilitate program maintenance, facilitate team collaboration development

2. Definition of the method:

Modifier return value type method name (parameter list) {

Method body

}

3. Invocation of the method:

1) No return value: Method name (with reference to the parameter);

2) There is a return value: Data type variable = method name (with reference to the parameter);

Later, you need to use one of the data in the method----have a return value

One of the data in the method is no longer needed in the late--no return value

4.return:

1) return value; 1.1) End method execution 1.2) Returns the result to the caller

2) return; 2.1) End the execution of the method

5. Other

Double c = math.random (); get random number

Double d = math.sqrt (25);//Ask (25) the square heel

Java Foundation (Fundamental)

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.