The Java self-study road-day11

Source: Internet
Author: User
Tags arithmetic pow square root time and date

JAVA11 Regular Expressions

L Concept

    1. is a string
    2. Meet a certain rule
    3. QQ number Check

[1-9] [0-9] [4,9]

    1. Check if certain characters are compliant such as whether the user name is compliant
    2. One [] represents one or more characters
    3. It's too complicated to solve some problems with string

L Matching Rules

    1. Character X

A) the content that needs to be matched is a

    1. Character \ \

a) representative \

b) is an escape character

    1. \ t tab
    2. \ n line break add a blank line
    3. \ r carriage return cursor to the header of the next line
    4. [ABC] represents a range of characters
    5. [^ABC] represents the inverse of a range that is not ABC to match
    6. [A-za-z] any one letter
    7. [0-9] any one number
    8. [Z-A-Z _ 0-9] Letter underline and number match
    9. \d Representative Number 0-9
    10. \w the letter underscore and the number match
    11. ^ Represents the beginning of the line

A) ^[abc][0-9]$ needs to match the content starting from [ABC] this position is equivalent to the left double quotation mark

    1. $ represents the end of the line

A) ^[abc][0-9]$ need to match the content to end with [0-9] This position equivalent to the right double quotation mark

    1. \b Word boundaries

Requires a non-word character alphanumeric underscore on both sides of a character

    1. X? Represents x once or once or no
    2. X * Represents 0 or more occurrences
    3. X + represents one or more occurrences
    4. X{n} represents n times
    5. X{n,} represents the presence of at least n times
    6. X{n,m} represents the presence of at least n times but not exceeding m times

L Use

    1. Matches of the String class

The return value is a Boolean

"ABC". Matches ("[A]")

    1. Method of the String class split

Return value is string[]

Use a rule to cut a string

"ABC". Split ("a");

    1. Method ReplaceAll of the String class

The return value is a string

Change strings by rule

"Abc0123". Reaplceall ("[\\d]", "#")

Replace all numbers with #

    1. “ . ” Represents any character
    2. "\\d+" integer
    3. "\\d+\\.\\d+" positive decimals
    4. "-\\d+" negative integer
    5. "-\\d+\\.\\d+" negative decimals
    6. "\\d+\\.\d{2}" retains a positive number of two decimal places
    7. "\\d+\\.\d{1,3}" retains a positive number of 1-3 decimal places
Date class

L Overview

    1. Represents a specific moment accurate to milliseconds
    2. To implement the interface
    3. Existing sub-classes
    4. Package name is Java.util.Date
    5. Milliseconds 1000 milliseconds = 1 seconds
    6. long time=System. Currenttimemillis ();
    7. returns a long type because the range of int is exceeded
    8. Time Origin 0 AD January 1, 1970 Midnight 0:00:00:
    9. Time and date calculations must depend on the millisecond value

L Construction Method

    1. Obsolete from jdk1.1 replaced by calendar class
    2. except date (); Date (long date)
    3. The date () output is not an object address description overriding the ToString method

Sat Jul 10:58:26 CST 2017 time in current operating system

    1. Date (long date)

Pass a millisecond value

into a date with 0 points added

    1. Date Get Set method

GetTime () converts a date to a millisecond value long time=system.currenttimemillis () can also

SetTime () Converts a millisecond value to a date construction method or

L Date Formatting

    1. DateFormat
    2. Abstract class for date formatting
    3. Java.text Bag
    4. Both abstract and non-abstract methods have
    5. SimpleDateFormat subclasses can implement abstract methods directly using non-abstract methods
    6. Create a SimpleDateFormat object

Write date format in construction method

YYYY year

MM Month

Days in DD month

HH 0-23 hrs

Minutes in mm hours

SS sec

New SimpleDateFormat ("A.D. yyyy mm month DD Day m minutes ss seconds");

Chinese characters can be written, but letters must be written as required.

Then call the format () method to return a value that is a string parameter that is a date

L string converted to date object

    1. Parse method
    2. Steps

