Java10eclipse shortcut key Supplement
L Check Class Ctrl T inheritance tree
L Ctrl or F3 view Source polymorphism jumps to the calling parent class
All classes in the Lang package in Java do not need to be directed to the package directly such as System String
L ECPLISE the JRE System Library is the default Eclipse dependent JRE class library where you can find the usual string class random class math class
L JDK includes JRE and development tools, JRE includes JVM and core class library required by runtime
L Run HelloWorld run this class and run the core class library such as the System class
RT has the. class file of the core class that is normally used.
Documentation comments and authoring in Java
- In order to allow users to understand the meaning of the program
- Document comments
- /** the document comment for the ENTER key class
Author
Functions of the class
@ Tag Author version
- Document Comment for method
/** Enter
Function
Parameters
return value
- Note In the source code, the class file does not have comments need to use tools to change the note to manual
- Javadoc.exe
- Usage in eclipse
export-java-javadoc-Select the package to which you want to play instructions-finsh
Find Index Click
Note must be written on the bottom or top of the auto-generated
Build Jar Package
- How to use a class or multiple classes
- Make a jar package
- Jar.exe
- Export-java-jar file– Select the package you want to play-finish
- There are only. class files
- It's not easy to change the operation directly in path.
- New system Variable Java_home
- Directory with path to JDK
- Add%java_home%\bin in Path;
Java_home Configuration
Percent of a reference
Importing JAR Packages
L Command Line Import
L set Classpath tell the JVM which path to look for to run the class
L Set Classpath
• How Eclipse Imports Jar packages
new-floder-lib-copy jar package into Lib--right-Buildpath-add to BuildPath
Same as using command line settings
Permission modifiers in a class
Public access modifier class method member variable
L Protected Access method member variables in protected access subclasses
L Default Access to class method member variables
L Private Access Method member variable
L static Modifier method member variable
L Final Modifier class method member variable local variable
L Abstract Modifier class method
L Abstract and private cannot be used simultaneously
L Abstract and static cannot be used simultaneously
L Abstract and final cannot be used simultaneously
The most common type of L-modifier is public
L Modify member variables the most common is private
L Construction method Most common is public
L member methods are most commonly public static abstract
Design analysis of local variables and member variables
L Use member variables to calculate the area and perimeter of a rectangle if it is a property of a thing
l Use local variables to calculate the product and sum of two numbers if it is a property of the function method of a thing
L define static methods without using non-static variables
Class as the parameter and return value of a method
L as a parameter of a method
- Write in the parameter list of the method
- Use a reference variable of a class to invoke a method
- An object has two variables to point to the most common object parameters
- Anonymous objects as parameters
L as the return value of the method
- Generic Object as Parameter
- Anonymous objects as parameters
Abstract types as parameters and return values of methods
L as a parameter of a method
- Abstract class as parameter no object
- An object instance that actually passes a subclass
- The method that is called is the subclass implementation of the method
- Scalability of multi-state calls that can pass multiple-seed objects
L as the return value of the method
- Abstract class changed to be abstract class as return value void
- No object can return only the object of the child class
- The received type should be an abstract class type
- But the disadvantage is that you don't know which subclass of the object is returned
- You can add a parameter to the method and then add an IF condition clause to choose which subclass object to return.
interface as the parameter and return value of a method
L as a parameter of a method
- An object instance of the implementation class is passed
- The implementation of the implementation class is also called
- Polymorphic transitive sub-class objects can also be
- Calling constants in an interface
A) can be called directly with the interface name
L as the return value of the method
- The return is also the invocation of the object polymorphism of the implementation class
- The type of interface is also received
- Methods to invoke the implementation class
- Many of the interface objects in the API are obtained using GET, not the new one.
- Simplifies the code for callers
- Calendar class
Abstract class as a return value case for a method
A) is an abstract class
b) Guide Pack util
c) Re-abstract method of known subclass
d) Direct inheritance using non-abstract methods
e) Static Get method to get Calendar subclass Object
F
G
h) Do not need to know what subclasses are
Five-star hotel case
- Introduced
A) a manager (special bonus) of more than one employee in the hotel a chef two waiter
b) VIP Service
c) Invoke employee function
d) Call the VIP service
L Analysis
- Employee Class Generic Parent class
- Chef Waiter Manager (special bonus) each of the characteristics of sub-categories
- VIP Service Extra Method interface
- Hotel user test class
Summarize
L modifier
When you define it, you use it.
Class public
The inner class can be used as a member
This class often refers to external classes
Member Private
Method public
L Custom data types as return values and parameters
Class
Abstract class
Interface
API Introduction
- Sun's good
- You don't usually need to know how to do that.
- You know how to use it.
- Src.zip source File
- Can view the source code
- API documentation
- How to find
Package String Java.lang
Show Button Index
Common classes for object classes
- All classes are his subclasses.
- Construction method Object ();
- Whether the interface inherits object
Whether
Interface does not have constructors that do not have access to the object class
Equals () method
A) One of the methods in the object class
b) is used to compare whether it is equal to this object
c) The method form parameter is an object type so all types can be arguments
d) All classes inherit the object class, so objects of any class can call the Equals method to use the
e) Non-static method
f) The return value is a Boolean value
g) Compare Memory graphs
I. This is the method caller
Ii. obj represents the object being compared
III. The object class is the memory address of the top-level class whose reference variable can point to an instance object of any class
Iv. = = Compare addresses of two object memory
V. Result of false return to method call
VI. Meaningless because two object memory addresses are definitely different. No comparability
L override equals
- Comparing object member variables
- This change to This.age
- Obj cannot invoke the unique properties of the passed object directly.
Because object obj= another object to be polymorphic, the parent class cannot invoke the subclass-specific property
- So you need to change down to the type of another object to call
- Disadvantages:
Only the corresponding object can be passed if another type, such as an array, throws an exception or an error
- Therefore, it is necessary to determine whether the corresponding object type instanceof
- In addition, non-null judgments are required to return false and the same object to be judged to return true
ToString Method
L The return value is of type string
The ToString method of the default call object when the output statement outputs an object
L System.out.println (object P); and System.out.println (object p.tostring); memory address of the same output object
L Overriding method ToString
- Returns the member variable of an object
- The object that prints the random class is an address that prints the object of the scanner class, not the address
- Because scanner overrides the ToString method
- Concepts and Features
- Characteristics
String class
All objects
A string is a thing and an object.
A class is a string class that describes a thing.
- There are many ways to manipulate strings
- All "" are a String class object
- String str = "DDD"
String class Name
Variables of the STR reference type
"" is an object instance
No new
Print STR also does not print out an address because it is also a string class that rewrites the ToString
- STRING constant
- A string is a constant that cannot be changed
- A string object is invariant instead of a reference type variable that can be repeatedly assigned to a reference type variable
- Memory diagram
A string is an object
Run at the time of heap memory
Essence is an array of characters
"ABCD" Equals char value[]={a,,b,c,d}
The private final char value [] in the String class;
So it's constant.
- Memory diagram
- Main method into the stack
- Defining the STR constant ABCD
- There is a constant pool in the fallback memory
- There are many constants in a constant pool
There are 52 types of character constants
When you need a itacat, take it out of the constant pool.
Essence is a character array str points to the character array space address because the ToString method is overridden to output the Itcast
If you create a new str variable =ABCDE then it will re-open a char array memory, re-point to a new array memory address, the output will change
- How to create
- String Str1=new string ("abc");
- String Str2=new string ("abc");
- Str1==str2
- Str1.equal (STR2)
- Memory diagram
- String Str1=new string ("abc");
Two new objects created
One is the new String ();
One is the character array value[]
New String holds the memory address of value[]
So the output is ABC.
- String Str2=new string ("abc");
Detects if an ABC array has detected a memory address that is directly pointing to the value array
So the output str1==str2 is output true because the address is the same
and. equals because the parent string overrides the Equals method to compare each character in the string, rather than comparing the address
- String Class construction method
- String (byte[] bytes)
A) specify a byte array by using the platform's default character set to construct a new string
b) Chinese operating system default encoding table is GBK
c) queries the elements in the defined byte array into the encoded table and constructs a new string
D) If it is a negative query GBK two bytes of a kanji
- String (byte[] bytes,int offset,int length)
A) is preceded by a byte array of the truncated range of an int representing the starting index one representing the number of intercepts
- String (char[] value) {};
A) parameters that convert a character array to a string character array do not query the encoding table
- String (char[] value,int offset.int count)
A) preceded by an array of characters to intercept the range of an int representing the starting index one representing the number of intercepts
- String ("")
- Find functionality for the String class
- Length (); Returns the length of an int string
- Get partial string
a) substring (int beginindex,int endindex)
b) Start index and end index contain header does not contain trailer
c) Returns a new string that needs to be re-received by the variable
d) The preceding index must be greater than the following index
e) substring (int beginindex), including all the back of the head
- Startwith (String prefix);
Tests whether a string starts with the specified prefix string
Returns a Boolean value
- Endwith (String prefix);
Tests whether a string is a suffix of a string
Returns a Boolean value
- Contains (String XXX)
Determines whether a string contains another string
- indexof (Char ch)
Finds one character, the first occurrence of an index in another character
Return-1 means no
- GetBytes ()
To convert a string into a byte array
Function and construction method opposite
Returns an array of bytes
Inside the array is the corresponding query code table
- Chartat (int index)
Returns the characters on the index
- ToCharArray ()
To convert a string into a character array
Function and construction method opposite
Returns a character array
Do not query the encoding table
- Equals ()
is the same
Equalsignorecase (String s)
Whether the same ignores case
- Practice
StringBuffer class
1. Concept
- string buffers Improve string efficiency
- Internal is a variable array class within the parent class that defines a byte array of char arrays without final
- The default capacity is 16 characters
- String immutable One "" represents an array and then a new array consumes resources
- StringBuffer can be enlarged
- Default capacity by constructor call parent class constructor method pass 16 Create default array
2. Methods
- Append (type variable name)
A) You can add any type of variable
b) The return value is StringBuffer
StringBuffer buffer=new StringBuffer ();
Buffer.append (6);
SYSTEM.OUT.PRINTLN (buffer);
C) Append method source code is to return this;
Who calls append on who to return
Buffer.append (6). Append ("2522");
Method call Chain
- Delete (int start,int end)
A) Delete the character header of the specified index interval without wrapping the tail
b) return to StringBuffer
c) Remove all 0 to length
- Insert (int index, any type)
Add any type of data to the specified location
A) can not be more than two people
- replace (int start,int end,string str)
The string header in the replacement range does not wrap the tail
- Reverse ();
To flip a character in a buffer
- Tostring
Inherit the ToString method overridden by the object class
Convert a mutable buffer object to an immutable string object
StringBuilder
L provide an API that is compatible with StringBuffer
L different
StringBuilder thread is not safe to run fast
StringBuffer Thread safety runs slowly
So it is better to use StringBuilder when using single thread
Practice
Change the array output format to "2,1,2"
The Java self-study road-DAY10