JAVA SE Miscellaneous theory

Source: Internet
Author: User
Tags instance method throw exception throwable java se

Concept:
1. Constructor//method is the same as class name, no return value
Class demo{
Public Demo () {
}
}
When new such an object is executed, the constructor
2. Constructor block//no method name, return value, run before constructor
Also called code block, run once for each new
Class demo{
public{
}
}
Class demo{
{}
}
3. Overloading//method is same as class name, no return value, different method of parameter
Class demo{
Public Demo () {
}
Public Demo (int i) {
}
Public Demo (String str) {
}
}
4. Recursion//function calls itself
5. External class name. Internal class name = new External class name (). New internal class name); When other classes refer to internal class names
6. Hash value//memory address
7. Hash table
The table that holds the memory address, in order of the value of the address, when the location is the same but the object is not the same, open a space under this address to store the same object
8. Static//will use a location directly in physical memory at the top level of the runtime
8.1. Static code blocks, which are loaded when the virtual runtime is running, and will only be added once
Class demo{
static{
}
}
8.2. Static methods
When you call a static method externally, you can use the "class name. Method Name" way, or you can use the "object name. Method Name" way.
The instance method has only "object name. Method Name". That is, calling a static method eliminates the need to create an object.
Static methods allow access only to static members (that is, static member variables and static methods) when accessing members of this class.
Instead of accessing instance member variables and instance methods, instance methods do not have this limitation.
public static void demo{}
9. No construction method provided
9.1. Description cannot new object, can think of the method in this class is static
9.2. There are also non-static methods found in this class
9.3. Note that the class will certainly provide methods to obtain this class of objects, and that the method is static, and that the return type is of this type
10 fields
Class name. method//Use of field
Methods in a field are static
11. Documents
Cannot access hidden files
Delete directly, without Recycle Bin
12. Reflection
The information in this class is explored through a class name,
For example, the property name of the class, the modifier of the property name, the method name, the method return value, the method modifier, and so on,
Anyway, except for the method body can not get, the other could be used to get the reflection;
Reflection can also generate an instance of a class, define properties by this instance, invoke methods,
In particular, it is possible to invoke private properties and private methods.

Symbol
1. (a==b) a:b; Equivalent to if (a==b) {a}else{b}
2.&&//With
3.| | Or
4.! Non -
5.>>//Convert a number to a binary right shift? -bit
Without symbols
The width of int is 32 bits
8:
0000 0000 0000 0000 0000 0000 0000 1000
8>>1
0000 0000 0000 0000 0000 0000 0000 1000 binary is 4
I >> n:i/(2^n)
>>>//Turn numbers into binary right? -bit
Right shift with symbol
-7:
1111 1111 1111 1111 1111 1111 1111 1001
-7>>>1:
0111 1111 1111 1111 1111 1111 1111 11,000 binary is 214748364
6.<<//Converting a number to a binary left
I&LT;&LT;N:I * (2^n)
<<<//left shift with symbols

Describe
Abstract//abstraction//No specific description
static//quiescent//function is present in memory
instanceof//Judgment type if (i instanceof int)//i type is int
Implements//implementation, connection interface, (a function implementation interface)
interface//interface, description class, Inside methods are all abstract, open. Variables are all open, static, constant
protected//Access range is sub-class
Private//Can only be this class
Public//Can be subclasses and can be accessed in the same package.

Type
Object//All types
int//integer
Size: 32
Range: -2147483648~2147483648,
Default value: 0
string//Strings
Long//Length shaping
Size: 64
Range: -9233372036854477808~9233372036854477808
Default: 0
float//Float
Size: 32
Range: -3.40292347e+38~3.40292347e+38
Default: 0.0f
Double//Dual precision
Size: 64
Range: -1.79769313486231570e+308~1.79769313486231570e+308
Default: 0.0d
Short//Quick-integer
Size: 16
Range: -32768~32768
Default: 0
Boolean//Boolean type
Size: 1
Range: True/false
Default: False
char//character type
Size: 16
Range: \U0000-U\FFFF
Default: \u0000
byte//byte type
Size: 8
Range: -128~127
Default: 0


Generic type
New features after the JDK1.5 version are used to address security issues and are a security mechanism
More common in collections
Arrylist<string> al = new Arraylist<string> ();
1.< type >//Specify INPUT element type
<String>//Specify INPUT element String type
<?>//ambiguous specific type, placeholder similar to <T> effect
2. Benefits
ClassCastException issues that occur during runtime to compile time to solve problems with programmers
Avoid forced conversion trouble
3. Generic class
When do you define a generic class?
When the reference data type to be manipulated in the class is undefined, the type is defined by the reference party
Early defined object to complete the extension
Now define the generic class to complete the extension
Class utiles<qq>{//qq for custom generics
Private QQ Q;
public void SetObject (QQ q) {
THIS.Q = q;
}
Public QQ GetObject () {
return q;
}
}
utils<student> stu = new utils<student> (); Custom Student Type
But after the explicit type, the following method can only be this type, otherwise you can only create a new class
4. Generic Methods
Higher degrees of freedom than generic methods
Class demo{
Public <T> void Show (T t) {
}
Public <Q> void print (q q) {
}
}
Demo d = new demo ();
D.show ("haha");
D.show (New Integer (4));
D.print ("Heihei");
static method Generics
static method generics do not have access to generics defined on a class
If the application data type for a static method operation is undefined, you can define the generic on the method
Class demo<t>{
public static <w> void Show (T t) {
}
}
5. Limitations of generics
? Wildcard characters, which can also be understood as placeholders
? Extends e: Can receive type E or subtype of e, upper limit
? Super E: Can receive type E or the parent type of E, lower limit

public static void Printcoll (ARRAYLIST&LT;?. extends e> all) {}
public static void Printcoll (ARRAYLIST&LT;? Super E> All) {}


Abnormal
Java.lang.Throwable
Java.lang.Object
Java.lang.Throwable
Exception class, Package
Exception//exception
RuntimeException//Execution exception
Classcastexcepion//Type conversion exception
Checkedexception//Check for exceptions
Except for RuntimeException exceptions,
IOException//i/o Anomalies
FileNotFoundException
Method
Printstacktrace//Output exception information
try{}
catch (Exception e) {
E.printstacktrace (System.out)}//Output error message in console
E.printstacktrace (New PrintStream ("Demo.txt")); Passing error messages to the Demo.txt file
Converting a compile-time exception to a run-time exception
throw new RuntimeException (e)
Handling Exceptions
try{}
catch (Exception e) {}
Throw exception
throw new RuntimeException ("* * *")//Throw exception

Special
...//variable parameters
public void demo (int ... arr) {//usage mode, int can be any type
System.out.println (arr.length); Returns the array length
}
For example:
Demo (1,2,3,4); Demo ();
Demo (12345,123,42,13); Can pass in an int type value of any length
Not available: public void demo (int ... arr, String str) {}//error
Can: public void demo (String str, int ... arr) {}

JAVA SE Miscellaneous theory

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.