A) Create a SimpleDateFormat object

b) Construction method Specify date format

c) Subclass object Invocation Method Parse pass string returns date

d) The string date in parse must be the same as the specified format

e) Date cannot be entered only select

Calendar

L Concept

    1. Replaced the date method
    2. A subclass implementation is required for an abstract class that cannot create an object
    3. static method static variable year calendar field
    4. GetInstance () Gets the child class object

L Get Gets the value of the Calendar field

Get (int)

parameter int gets the specific value of which calendar field

Returns an int value

int year=calendar.get (calendar. year);

Year

Months month

Days Date_of_mouth

L Set (int field,int value)

Set Calendar Field specific values

Set (int year,int month,int Day)

The month and day of passing 3 integers

The foreign months are less than the domestic month

L Add (int field, int offset)

The offset of the calendar can specify which one of the fields in the calendar, the offset of the whole number

L GetTime () not used

Convert a Calendar object to a Date object

Practice

L've lived many years.

L Leap Year

    1. Assign calendar to March 1, add offset Day 29 leap year 28 common year

L Java Calendar

Packaging class overview
    1. There are eight types of mathematical calculations for the basic type
    2. Basic types do not need to be expanded for complex operation functions
    3. The wrapper class solves this problem.
    4. Any data entered by the user from the interface is stored as a string
    5. Operations on these strings can only be performed on string operations that cannot be converted to basic type completion operations
    6. Java provides eight basic types of wrapper classes

A basic type is encapsulated in each class to manipulate more data

Except that int is Iteger char is character the other is the first letter capitalized

    1. The main learning integer, the other classes and the same as the integer class
    2. In the Java.lang package
Characteristics

L parseint (String a)

    1. Switch between a basic data type and a string
    2. parseint (String a)
    3. Resolves a string to a signed int integer
    4. You can only write numbers and no spaces.

L parseint (String s,int Radix)

    1. Convert other binary numbers to decimal
    2. The preceding binary number and the back of the system must correspond
    3. Can write abcdef 16 binary

L Change the base type to a string

    1. Data type variable + ""
    2. Integer static Method ToString
    3. ToString (String s,int radix) to specify the input output up to 36 binary 0-9 A-Z

L Construction Method

    1. Integer (string s) creates a Interger object that contains a string
    2. Non-static method Intvalue () returns the int type to convert this string to the base data type

L Other methods

    1. Three methods and two static member variables
    2. Max_value base data Type value maximum
    3. Min_alue basic Data Type value minimum value
    4. tobinarstring (int) decimal into binary returns string
    5. tooctalstring (int) decimal to octal
    6. tohexstring (int) decimal to hexadecimal
Auto-boxing and automatic unpacking

L jdk1.5 After

Data type becomes object auto-boxing

The data in the object changes back to the base data type auto-unpacking

L Automatic Packing

    1. Integer in=1;

After printing for string 1

For example, collection arraylist<integer> can store 1

    1. In=in+1

In first In.invalue () to basic type

Then in+1

After in is converted to wrapper class

L Disadvantages

Null pointer exception

If in is null, the compilation is correct, but the operation will be wrong.

L Practice

System class

L Java.lang Bag

L Final Class

L Construction Methods Private outsiders cannot directly create objects

L can access static methods with the class name

L method

    1. Currenttimemills ()

A) Get current system time

b) can be called once before and after the program is run for statistical program execution time

    1. Exit ()

A) The virtual machine quits and then stops running the program

b) exit the virtual machine

c) Use the parameter as status code 0 to indicate a normal termination of 1 indicates an abnormal termination

    1. GC ()

A) recycling of waste

b) such as anonymous objects, etc.

c) override the Finalize () method in the object class to output the statement

    1. GetProperties ()

GetProperties (String key)

A) Gets the properties of the current operating system

b) Returns a class in the Properties collection similar to ArrayList

c) Output GetProperties () to get all the information

d) file.separator System file location symbols such as Windows \ Unix

Is

    1. ArrayCopy

