Some small knowledge about Java programming

xiaoxiao2021-03-06  27

Q: int n = integer.parseint (" 5");

INT n = integer.Parseint ("123ABC");

When compiling is normal, you will report an error in the analysis, to achieve the above conversion, how to solve it?

A: If you want to with a symbol, int n = integer.parseint ("- 5"); can, but 5 is not possible.

INT n = integer.parseint ("123ABC", 16);

Q: The book speaks class.forname ("org.postgreSql.driver); the role is what the driver will be loaded by the static initialization process, what does it mean! A: The static initialization process explains too much trouble, I hope you can read this THINKING in Java 2nd chapter 5-8, I can explain why we always write this sentence when calling JDBC: JDBC The DRIVERMANAGER class is used to track all available JDBC drivers and select the appropriate driver when the user needs, but its tracking is not automatic, and must be registered on the DriverManager driven by the available JDBC driver. The process is generally automated when loading is loaded by the Driver class. Class.Forname ("Org.PostgreSql.driver); This sentence is to load this class into the memory, and when a class is loaded into the memory, the static initialization process in the class will execute, and you need you on this part. Going to Thinking in Java, and the process of registered on the DriverManager, in fact, in this static initialization block, that is, Class.Forname ("Org.PostgreSql.driver" This sentence is here to force JVM to load org.postgresql.driver into memory to register it to the DriverManager class.

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

New Post(0)