Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the problems that Java needs to pay attention to?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what the Java needs to pay attention to, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Top 1: the result returned by "abc" = "abc" is False. Many beginners of Java waste a lot of time on this problem, because they will confidently think that true will be returned here, and will not think that the original problem lies here. On the Internet, I saw a post discussing this problem, saying that Java is a pure object-oriented language, the = = operator is a comparison address, and "abc" is a reference, so you can't use the = = operator for comparison, but you should use the Equals method to compare. You will make this kind of mistake, mostly because you don't have a solid foundation, but you still say that Java is not. One day I went to a restaurant because there was a pool of water at the door of the restaurant, which caused the road to be slippery, so I accidentally fell down, so I called the restaurant manager to investigate his responsibility. as a result, the restaurant manager told me that this was because I was walking in the wrong way, so I slipped and had nothing to do with the restaurant.

Top 2: why don't you use the getXX (); setXX () method instead of the get;set; attribute? doesn't reflection cost?

This method is widely used in Struts\ Spring\ Hibernate that I have learned, such as the VO object in Struts. If there is a getUsername () in the VO object, it can be used to take a value on the page. I think reflection should be used to find the getUsername () method and then get its value. This method is also widely used in the same Spring\ Hibernate. I would like to ask, doesn't reflection say that it is very inefficient?

Top 3: make a custom tag and write your own TLD configuration file. Sometimes when I read some books about Java that mention zero configuration, I find it very funny. I don't know what the spirit of zero configuration is. Maybe it's not that difficult to write a configuration file, but the key question is that technically speaking, this TLD is obviously unnecessary. TLD mainly describes what the tag is called, which attributes, and what type it is. This information can be expressed in the class. As long as the class that implements the Tag interface is automatically recognized as a custom tag, isn't it good? Isn't it bad to identify which getXX (); setXX (); (better yet, have get;set; attributes) in the class to determine which attributes this custom tag has and what types they are? Why bother to create a TLD configuration file?

Another problem is that if I write a MyTag class that inherits a custom tag class, I also have to write a corresponding TLD configuration for MyTag. I don't know if any other developers will inherit my MyTag in the future, maybe even if I warmly welcome others to inherit my MyTag, but when others see nearly 30 or 40 getXX (); setXX () in my MyTag; after that, I get scared at the thought of writing the corresponding TLD configuration file.

Top 4: in my opinion, data access should be a very simple thing. To put it simply, it is to execute SQL statements, a little more complex, plus entity mapping. The problem solved by all frameworks is, first of all, to be easy to use. After using Hibernate, I feel that it is too complex. I have a data access layer in .NET and only need to configure the connection string in the specified configuration file. DbHelper.Execute (sql), DbHelper.ExecuteDataSet (sql), DbHelper.ExecuteDataTable (sql) can be called anywhere in the program. It is very easy to use. Of course, there is also entity mapping. DbHelper.save (entity), DbHelper.delete (entity or key), DbHelper.select (condition) this group of methods can manipulate entity objects. Select returns a list of entities, and entities set their associated tables and fields through meta attributes. There is no configuration file except for the connection string. By contrast, why does Hibernate need so many configuration files? I know that Hibernate can also be configured for annotations, so you don't need HBM configuration files, but even so, as far as I know, you still need a lot of related configuration files other than connection strings.

Top 5: it is said that Java has been for so many years, and Hibernate has been for so many years. Is it that I can't use it, or is it really the way it is? Hibernate's support for stored procedures really drives me crazy. When I look for Hibernate to call stored procedures on the Internet, most of the answer is to go beyond Hibernate, just get a Connection from Hibernate, and then use JDBC to call stored procedures. There is a problem in doing so. Transactions can not be controlled, because I am still quite water, Hibernate transaction control is clandestine operation, as long as the business code written in the Service layer is in the same transaction, so I can not let my stored procedure calls and Hibernate business code string in a transaction, and in many cases, I want to let them all fail.

In addition, there are two ways to call stored procedures without going beyond Hibernate. One is to write configuration files. One is that there must be a returned result set. I wonder why there must be a result set. Many of my stored procedures just deal with some data and do not need to return the result set. The most painful thing is that the stored procedure of Oracle actually does not support the return of the result set. It must be returned in an abnormal cursor way. In doing so, I will feel extremely sick to my stomach. Another way is by modifying the default behavior of entities in Insert\ Update\ Delete. For example, when I am an employee in Insert, I should have executed the SQL statement insert into employee values (?) I can change this default behavior to {call myproc} through the configuration file, which is obviously not what I want either. I just want to call a stored procedure to perform a business process. The above two ways will be managed by black-box operation of the firm, but can not meet my needs, what should I do?

