当前位置:网站首页>Summary of abnormal mechanism of interview
Summary of abnormal mechanism of interview
2022-07-03 07:06:00 【L gold p】
.1 Biginteger
1.1 summary
1、Integer Class as int The wrapper class , The maximum integer value that can be stored is 231-1,Long Classes are also finite , The maximum is 263-1. If you want to represent a larger integer , Whether it's basic data types or their wrapper classes There's nothing we can do , Not to mention doing calculations .
2、java.math Bag BigInteger Can represent immutable integers of any precision .BigInteger Provide
all Java The equivalent of the basic integer operator of , And provide java.lang.Math All the relevant methods . in addition ,BigInteger The following operations are also provided : Modular arithmetic 、GCD Calculation 、 Prime number test 、 Prime generation 、 Bit operations and some other operations .
1.2 Common methods
public BigInteger abs(): Back here BigInteger The absolute value of BigInteger.
BigInteger add(BigInteger val) : Returns a value of (this + val) Of BigInteger
BigInteger subtract(BigInteger val) : Returns a value of (this - val) Of BigInteger
BigInteger multiply(BigInteger val) : Returns a value of (this * val) Of BigInteger
BigInteger divide(BigInteger val) : Returns a value of (this / val) Of BigInteger. Integers Division preserves only the integral part .
BigInteger remainder(BigInteger val) : Returns a value of (this % val) Of BigInteger.
BigInteger[] divideAndRemainder(BigInteger val): Return contains (this / val) Heel (this % val) Of the two BigInteger Array of .
BigInteger pow(int exponent) : Returns a value of (thisexponent) Of BigInteger.
1.3 Use
BigInteger abs() Returns the absolute value of a large integer
BigInteger add(BigInteger val) Returns the sum of two large integers
BigInteger and(BigInteger val) Returns the bitwise sum of two large integers
BigInteger andNot(BigInteger val) Returns the result of two large integers and non
BigInteger divide(BigInteger val) Returns the quotient of two large integers
double doubleValue() Returns the of a large integer double Type value
float floatValue() Returns the of a large integer float Type value
BigInteger gcd(BigInteger val) Returns the greatest common divisor of a large integer
int intValue() Returns the integer value of a large integer
long longValue() Returns the of a large integer long Type value
BigInteger max(BigInteger val) Returns the largest of two large integers
BigInteger min(BigInteger val) Returns the smallest of two large integers
BigInteger mod(BigInteger val) Pair... With the current large integer val modulus
BigInteger multiply(BigInteger val) Returns the product of two large integers
BigInteger negate() Returns the inverse of the current large integer
BigInteger not() Returns the non integer of the current large integer
BigInteger or(BigInteger val) Returns the bitwise or of two large integers
BigInteger pow(int exponent) Returns the of the current large integer exponent Power
BigInteger remainder(BigInteger val) Returns the current large integer divided by val The remainder of
BigInteger leftShift(int n) Move the current large integer to the left n Returns... After bit
BigInteger rightShift(int n) Shift the current large integer to the right n Returns... After bit
BigInteger subtract(BigInteger val) Returns the result of subtracting two large integers
byte[] toByteArray(BigInteger val) Convert a large integer into a binary inverse code and save it in byte Array
String toString() Converts the current large integer to a decimal string
BigInteger xor(BigInteger val) Returns the XOR of two large integers
2 Math
2.1 summary
java.lang.Math A series of static methods are provided for scientific calculation . The parameters and returns of its method
The value type is generally double type .
2.2 Common methods
abs The absolute value acos,asin,atan,cos,sin,tan Trigonometric functions sqrt square root
pow(double a,doble b) a Of b The next power log Natural logarithm
exp e Bottom index
max(double a,double b)
min(double a,double b)
random() return 0.0 To 1.0 The random number
long round(double a) double Type data a Convert to long type ( rounding )
toDegrees(double angrad) radian —> angle
toRadians(double angdeg) angle —> radian
Apply to int long float double Methods . Call form :abs(int a, int b)
Method name explain
abs The absolute value
max Maximum
min minimum value
Apply to int long These are java1.8 New method , Mainly for some Throw the type overflow exception . Call form :addExact(int a,int b)
Method name explain
addExact Add
substractExact reduce
multiplyExact ride
incrementExact Self increasing
decrementExact Self reduction
negateExact Negative operation :1->-1;-2->2
Trigonometric function related double , Here is only a partial list . Call form :cos(double a)
cos,sin,tan,acos,asin,atan...
square root :sqrt(double a) Cube root :cbrt(double a)
power , Index , Logarithmic correlation . except pow(double a,double b), Other call forms are log(double a)
Method name explain
exp In natural logarithm e Bottom , Exponentiation
expml In natural logarithm e The power of the bottom -1
log Take the natural logarithm e Log base
log10 take 10 Log base
There are many criteria for the result of remainder .
Math.IEEEremainder(double a,double b) It uses IEEE Take the remainder according to the standard of .
There are other methods in the class library :
Method name explain
ceil(double a) Return to the smallest ( It's closest to negative infinity )double value , The value is greater than or equal to the parameter , It's going to be equal to some integer .-3.1->-3.0;3.1->4.0
floor(double a) Return to the biggest ( It's closest to positive infinity )double value , The value is less than or equal to the parameter , It's going to be equal to some integer .
round(float a) Closest to the parameter int
round(double a) Closest to the parameter long
rint(double a) Returns the closest parameter equal to an integer double value
round(double a) Go back to the plus sign double value , The value is greater than or equal to 0.0 And less than 1.0
2.3 Usage mode
3 Exception mechanism
3.1 Encountered exceptions
1 Null pointer exception
2 Subscript out of range exception
3 Type conversion exception
4 Stack memory overflow
3.2 summary
Exception is Java Provides a consistency mechanism for identifying and responding to error conditions . Effective exception handling can make the program more robust 、 Easy to debug .
There are many reasons for the abnormality , such as :
- The user entered illegal data
- The file to be opened does not exist
- The connection is broken during network communication
- JVM out of memory
- Some of these exceptions are caused by user errors , Some are caused by program errors , Others are caused by physical errors .
3.3 Inheritance system
3.4 Error
System internal error , Such errors are handled by the system , The program itself does not need to capture processing .
such as :OOM( Memory overflow error )、VirtualMachineError( Virtual machine error )、StackOverflowError( Stack overflow error ) etc. , It usually happens ,JVM Will choose to terminate the program .
3.5 Exception
3.5.1 summary
Exception Is the parent of all exception classes . Divided into non RuntimeException and RuntimeException .
- Not RuntimeException
It refers to the exceptions that need to be caught or handled during program compilation , Such as IOException、 Custom exception, etc . Belong to checked abnormal . - RuntimeException
It refers to the exception that does not need to be caught or handled during program compilation , Such as :NullPointerException etc. . Belong to unchecked abnormal . It is usually caused by the carelessness of programmers . Such as null pointer exception 、 An array 、 Type conversion exception, etc . - 5.2 Common methods
3.5.3 Try ....catch
3.5.4 Throws
There are three forms of throwing an exception , One is throw, One throws, There is also a system that automatically throws exceptions . Here are the similarities and differences between them .
One 、 The system throws exceptions automatically
When a program statement makes a logical error 、 M error or typecasting error , The system throws an exception automatically :( Take a chestnut )
public static void main(String[] args) {
int a = 5, b =0;
System.out.println(5/b);
//function();
}
The system will throw it automatically ArithmeticException abnormal
perhaps
public static void main(String[] args) {
String s = "abc";
System.out.println(Double.parseDouble(s));
//function();
}
The system will throw it automatically NumberFormatException abnormal .
Two 、throw
throw The statement throws an exception , It's usually inside a block of code , When a program makes a logical error, the programmer throws a specific type of exception
public static void main(String[] args) {
String s = "abc";
if(s.equals("abc")) {
throw new NumberFormatException();
} else {
System.out.println(s);
}
//function();
}
Runtime , The system throws an exception :
Exception in thread "main" java.lang.NumberFormatException at......
3、 ... and 、throws
throws Is a declaration that a method might throw an exception .( Used when declaring methods , Indicates that the method might throw an exception )
public void function() throws Exception{......}
Used when a method might throw an exception throws Declare exceptions that may be thrown , It is then handed over to the method program that calls it at the top
public class testThrows {
public static void function() throws NumberFormatException {
String s = "abc";
System.out.println(Double.parseDouble(s));
}
public static void main(String[] args) {
try {
function();
} catch (NumberFormatException e) {
System.err.println(" Non-data types cannot be cast .");
//e.printStackTrace();
}
}
}
Running results :
Non-data types cannot be cast .
Four 、throw And throws Comparison
throws Appears in the method function header ; and throw It appears in the body of the function .
throws Represents a possibility of an exception , These exceptions do not necessarily occur ;throw An exception is thrown , perform throw Must have thrown some kind of exception object .
Both are negative ways of handling exceptions ( The negativity here is not that it is bad ), Just throw or might throw an exception , But the function does not handle the exception , The actual handling exception is handled by the upper-level call to the function .
3.5.5 Finally
Statement blocks that must be executed , Not to be used alone It has to be with try perhaps try...catch Use it together
finally There is only one case of non execution Namely system.exit();
3.5.6 There can be no broader exceptions
3.6 Custom exception classes
3.6.1 demand
Complete the user login function
Pass in user information , Verify that the user name and password are correct , If it is correct, all the information of the user will be returned , Otherwise, an error message will be prompted
3.6.2 Entity class
3.6.3 Exception class
3.6.4 controller
3.6.5 Date
3.6.6 Dao
3.6.7 Service
边栏推荐
- How does the insurance company check hypertension?
- Deep learning parameter initialization (I) Xavier initialization with code
- Thoughts on project development
- [LeetCode]404. Sum of left leaves
- centos php7.2.24升级到php7.3
- Winter vacation work of software engineering practice
- [Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
- dataworks自定義函數開發環境搭建
- Stream stream
- 2021 year end summary
猜你喜欢
golang操作redis:写入、读取kv数据
Reading notes of "learn to ask questions"
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
VMware virtual machine C disk expansion
Pytest -- write and manage test cases
SecureCRT取消Session记录的密码
深度学习参数初始化(一)Xavier初始化 含代码
On the practice of performance optimization and stability guarantee
Practical plug-ins in idea
随机推荐
JS date comparison
服务器如何设置多界面和装IIS呢?甜甜给你解答!
Inno Setup 制作安装包
centos php7.3安装redis扩展
New knowledge! The virtual machine network card causes your DNS resolution to slow down
3311. 最长算术
When MySQL inserts Chinese into the database, there is a diamond question mark garbled code
2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
LeetCode
Summary of remote connection of MySQL
3311. Longest arithmetic
Software testing assignment - the next day
Advanced API (UDP connection & map set & collection set)
Inno setup production and installation package
Software testing learning - the next day
How to specify the execution order for multiple global exception handling classes
Search engine Bing Bing advanced search skills
SecureCRT取消Session记录的密码
Getting started with pytest
Thoughts on project development