A) The principle of variable group Arratlist StringBuffer is used in this

b) The source code is not

c) Copy Replacement

D) is the local method of calling Windows The JVM memory is part of the local method stack and this method runs when it is in the local method stack

Math Class Concepts

• Classes of mathematical calculations

L Tool Class

L square Root logarithmic exponential trigonometric functions

L Java.lang in Bag

L static method

Method

l static int abs (int i)

    1. Get the absolute value of a parameter
    2. Math.Abs (int a)
    3. Floating-point long is available

L static double ceil (double D)

    1. Returns the smallest integer greater than or equal to D
    2. Math.cell ()

L static double floor (double D)

    1. Returns the largest integer less than or equal to D
    2. Math.floor ()

L Static Double pow (double A, double A,)

    1. Returns the B-side of a
    2. Math.pow (2,3) 2 of the 3-time Square

L static double sqrt (double D)

    1. Returns the square root of a double argument
    2. If a negative number-2 will output Nan
    3. Local method

L static double random (double D)

    1. SOURCE Random Class
    2. Returns a random number between a 0.0-1.0
    3. Not recommended for

L Static double round (double D)

    1. Gets the rounding of the parameters takes an integer
    2. How to achieve your own + 0.5 strong turn int in the conversion to double
Arrays Tool Class Concept

L contains the contents of an array of operations

L Java.util

L Include sort Lookup

Method

L static void sort (array)

    1. Sorting arrays in ascending order
    2. Sorting algorithms are optimized for fast sorting

l static int BinarySearch (array, element found)

    1. The binary search method of array
    2. Returns the index of the element that appears in the array
    3. If the element does not exist return is (-insertion point-1)

A) Ensure that the elements are placed in an orderly manner

b)-index-1

L Static String toString (array)

    1. Change an array to a string
    2. and has a certain format
    3. Principle StringBuilder output array in a format previously written
Practice

L Receive input Storage 10 people's scores

L PUT the last three people into a new array

L Returns a new array

L Program Analysis

    1. The main method passes over an array
    2. Sort by using the Sort method

    1. Create a new array
    2. Copy the first three elements of a passed array to a new array with arraycopy
    3. Returns the array
    4. Main receives this array
    5. Output with ToString
    6. You can also use a for loop to traverse the output and remove the first three elements, but it's more troublesome.

BigInteger Concept Introduction

L Long type is the largest integer

L A base type that exceeds a long type cannot be represented

L Become a BigInteger object

L implementation of Big Data operations

L Java.math

Construction method

L can pass byte array integral type has limitations

L Select Pass string to represent an integer of any size

L BigInteger (String s) is an object

Operation

L can carry out arithmetic

    1. Caller arithmetic
    2. Calculation results can only be BigInteger objects

l addition Add (another BigInteger object)

    1. The result is still an object

L subtraction Subtract (another BigInteger object)

The result is still an object

L multiplication Multiply (another BigInteger object)

The result is still an object

L Division Divied (another BigInteger object)

The result is still an object

Bigdeciaml Overview
    1. 0.09+0.01=0.09999999999999

L infinitely close to 0.1

    1. Cause the floating-point number is inaccurate in computer-calculated binary
    2. Super large number floating point arithmetic improves operation Precision
    3. Java.math
Construction method

L Recommended passing parameters with string

l int and double may go out of the unpredictable

Operation

L Plus minus multiply

    1. Addition

A) Add

b) Accurate calculation

    1. Subtraction

A) Subtract

b) Accurate calculation

    1. Multiplication

c) Multiply

d) Accurate calculation

    1. Results

0.1 0.68 101.5

L Division Extraction High Precision

    1. Division Divied
    2. Results

1.301/100

0.01301

1.301/101

Abnormal infinite Non-circulation

    1. Workaround: Reload

A) Retention mode

Read the API documentation

. Round_up up one plus 1

. Round_down truncation

. Round_half_up rounding

. Round_half_down Sishe (greater than 0.5 V) into

The Java self-study road-day11

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.