Java certification summary

xiaoxiao2021-03-06  41

Java certification summary

1.Switch (?) Can only be short, int, char, byte. 2.IF (a = "a") compile error, // Assignment IF (a = false) Compile OK, because A = FALSE A represents a boolean value 3. This type of writing Outer.inner i = new outer (). New Inner (); ok! 4. File, 8 default is int, 8.0 default is Double 5. Octa is 0 start, Not O (English O) 6.byte -128 ~ 127, -128 is the binary? 7. -1 >> 32 or -1, -1 >>> 32 Why is it -1? 8.Char C ='c '; STRING S = "S"; S = C; the result is SC !!! 9.Boolean B1 = true; boolean b2 = true; system.out.println (b1 | b2); result is true. Compilation is ohat! 10. What is the default IMPORT package of Java ??????? java.lang. *

Class and objects (Class and Object) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ 0. The outermost class can declare to Final: "$ file a": , However, you can't be private, protected, and static. 1.OverLoad is the same method name, parameter type, order or number of numbers in the same kind. Override is the result of the inheritance of the father and son 2. The return result of the inheritance of the father and son must be the same, otherwise the compilation is wrong :) Override's Modifier can expand, but it cannot be reduced. For example, parent private void test () {} subclats: public void test () {}, no problem; if it is, it is dead! Override throwing exceptions can only throw an abnormal subclass Or do not throw an abnormality 3. Super.super (), rely, wrong, not written. The calling method can use super.method (), but cannot use super.super.method () 4.STATIC and non-Static never notrride! 5. Look at the program class a {void test1 () {hi ();} void Hi () {system.out.println ("Say Hi, A");}}} class aa extends a {void hi () {system.out.println ("Say Hi, AA");}} public class test { Public static void main (string b []) throws exception {a a = new aa (); a.TEST1 ();}} The result is "Say Hi, AA", what? Description, the method always follows the class It turned out to go; but the variables are just the opposite! If two hi () declare to static, "SAY HI, A" is output, because the Static method cannot operate, just hidden. If the parent class's Hi () declares is Private, "Say Hi, A" is output, and the reason is not known, remember is! 6. A non-abstract method, don't want Override to become an abnormality of the subclass of an abstract method 7. The abnormality thrown by the subclass ofoverride can only be a parent class to throw an abnormality class, or there is no! 8. Constructor cannot It is native, final, static, synchronized, can be public, private, nothing, huh, huh 9. Write return in the constructor, but nothing is not allowed, or even null (because it does not return value) 10. The constructor cannot return a value. But if there is a "constructor", it is not tense, it is not a constructor, just a normal function 11.super (); this (); these two functions can only Call in the constructor, and must be in the first line 12. Member variables declare to assign the value than the constructor is also early. INT i = 1; Earlier Test () {} 13. The parameter variable of the method can be Final, no access Control modifier (public, etc.) and static 14.hashcode Returns an int, object's memory address 15.void Wait () throws InterruptException, Wait Throw InterruptException is nothing out 16.java.lang.void is a Void package 17.byte, interger , Double ... All the number of copies related packaging classes are inherited in Numeric

