(Copyright statement: self-created works, please refuse to forward! Otherwise, legal responsibility will be pursued.
Main points of knowledge this season:
Eclipse development tool to develop JAVA program
Use of regular expressions
Eclipse: The original meaning is: solar eclipse
JAVA is developed by SUN enterprise. Eclipse was first developed by IBM and later transferred to the eclipse organization. Now it is a completely free development tool that can be downloaded directly from eclipse.org to the latest version. After downloading, unzip it and run it.
There can be multiple JAVA projects in a workspace in eclipse.
Eclipse itself supports the following features:
·JDT: JAVA development environment
Junit: test environment
·CVS client:
Eclipse plug-in development
You can directly choose to create a new JAVA project
create a new class
JAVA naming rules:
Class Title: Capitalize the first letter of each word
Method name: lowercase the first letter of the first word, capitalize the first letter of each subsequent word
Attribute name: the first letter of the first word is lowercase, and the first letter of each subsequent word is uppercase
Constant title: capital letters for each word
·Package name: lowercase letters of all words
Adjust font size
show line number
Test print HelloWorld
In eclipse, you can compile automatically as soon as you keep the file
Create a new Person class for a simple test~
After the class is written, you need to write properties, and after the properties are written, you need to write setter and getter methods. At this time, you can use the function of generating code
The following vivid structure method
Next we write another Math class
Ctrl Shift F: can format code
This Math class is called in the following Demo01
There is a red line under the code to indicate that there is a problem with the code, prompting UnhandledceptiontypeException, you can use Ctrl 1: Correct the code function.
We choose try/catch
run the test
Let's take a look at the debugging function of eclipse
Double click to add breakpoint
Ask if you want to switch to the debug interface, select yes to indicate the switch.
Choose single step filter
Step over: only look at the results, not the operation inside the code
Step into: Enter the code to see the result of the operation.
If we directly choose to step through, we will directly see the result 2
Let's make the Math class code a little more complicated.
Continue to debug this Demo01
Select to step into
Now into the structure method, keep stepping in
Here, enter the Math method and observe the change of its value. The value of i is 10 and the value of j is 5.
The initial value of x is 0
When returnx;, the value of x is 2
We can use the debug function to track the change of the first line of code and each value~
Also included in eclipse is the Junit test tool, which is an open source project and a set of jar packages. We need technology to add these jar packages.
Now let's test the div method in the Math class
TestCase: Indicates a test case
TestSuite: Indicates that multiple test cases are tested together.
Although junit has been integrated in eclipse, the package technology should be added.
This jar package is located in eclipse\plugins
Craftsmanship increases~
Add extension jar
After adding the extension jar package, there is no red line in the program~ It means that this package is accurate~
Let's test it, using TestCase.assertEquals() to test the div() method, which indicates that the test
TestCase.assertEquals(newMath().div(10,5),2);
There is an exception here, we need to catch the exception
run junit tests
There are two well-known flags in Junit:
GreenBar: Indicates that the test results are accurate
· RedBar: Indicates that the test results are inaccurate
Let's verify the effect of 10/5=6
If we set the result to have an error, exaggerate it, the error is 4
At this moment, 10/2=6 will pass the test~
Regular expression:
Since JDK1.4, it has been integrated in JAVA, and a set of Apache components has been used at the earliest. Data is usually validated using regular expressions. Mainly used for strings.
There are three methods in the String class that integrate regular usage:
·publicbooleanmatches(Stringregex);--gt;matched
·publicStringreplaceAll();
·publicStringsplit();--gt;split
Request one:
Request to verify that a string is composed of numbers. If so, display true, otherwise display false
We use regular expressions to do it~
How to indicate the number, if we don't know it, we can detect the str.matches() method
have a test
Now the match is a one-bit string. If you want to match multiple bits, it is assumed that the length of this string is 6~15 bits.
Verification is successful~
Request two:
Verify that a string is composed of letters (a~z, A~Z), and the length is also 6~15 digits
Add this number to the string to verify
This is the basic operation of regular expressions~
Request three:
Verify that a string is not composed of numbers. Assume that the string length is still 6~15 bits.
If the first digit cannot be a number
Request four:
Give a string and request to split according to the number, that is: all numbers are split points, as long as there are numbers, they will be split, so here you can follow a wildcard of length: " "
Wildcards are as follows:
·
: indicates that the length is 0, 1 or more digits
: indicates that the length is 1 or more digits
?: Indicates the length is 1 or 0 digits
In fact, it is used in many programs, and sometimes it is not used to write such code directly, but prefer to replace it with some other content:
\d: indicates a number
·\D: indicates non-digital
·\w: Indicates that it consists of letters, numbers, and underscores
·\W: Indicates that it consists of non-letters, numbers, and underscores
Request five:
Request to determine whether a string is composed of letters, numbers, and underscores
Request Six:
The Replace method also supports regular expressions, for example: replace all numbers in a string with "X".
Regular expressions are often used to split strings and match in program development. For example, websites often need to verify the entered email address.
Request Seven:
Verify email address
Summarize
1. Using eclipse
2. The use of regular expressions (matching, splitting)
################################################## ####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################)