Java Learning Note (2015.7.20~24)

Source: Internet
Author: User
Tags dateformat

Java Learning Note (2015.7.20~24) Java Learning Note (2015.7.20~24)

Java

    • Java Learning Note (2015.7.20~24)

      • 1, the difference between StringBuffer and StringBuilder:

      • 2. Basic data type packing class

      • 3, date, Calendar, DateFormat and other time-related classes

      • 1. Common type String

      • 2. Regular expressions

      • 3, the common class StringBuffer represents the variable character sequence

      • Unpacking and Packing

      • Application of Packaging class

      • Anonymous inner class

      • Array

      • Day11

      • Day12

      • Day13

      • Day14

Day11
  • The parent class uses a method that is defined by public, and the child class must have access to public

  • Members of private definition can only use their own

  • Overwrite the method can expand permissions, such as Default>public, can not reduce permissions, will error

  • The private method cannot inherit from the quilt class, but it can be called by the parent class's method

  • Declare member variables, add a m before the general name

  • In an abstract class, you can define a constructor method.

  • The abstract method in the interface must be defined as public permission, not write is public

  • Transition up, parent class to child class

  • Similarities and differences between interfaces and abstract classes

  • Familiarity with anonymous internal classes

  • Interfaces are made up of global constants and abstract methods, so

  • String AUTHOR = "Jensen"; equivalent to public static final String AUTHOR = "Jensen";

  • void print (); equivalent to public abstract void print ();

  • String GetInfo (); equivalent to public abstract String getInfo ();

  • Java allows an interface to inherit multiple interfaces:
    Interface sub-interface extends parent interface A, parent interface B, ... { }

  • Object Instanceof Class returns a Boolean type

  • Abstract class Authoring templates

  • Interface Development Standards

  • Design mode Factory mode
    By adding a transition between the interface and the subclass, an instantiated object of the interface is obtained through this transition side, which is generally called the factory class.

  • "Orange". Equals (ClassName) Why write string constants in front of string judgments?
    A: This avoids null-pointing exceptions, such as when an incoming value is null

Array

Arrays can be seen as multiple combinations of the same type of data
Array variable belongs to reference type

One-dimensional arrays
Declaration of an array
Int[] A; It is recommended to use this
Byte[] C;
int b[];
Attention:
Cannot specify its length when declaring an array in the Java language

Initialization
Static initialization
int b[] = new int[]{1,2,3,4,5};//static initialization
Int[] C = {1,2,34,56,7};//static initialization
Dynamic initialization

To take a value from an array according to the subscript: can be an integer constant or an integral type expression
Subscript starting from 0

Print all elements of an array in the console

Each array has a property length that indicates its lengths

Sort:
Bubble Sort Select Sort Insert Sort Hill sort

Sort:
Replace
if (A[i]>=a[j]) {
int temp = A[i];
A[i] = A[j];
A[J] = temp;
}

Two-dimensional arrays
A two-dimensional array can be seen as an array of elements
Statement
Int[][] A
int b[][]
Initialization
int b[][] =
{{1,2},{2,2,3,45,6},{2,3,6,7}};
Int[][] C =
New int[][]{{1,2},{2,2,3,45,6},{2,3,6,7}};

Two-bit array initialization
First initialize the high-dimensional
Int[][] A = {{1,23,4},{1,3,4},{2222}};

DAY12 Unpacking and Packing
int x = 30;integer i = new Integer (x);//boxing int y = I.intvalue ();//Unpacking
Application of Packaging class
    • The most common use of wrapper classes in practice is to make a string into a primitive data type, such as a string of all numbers into an int or float type of data.

String str1 = "30"; String str2 = "30.3"; int x = Integer.parseint (str1); float f = float.parsefloat (STR2);
Anonymous inner class

The interface itself cannot be instantiated directly, so there is a brace after the interface instantiation in which to write the specific implementation method.

Anonymous strings are placed inside data segment

string, Length () method
Object, Length Property

day131, Common class String2, regular expressions
    • Format not to be remembered

    • A period. Represents a single character

    • square brackets [] indicate that a single character may appear in the character set

    • Parentheses () can represent multiple characters

    • Curly Braces {} indicates the number of times

    • Escape character "\"

    • General regular expressions are made up of wildcards and fixed characters

    • Chestnuts:

      • Letter _ number greater than 6 less than 10 bits
        "\w{6,10}"

      • Email: [Email protected]
        "\[email protected]\w+\.\w+"

      • Mobile: Starting at 13 15 18 17 11-bit
        "[1][3578]\d{9}"

Just remember:
Pattern p = pattern.compile ("A*b");
Matcher m = P.matcher ("Aaaaab");
Boolean B = m.matches ();

3, the common class StringBuffer represents the variable character sequence

String
StringBuffer

Reverse ()

Note: StringBuffer default capacity 16;
If the amount of incoming data is greater than the current capacity
StringBuffer capacity will change before the volume + 2

The difference between day141, StringBuffer and StringBuilder:
    • StringBuffer: Synchronization thread security is less efficient

    • StringBuilder: Asynchronous insecure single-threaded high efficiency

2. Basic data type packing class
    • base data Type wrapper class
      boolean boolean
      byte by Te
      char Character
      short Shor T
      int Integer
      long long
      float float
      double double
    • Integer

      • public static int parseint (string s)

      • public static Integer valueOf (string s)

      • java5.0 after the automatic unboxing function, as follows

Integer i = new Integer (+), int j = i + 100;//automatic unpacking int k = 100;integer m = k; Automatic Boxing
    • Character
      Isuppercase (char ch) determines whether a character is uppercase
      Islowercase (char ch) to determine if a character is a lowercase letter
      Isletter (char ch) determines whether a character is a letter
      IsDigit (char ch) determines whether a character is a number

3, date, Calendar, DateFormat and other time-related classes
import java.text.parseexception;import java.text.simpledateformat;import java.util.calendar; import java.util.date;public class test {         Public static void main (String[] args)  {             //  Create date format objects                      SimpleDateFormat format = new  SimpleDateFormat ("yyyy mm month DD Day  HH:MM:SS");                     try {                              date date = format.parse ("November 11, 2011  11:11:11");                              system.out.println (Date.gettime ());              } catch  (parseexception e)  {                   e.printstacktrace ();                       }                      //  Create a Calendar object                       calendar calendar = calendar.getinstance ();                       int  Year = calendar.get (calendar.year);                      system.out.println ("year = "   + year);                      int month = calendar.get (Calendar.month);                       System.out.println ("month = "  +  (month + 1));                     int day =  calendar.get (Calendar.day_of_month);                      system.out.println ("day = "  +  Day);     }   } 

Output Result:
1320981071000//Number of milliseconds from 1970 to that point in time
Year = 2015//print today's date
month = 7
Day = 25

Java Learning Note (2015.7.20~24)

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.