The Java self-study road-DAY10

Source: Internet
Author: User

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
    1. In order to allow users to understand the meaning of the program
    2. Document comments
    3. /** the document comment for the ENTER key class

Author

Functions of the class

@ Tag Author version

    1. Document Comment for method

/** Enter

Function

Parameters

return value

    1. Note In the source code, the class file does not have comments need to use tools to change the note to manual
    2. Javadoc.exe
    3. 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
    1. How to use a class or multiple classes
    2. Make a jar package
    3. Jar.exe
    4. Export-java-jar file– Select the package you want to play-finish

    1. There are only. class files
    2. It's not easy to change the operation directly in path.
    3. New system Variable Java_home
    4. Directory with path to JDK
    5. 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

    1. Write in the parameter list of the method
    2. Use a reference variable of a class to invoke a method
    3. An object has two variables to point to the most common object parameters
    4. Anonymous objects as parameters

L as the return value of the method

    1. Generic Object as Parameter
    2. Anonymous objects as parameters
Abstract types as parameters and return values of methods

L as a parameter of a method

    1. Abstract class as parameter no object
    2. An object instance that actually passes a subclass
    3. The method that is called is the subclass implementation of the method
    4. Scalability of multi-state calls that can pass multiple-seed objects

L as the return value of the method

    1. Abstract class changed to be abstract class as return value void
    2. No object can return only the object of the child class
    3. The received type should be an abstract class type
    4. But the disadvantage is that you don't know which subclass of the object is returned
    5. 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

    1. An object instance of the implementation class is passed
    2. The implementation of the implementation class is also called
    3. Polymorphic transitive sub-class objects can also be
    4. Calling constants in an interface

A) can be called directly with the interface name

L as the return value of the method

    1. The return is also the invocation of the object polymorphism of the implementation class
    2. The type of interface is also received
    3. Methods to invoke the implementation class
    4. Many of the interface objects in the API are obtained using GET, not the new one.
      1. Simplifies the code for callers
      2. 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
    1. 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

    1. Employee Class Generic Parent class
    2. Chef Waiter Manager (special bonus) each of the characteristics of sub-categories
    3. VIP Service Extra Method interface
    4. 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
    1. Sun's good
    2. You don't usually need to know how to do that.
    3. You know how to use it.
    4. Src.zip source File
    5. Can view the source code
    6. API documentation
    7. How to find

Package String Java.lang

Show Button Index

Common classes for object classes

    1. All classes are his subclasses.
    2. Construction method Object ();
    3. 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

    1. Comparing object member variables
    2. This change to This.age
    3. 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

    1. So you need to change down to the type of another object to call
    2. Disadvantages:

Only the corresponding object can be passed if another type, such as an array, throws an exception or an error

    1. Therefore, it is necessary to determine whether the corresponding object type instanceof
    2. 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

    1. Returns the member variable of an object
    2. The object that prints the random class is an address that prints the object of the scanner class, not the address
    3. Because scanner overrides the ToString method
    4. Concepts and Features
      1. Characteristics
String class

All objects

A string is a thing and an object.

A class is a string class that describes a thing.

    1. There are many ways to manipulate strings
    2. All "" are a String class object
    3. 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

    1. STRING constant
      1. A string is a constant that cannot be changed
      2. A string object is invariant instead of a reference type variable that can be repeatedly assigned to a reference type variable
      3. 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.

    1. Memory diagram
      1. Main method into the stack
      2. Defining the STR constant ABCD
      3. There is a constant pool in the fallback memory
      4. 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

    1. How to create
      1. String Str1=new string ("abc");
      2. String Str2=new string ("abc");
      3. Str1==str2
      4. Str1.equal (STR2)
      5. Memory diagram
        1. 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.

    1. 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

    1. String Class construction method
      1. 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

    1. 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

    1. String (char[] value) {};

A) parameters that convert a character array to a string character array do not query the encoding table

    1. 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

    1. String ("")

    1. Find functionality for the String class
      1. Length (); Returns the length of an int string
      2. 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

    1. Startwith (String prefix);

Tests whether a string starts with the specified prefix string

Returns a Boolean value

    1. Endwith (String prefix);

Tests whether a string is a suffix of a string

Returns a Boolean value

    1. Contains (String XXX)

Determines whether a string contains another string

    1. indexof (Char ch)

Finds one character, the first occurrence of an index in another character

Return-1 means no

    1. 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

    1. Chartat (int index)

Returns the characters on the index

    1. ToCharArray ()

To convert a string into a character array

Function and construction method opposite

Returns a character array

Do not query the encoding table

    1. Equals ()

is the same

Equalsignorecase (String s)

Whether the same ignores case

    1. Practice

StringBuffer class

1. Concept

    1. string buffers Improve string efficiency
    2. Internal is a variable array class within the parent class that defines a byte array of char arrays without final
    3. The default capacity is 16 characters
    4. String immutable One "" represents an array and then a new array consumes resources
    5. StringBuffer can be enlarged
    6. Default capacity by constructor call parent class constructor method pass 16 Create default array

2. Methods

    1. 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

    1. 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

    1. Insert (int index, any type)

Add any type of data to the specified location

A) can not be more than two people

    1. replace (int start,int end,string str)

The string header in the replacement range does not wrap the tail

    1. Reverse ();

To flip a character in a buffer

    1. 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

Related Article

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.