Top 6: the result set objects of data access, such as ResultSet, RowSet, CachedRowSet, etc., are not widely used, and each framework tends to support the entity list, which leads to a problem, that is, I can only return the result set with a known structure. If I want to return something temporarily, I must add the corresponding attribute getXX (); setXX () to the entity. Methods, for example, in Hibernate, in order to access the employee table, there is only department ID in the employee table, but there is no department name. If you want to have a department name, you must add an attribute of deptName in the employee entity, so that all the results are of known structure. This is very painful. If you do not return to the entity list, you can also return to the ArrayList, but such data does not have a column name, so you do not understand why it is not directly queried in ResultSet. Then let more frameworks support ResultSet, such as Struts, and when writing pages using Struts tags, you can manipulate ResultSet as if it were a list of entities.

Or do you support it in the first place, but I won't? Then I'm sorry!) Just want to let more frameworks support the result set of unknown structure, it is very tiring to let programmers design the structure of result set beforehand, even if the code is generated, it can only generate the corresponding entity of each table in the database, but often we need select unkownSchema from myTable to get the result set of unknown structure, not every time Select *.

Top 7: besides, ResultSet, instead of using this directly, instead of using entity lists, I think it indirectly shows that the class ResultSet is not convenient to use, so DataSet and DataTable in .NET are widely used because they are easy to use and practical. Maybe the difference is that DataSet is a disconnected micro-database in memory, while ResultSet is just a connected database reader, which is equivalent to DataReader in .NET. You have to keep a connection in order to read data. I know that CachedRowSet can disconnect and store data in memory. Well, that's not a problem. But another problem is bothering me. As a container for storing the result set, there are too few ways for us to manipulate the result set, and even to get the total number of rows of the result set, we need to use our brains to write: rs.last (); int count = rs.getRow (); if rs.first () is responsible, it needs at least three lines of code to get the total number of lines. Maybe this is just a small problem, maybe it should be realized by the brave, industrious and wise us.

Top 8: in my opinion, the point of Struts*** is that it makes every JSP page have a corresponding Java class method, that is, the Action method. You must tell me that the function of Struts is more than that, but I say, I have seen a lot of (small companies) projects, Struts is just like that. I imagine that in our country, there are thousands of companies that use Java technology, what Struts means to them, that is, to give JSP back-end code. If that's all, why not provide it officially, let JDK support it directly, and let the advanced Struts make up for the backwardness of JDK? Just want to cover it up.

Or you will say that even if Struts provides a corresponding Action method for each JSP page, it is also very great, to do this, has completely changed the way people develop Web projects, from the original business code and pages mixed together, into decoupling separation, very successful. I want to say, don't talk about your glory ten years ago today, it's not Out anymore.

Top 9: besides MyEclipse, this IDE has almost become the standard in the Java system. All the Java developers I have seen use this IDE, but by comparison, it is too different from Visual Studio, so its performance is not to mention. If it is not optimized, it will be incredibly slow, so why can't the default settings released in one of them be * *? Wouldn't it be clearer if we needed some plug-in components and loaded them ourselves?

In addition, the plug-in installation mode of MyEclipse really makes me ashamed. The plug-in installation methods of the versions of 6.x, 7.x, and 8.x are different. I was thinking, why can't we just double-click the installation? VS2005 is just double-click the installation. So far I have not figured out how to install the svn plug-in, well, I am very water, the installation of that plug-in sometimes to copy files to the specified directory, sometimes to start MyEclipse, choose Software Updates under the Help menu, sometimes to choose what MyEclipse configuration center, sometimes to connect to the Internet online operation, what is more, to give you a Java file, want you to compile into a Class file, and then follow the steps, I am convinced.

Top 10:Out output parameters, partial classes, extension methods, LAMUDA expressions these very good things, Java does not have, or I can not? Look at the correction.

My sin: Spring, actually I don't know what it does yet. Well, it's my sin.

Thank you for reading this article carefully. I hope the article "what are the problems you need to pay attention to in Java" shared by the editor will be helpful to you? at the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report