One: the basics of grammar
Java Features: Simplicity, object-oriented, distributed, secure, portable, high-performance, multi-threading support
Key words:
Data type: Boolean,byte (1), short (2), char (2), float (4), int (4), double (8), Long (8)
Class-to-interface declaration: Class,extends,implements,interface
Process Control: If.else,switch,do,while,case,break,continue,return,default,for
Exception handling: Try,catch,finally,throw,throws,
Modifier: Static (only one of the programs, regardless of how many objects are created) Abstract,final,private,public,protected,transient,volatile
Others: New,instanceof,this,super,void,assert,enum
Operator:
a++ is the latter self-increment; ++a is the first self-increment;
Identifier:
Java legal identifiers are a bit different from C, and Java identifiers consist of numbers, letters and underscores (_), Dollar signs ($), or renminbi symbols (¥), and they also require that the first digit cannot be a number
II: Classes and objects
Construction method: In a class that has an inheritance relationship, the constructor of the parent class must be called First, and then the constructor of the child class is called.
Common methods
static method:
Abstract method:
Override of Method:
Overload:
This reference: cannot be used in main ()
Super Keyword: Calls the constructor of the parent class and cannot be used in main ()
Abstract classes and Interfaces:
1: A class containing abstract methods must be declared abstract Class 2 abstract class not all methods are abstract methods 3 subclasses of an abstract class must implement all the abstract methods of the parent class to instantiate the 4 abstract class cannot be instantiated
1: Implement interface must implement all methods of interface
Difference: If a drawing of all the methods in the class is abstract, and the data members in the abstract class are final constants, then this abstract class is an interface.
All methods in an interface are abstract, whereas abstract classes can define common methods with method bodies, and methods in interfaces are public abstract by default, and member variables are public static constants by default.
1 //interfaces, all of which are abstract methods2 Public InterfaceA () {3 intI=1;//equivalent to public static fianl int i = 1;4 Public voidStrat ();//equivalent to public abstract void Strat ();5 Public voidStop ();//equivalent to public abstract void Stop ();6 }7 //abstract classes, not all methods are abstract methods8 Public AbstractB () {9 Public voidStrat () {TenSystem.out.println ("This is a method of abstract classes"); One } A Abstract voidrun (); -}
Three: Java Common classes
Object class:
Equals () method: Determines whether two references point to the same object, while "= =" is used to compare two objects for equality, both of which can be basic types, or they can be reference types that return TRUE or false
Hashcode () Method: Returns the hash code value of an object
ToString () Method:
Packing class:
Regular Expressions:
Four: New features of the Java language
Enum: enum
Note: (A good programmer must write his own notes)
LAMDBA expression:
V: Containers and generics
Container (this part is closely related to the data structure and does not explain too much)
List List = new ArrayList ();//??? Can you do that in turn?
Generic type:
VI: Exception handling
Seven: IO stream
Borrow this picture to understand better
1: If it is audio files, pictures, songs, with the word throttle better, if it is related to Chinese (text), with a character stream better.
2: Input and output for the console, each stream (byte Fileinputstream,fileoutputstream, character Filereader,filewriter) corresponds to a file
3: General common link flow is used to wrap the stream in 2 multiple times during operation
Byte throttle Wrapper buffer stream: Bufferinputstream,bufferoutputstream
Character Stream wrapper buffer stream: Bufferreader,bufferwriter
4: Conversion stream:
The problem of Chinese characters in actual development through inputstreamreader,outputstreamwriter, in fact, through byte[] and string, is actually caused by the non-unification between character stream and byte stream.
Eight: Multithreading
There are two ways of creating a thread:
Inherit the thread class: The user's threading class simply inherits the thread class and overrides its run () method to start the user thread by invoking the start () method of the user thread class
1 classMyThreadextendsthread{2 Public voidrun () {3 4 }5 }6 7 Public classtestthread{8 Public Static voidMain (string[] args) {9MyThread thread =NewMyThread ();//Create a user thread objectTenThread.Start ();//start the user thread OneThread.run ();//The main thread calls the run () method of the user thread object A } -}
Implement Runnable Interface: When you create a thread object using the thread (Runnable thread), you must pass an object that implements the Runnable interface for the method, so that the created thread will call the run () method of the object that implements the Runnable interface
1 Public classtestthread{2 Public Static voidMain (string[] args) {3Mythread MT =NewMythread ();4Thread T =NewThread (MT);//Create a user thread5T.start ();//start the user thread6 }7 }8 classMythreadImplementsrunnable{9 Public voidrun () {Ten One } A}
IX: AWT and Swing components
Common components: JButton (Button), JTextField (text box), Jcheckbox (check box), Jradiobutton (radio button Buttonground.add (JRB) ~ ~ ~), JList (l list box)
Menu components: JMenuBar (menu bar), JPopupMenu (pop-up menu), JTabbedPane (tab panel), JToolBar (toolbar)
Data Management components: JTable (table), JTree (tree view)
Other:
Common Basic Operating questions:
Seeking least common multiple and greatest common divisor
1 Public classcommonmultiply{2 3 Public Static voidMain (string[] args) {4 5Scanner input =NewScanner (system.in);6 intM,n,r,gcd,lcm=0;7m=input.nextint ();8n=input.nextint ();9Lcm=m*n;Ten while((r=m%n)!=0){ Onem=N; An=R; - } -GCD =N; thelcm=lcm/gcd; -System.out.println ("Greatest common divisor:" +gcd); -SYSTEM.OUT.PRINTLN ("Least common multiple:" +LCM); - + } -}
Javase Basic Knowledge