Interface: (Interface) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ 1. All methods of interface are defaults about Abstract (no method) and Non-Static 2. All variables of the interface are default. STATIC, FINAL, so the variable of the interface cannot be changed in its implementation class. 3. Implementation of the interface implementation must throw the same exception with the interface method, which is not the same, this is different from Override! Similar If the interface method does not leave, the implementation method cannot be thrown. 4.Runnable interface There is a Run () method, implementation of the implementation method must declare into public void run () {...} 5. The interface cannot be declared into final, do you have to be implemented? (This is also nonsense: 6. A class implements two interfaces. If the two interfaces have the same method, implement the class to implement this method, no problem. 7. Interface cannot be instantiated, can only be implemented by the class / interface 8. Interface inheritance interface EXTENDS, class implementation interface with imports 9. Interface can only be declared as public or default, and there is a modifier Abstract, you can compile.

Inline Class: (Inner Class) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ 1. Embedding can access any variables of the Outer class, including private 2. Static Inner class, only access to Outer Any Static variable of the class (any static Content can only access static) 3. The embedded category can be Final, Abstract 4. The inline category within the method cannot be static, void test () {static class a {}} xxxxx !!!! 5. The inline category within the method cannot take any modifier. Void test () {public class a {}} xxxxx !!!! 6. The inline category within the method can only access the Final variable in the method, but you can access any variable of the Outer class 7. Anonymous classes do not have a constructor, However, with parameters, it is equivalent to the parameter transmission of the constructor. Class ABC {} class abcd {private abcd (int i) {}} ABC test3 () {Return new abc () {} ABCD test4 () {Return new abcd (3) {};} interface iii {} iii TEST5 () {Return New III () {};} // Class BCD Extends Abcd {} compile error, ) {}; Actually anonymous class inherits ABC. 8. Class a {private a () {system.out.println ("a!");}} Class B Extends a {} is right! B is instantiated, I will actively call the texture of the parent class A, even private, it seems that there is no problem !!! 9. The internal class can have a synchronized method, then the lock is this internal class, with the external class, there is no point; On the problem of lock, the inside and outside is separate. 10. External classes cannot be accessed through this, this should refer to internal classes at this time, and the members of the external class are used directly without adding any qualifiers. 11. How to use this? See: class outr {ion i; class inner {class innerinner {void test () {outer.this.i = 1;}}}} is seen, class name .this. Variable name You can quote i, see it for the first time, hey, lonely. 12. Note that these two ways can be Outer.INNER i = new outer (). New inner (); or, Outer o = new outer (); Outer.inner i = OU.NEW Inner ();

Thread: (Thread) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~ ????? Go see Thread's API !!!! 1. Thread startup must pass start () 2.Run () only Can be public. 3. Thread has priority from 1 to 10, via thread.setPriority (int); can not exceed 10, otherwise run exception 4. Thread priority is 5, name Norm_Priority, is Thread Static variable 5.Thread.yeild (); is a static method, so using the format is thread.yield () or yield (), she is forcing the current process to give up Cup 6.sleep (1000), is a static method, it is Thread sleep for 1 second, then enter the Ready Status Note: Not a state of operation, it also wants to wait for OS to schedule CUP.

Java.lang. *; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ 1. A group of clones: int {1,2}, null}; int}; int} ] = (int [】 []) ia.clone (); 2. What is Nan ????? then CEIL (NAN), Floor (NAN), ... 3.math.floor (-1.1f) ; // - 2.0 math.ceil (-1.1f); // - 1.0 math.Round (-1.6d) // - 2 4.0 = > 正 正 零, negative one, >>> How many digits are -1; 1 << 31 becomes minimum negative number, 1000 .... 0000 11. The maximum positive number is 01111 .... 1111 12. The minimum negative number is 1000 ... .0000 (-2147483648) 13. A InstanceOf B must be a class / interface, not an example

-------- Supplement ------------------------------ 1. Byte, Short, Char all have var = -var; compile errors, because the -var is automatically turned into an int type 2. INT / 0 will throw the ArithmeticException Double, float / 0 INF or -Inf 0 NAN 3. Int ABC; is Variable names that do not meet the naming rules ???? Compile error. 4. CHAR A = '/ u0001'; pair! Char b = / u0001; Compile error! 5. Boolean B1, B2, B3, B4, B5; B1 = B2 == B3; // b1 = (b2 == b3) b1 = b2 == b3 && b4 == b5; // b1 = ((b2 <= b3) && (b4 == b5)); b1 = B2 == b3 == true; // b1 = (B2 == (b3 == True)); b1 = b2 == b3 == b4 is all right! 6. 1 >> 1 is 0 7.% = << = = >> = >>> is a legal symbol 8. --1-10 * 4 This way is correct, that is, (--1) -10 * 4 9. k = 1; K K K; result is 7, equivalent to ( K) (K ) (k) = 2 2 3 10. The label cannot be marked statement. Hi: if (b) {Break Hi; // Break Hi1; No, you can't turn back} // hi1: No, you can't put it before INT i; hi1: i = 1; 11.public static void main (string s []) throws exception {} can be, main can throw out Abnormal 12. Hi: if (b == true) {Break Hi;} Break label, can be used in IF, anything else, including Break, Continue label. 13.int x = i * -j; I rely No problem !!! Compilation is true! Int x = i * j ; this is no problem,

Variable modifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ 1. The outermost layer cannot be declared into protect and PRAVITE 2. You can access between the two instances of the same class. Private methods and private variables with each other! 3. Protect and no modifier specific differences ??????? About outsourcing can access the subclass access to which? 4. When the member variable is modified into final, it must be declare that the initial value is assigned or in the constructor. Getting the initial value, don't expect her to get the default value. 5. Abstract method can be static !!! Native method can't be Abstract 6. Static method will change with the change of the class, see example: Class Parent {static void Test () {System.out.println ("hi, parent")};} class child extends Parent {static void test () {system.out.println ("hi, child")};} Parent P = New child ); p.Test (); // is hi, parent! Static method is not Overrided, just hiding differences in situations (output Hi, Child) without statements (Output Hi, Child) 7. Static method can pass class instance Call. New child (). Test (); and child.test (); all OK! 8.Transient can only be used on a member variable of the class, can't be used in the method 9.Transient variable cannot be Final and Static 10 .native method can be private, final, no method body, can not be Abstract, process control ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. The statement that is not arrived is wrong: while (false) {}; for (; false;) {}; if (false) {} can be compiled 2.FOR (first part ;;) The first portion can be used to declare and assign, such as for (int i = 0; i < 5; I ) 3.Byte B; Switch (b) {case 200: // 200 Not in Range of Byte, because 200 exceeds B range, compiling error 4. Tagged Continue to the label location, from new entry Retrieve the loop 5 behind the label 5. Break with label interrupt the current loop and transfer to the end of the loop of the label.

转载请注明原文地址:https://www.9cbs.com/read-53713.html

New Post(0)