JavaSE knowledge details

A knowledge statements .JavaSE
1. Local variables: method belonging to or block. Members of the change: automatic is automatically assigned default initial values belong to [the object]. Static variables: are variables that belong to the class.
2. constant: use to modify final variables. [Final double PI = 3.14;]
3. The basic data types
integer types: byte, short, int, long int [] is the default
decimal type: float, double double] [default
character: char
boolean: boolean
order: (byte, Short, Chart) -> int -> Long -> float -> Double
4. hexadecimal
0: 0 at the beginning is octal 0x: hex is 0b: binary
5.BigDecimal [any floating point operation ], BigInteger any integer precision operation] [
6 important to note operator knowledge.
Bitwise operators: in 0: false, 1: true.
7.Scanner class
common methods:
Scanner Scanner Scanner new new = (the System.in);
String name = scanner.nextLine (); // accept keyboard string
int age = scanner.nextInt (); // accept keyboard integer
8. Math class generates a random number
Math.random (); // generates a random number (0,]
Random rd = new Random (); rd.nextInt (10); // generates a [random number between 0,10).
9.switch
Switch ( "int, enumeration, may be used after jdk1.7 String") {
Case value. 1:
[BREAK];
...
[defalut:
execute statement;]
}
10.while
the while (Boolean expression) {...}
do {...} while (boolean expression)

11. The method of overload
① in the same class in a
② method of the same name
③ in the form of parameters or the number or order of the different types
######################## ################################################## #####
1. class basic concepts and elements contained.
Abstract class is a class of things [in which one of a class of things called objects].
Class contains mainly elements are: attributes and methods.
Properties: Constant member variables,
methods: constructor, abstract methods, general method
2. constructors: [There argument constructor public Studen (int age, String name ) {...} } [constructor with no arguments public Studen () { ...}}
3. static initialization block
format: static {...}
effect: constructor initializes a user object, the static initialization for the class initialization operation.
Static initialization block call sequence, with the same calling sequence constructor.
4. The main point Inherited
① keyword: the extends
② subclasses can obtain all the properties and methods of the parent class (parent class in addition to constructor), but the private properties and methods of the parent class can not be obtained.
③java but is continuing, the interface is multiple inheritance.
④ class does not inherit that they will default to continue the Object class.
The rewriting process
continues occurring in ①
② same method signature
method ③ access rewritable greater than equal access to the parent class
④ return type parent less return type
6.And the equals
= =: the time value of the basic types of time comparison of equality, reference types when comparing the address of equality.
equlas: the object of comparison is the same address.
String comparison using the comparison equals class, String class overrides the equals method because of, compare the contents are the same.
7.supers:
is a direct reference to the parent class, properties and methods of the parent class can be called.
Constructor subclass added default super () to call the parent class constructor;
8. package
using the modifier to achieve: public (all), protected (subclass authority), default (package privileges), private (with a class)
over nine states
used: ① interface implemented or inherited, rewriting method ②, ③ references to parent subclass object to achieve polymorphism.
10.final
①final modified attribute becomes constant ②final modification method is you can not rewrite ③final modified class can not continue the
11 array
once the array is created on ①, its size is not changed. Array is the object.
② array declaration and distribution space int [] ary = new int [ 10];
static initialization: int [] ary = {1,2,3,4,5 };
dynamic initialization: int [] ary = new int [1] ; ary [0] = 10;
traverse the array ③: may traverse with foreach.
################################################## #############################
1. abstract methods and classes
① definitions: abstract class Animal {abstract public void shout ();}
② When there is an abstract class methods, class must be abstract.
③ subclass inherits the abstract class time must implement the abstract methods.
④ abstract classes and ordinary classes, but more than an abstract method.
An abstract class can not be instantiated ⑤

2. Interface {public interface UserInterface {...}}
① interface methods are abstract, the abstract may be omitted. Properties are constants.
② interface multiple inheritance. | Private interface methods do not exist. | implement to achieve the interface, you can implement multiple interfaces.

3. Internal class
① member inner classes [nonstatic inner classes, static inner class]
nonstatic inner classes: [class object to create an internal Outer.Inner inner = new Outer () new Inner ();. ]
Class Outer {
Private int = 10 Age; public void testOuter () {}
class inner {int A = Outer.this.age;}
}
[① not directly accessible outside the class of non-static inner class members. ② nonstatic inner classes can not have static methods, static properties and static initialization block.
Method ③ external static class, static code block can not access the internal non-static classes, including non-static inner classes can not use the defined variables, create an instance.
④ This class can access the property outside of the class directly. ⑤ access attribute] within the outer
static inner classes: [pulic class Outer {static class Inner { } -> equal to class a static property}}
② anonymous inner classes: [new parent class constructor (argument type table) \ implement the interface () {}} // class body
③ partial inner classes: internal class method. Among the limited role of the method.
Copy 4. _ insert and delete elements of the array.
The method of the array copy: System.arraycopy (the src, srcPos, dest, destPos, length);
5. The optimized sequence bubble sort _
int [] = {8,3,2,5,10} ary;
for (int I = 0; I <-ary.length. 1; I ++) {
for (int I = J +. 1; J <ary.length; J ++) {
int TEMP = 0;
IF (ary [I] <ary [J]) {
TEMP ary = [I];
ary [I] = ary [J];
ary [J] = TEMP;
}
}
}
6. The binary search binary search _
int [] ary = {8,3,2,5,10} ; Low int = 0; int = ary.length-HIG. 1; value = int. 3;
the while (Low <= HIG) {
int = MID (HIG Low +) / 2;
if(value
ary [MID]) {return MID;}
IF (value <ary [MID]) +. 1 {Low = MID;}
IF (value> ary [MID]) = {MID-HIG. 1;}
}
##### ################################################## ########################
1. The use of packaging, automatic packing, automatic unpacking.
Integer a = new Integer (3) ; // 3 plastic packaged into the Integer object.
Integer a = Integer.valueOf (30); // packed into the shaping 3 Integer object.
Integer a = Integer.parseInt ( "999" ); // string converted into digital Integer object.
int c = a.intValue (); // packaging turn the base data
① Autoboxing: Integer = 23 is A; A = Integer.valueOf // Integer (23 is);
② automatically unpacking: int b = a; //a.intValue ();
③ create a buffer [-128,127 between cache array, use checks to see if in this array, direct access to the wrapped object, or re-create the wrapper object]
Integer in1 = -128; Integer in2 = -128; [in1 == in2 -> true]
2.StringBuilder, StringBuffer variable string []
①StringBuilder thread-safe, high efficiency. StringBuffer thread-safe, low efficiency.
②append ( ""), Reverse (), setCharAt (. 3, 'G'), INSERT (2, 'O'), Delete (20,23);
3.Calendar [Date type], Date [date classes], DateFormat [date format class]
①Calendar
Calendar Calender the GregorianCalendar new new = (2999,10,9,22,10,50);
calender.get (Calendar.YEAR); // in calendar.get (Calendar.MONTH); // month

 Calendar calender2 = new GregorianCalendar(); //获取今天的日期的Calendar
 calendar2.set(Calendar.YEAR,8012);//设置8012年

 Calendar calender3 = new GregorianCalendar(); //获取今天的日期的Calendar
 calender3.add(Calendar.DATE,100); //日期加100天
 calender3.add(Calendar.YEAR,100); //日期加100年
  
 Date dd4 = calender3.getTime();
 Calendar c = new GregorianCalendar(); 
 c.setTime(new Date());

②Date
a Date d = new new a Date (); // [System.currentTimeMillis () to get the current time]
d.getTime (); // get the current time] [d.afer (d1); // d [d1 is whether behind ]
③SimpleDateFormat [DateFormat is an abstract class]
DateFormat new new DF = the SimpleDateFormat ( "the mM-dd-YYYY HH: mm: SS");
String time = df.format (new new Date (9000)); // switch to the character Date time string
Date date = df.parse ( "2018-02-09 09:00:33 "); // time of the character string converted into a Date
4. filename class using
File f = new File ( "d : \ d.txt "); \ [d: \ t.txt]
f.renameTo (new file (" d: \ t.txt ")); change the file name [System.getProperty (" user.dir "); obtaining the user's current directory]
f.createNewFile (); // create a file
f.exists (): if there is
f.isDirectory (): is a directory
f.lastModified (): last modified
f.length (): Gets the file size
f.getName () : get the file name
f.getAbsolutePath (): Gets the absolute path of the file
f.delete (); delete files.
f.mkdir (): you must have a parent directory to create a subdirectory
f.mkdirs (): You can create a directory directly.
The use substantially enumeration class.
① defined enumeration class: enum {Season SPRING, SUMMER, AUTUMN, WINDER}
② use enumerated classes:
class TestEnum {public static void main (String [] args) {
Season = S Season.SPRING;
Switch (S) {Case SPRING: System.out.println ( ""); BREAK; ...}
}}
################################ ################################################
1. Exception, Error, Throwable relationship among
2. exception handling and custom exception
################################## ##############################################
1.Collection, Map relationship
Collection: {the Set: {} HashSet, List: [the ArrayList, the LinkedList]}
Map: {} the HashMap
2.Collection interfaces, List interfaces, ArrayList conventional method.
①Collection interface methods
c.size (): size | c.isEmpty (): whether the air | c.add ( "HP"): add elements | c.remove (Object o); remove elements
c.clear () : Clear all elements | c.toArray (): turn into object arrays | c.contains ( "Lenovo"): contains an element
②ArrayList class common method (re-ordered)
list01.addAll (list02): a collection of the list02 was added to all elements in list01
list01.removeAll (list02): and the same parts list01 list02 deleted
list01.retainAll (list02): list01 and the same elements are not removed list02 off
list01.containsAll (list02): list02 whether the element collections exist in list01
③List Interface
list.add (int index, E element) : add an element at the specified location | list.remove (2): delete elements 2 position |
list.set (2, "HH"); the element 2 is modified to position "hh" | list.get (2) : obtaining the position of the elements 2 |
list.indexOf (Object O): returns the first occurrence of the element in position, does not return -1
list.lastIndexOf (Object o): returns the last occurrence of the element, does not return -1
3.ArryList underlying source JDK reading
ArrayList] [jdk8 insufficient length when width capacity size: length + (length >>. 1)
4. done manually ArrayList1 (most simplified way, adding generics)
5.LinkedList characteristics [query efficiency is low, high efficiency deletions, threads are not security]
6.Map Interface [HashMap, TreeMap, HashTable]
①HashMap
common methods of HasMap: PUT, size, the putAll, ... isEmpty
the HashMap underlying principle:
deposit: + list [array key-> hashCode () -> Get hash code -> for the algorithm to obtain positions according to the array -> Entry for the memory array (hash, key, value, next ), hash to the same value for the stored list]
taken: key-> hashCode () -> Get array according to an algorithm index- > list to find the corresponding array -> compared to find key values according to call equals ().
Upon reaching 0.75 * length, it will expand 2 times the original. The default size is 16.
[java provides that: two identical content equals () is true, the object must have the same hashCode]
②TreeMap
sort when available, sorted according to key an incremental manner.
Comparable need to implement a custom ordering interface, compareTo (Emp o) {} collation method. [Negative: less than 0: equal to an integer: greater than]

③HashTable
HashMap: thread-safe, high efficiency. Allowing the key or value is null.
HashTable: thread-safe, low efficiency. Do not allow key or value is null.
7.Set Interface
Set interface [not sequential, non-repeatable], List [sequential interfaces, repeatable]
Set {HashSet, TreeSet}
①HashSet: [bottom] is achieved HashMap
②TreeSet: the bottom is actually the TreeMap [,] can be realized sort
8 iterator
iterator traversal List: iterator iter = list.iterator () ; iter.hasNext ();
iterator traversal Set: iterator iter = set.iterator () ; iter.hasNext ();
iterator traversal Map:
mode 1 : Set <Entry <K, V >> set = map.entrySet (); Iterator <Entry <K, V >> iter = set.iterator (); iter.hasNext ();
Second way: Set keySet = map.keySet (); ITER = set.iterator the Iterator (); iter.hasNext ();
9.Collections tools [is Set, List, Map, etc.] filled sort
shuffle (list): a random arrangement of elements in list
reverse (list ): reverse order
Sort (): sorted in ascending
binarySearch (list, "ll") ; binary search using elements
10. The table data store, to map and store the entire table list. [Orm: object-relational mapping. Form each line using Map, the entire table is stored using the List]
###################################### ##########################################

Published 20 original articles · won praise 0 · Views 1211

Guess you like

Origin blog.csdn.net/jinhuding/article/details/104836939