2013年9月15日星期日

java ten sins

java ten sins


Well, I know a lot of people look at this title can not help but want to Paizhuan or disagreed , and I have to accept.

I'm having problems, looking for some help from friends to engage in java , there can be resolved, I would say is not to solve the case , most of them will say: " So how can you get it ? such a practice is No , you are wrong on the first idea , and we never do that . " , such as" we rarely use stored procedures, stored procedure, you use so much , I suggest you use the hibernate code to implement your business, and not with stored procedures " , the problem is I have met with hibernate stored procedure call occurs when some of the situation , I have a friend engage in java can not be solved, he said so.
java developers also like to say : this should not be completed by the jdk or a certain frame , but rather by the brave, industrious , intelligent writing to you to achieve.

The following are my java projects in development , some of the problems encountered , may also be written in the wrong place , hope to correct me.
encountered many problems , one time can not be all up for discussion , it is just a few examples .

1. "abc" == "abc" result returned is false, many beginner java have a lot on this issue is a waste of time because that would be very confident here will return true, would not think of the original problem here . See the Internet postings discussed this issue , saying that java is a pure object-oriented language , the == operator is relatively address or something, but "abc" is a reference , it can not be compared using the == operator , while equals method should be used for comparison , would commit such a mistake , mostly because of their solid foundation, still speaking of java is not. I saw an example of one person said , it is able to express my feelings, is to say : One day I went to a restaurant, because the restaurant entrance there is a pool of water , leading to the road very slippery, I accidentally fell down, so I called the restaurant manager , held accountable , results restaurant manager told me that it was because of my own walking posture wrong, so slipped and restaurants irrelevant .

2. Why did not get; set; property , but the use getXX (); setXX () method instead, do not reflect the cost of it ?
I 've learned struts \ spring \ hibernate there are a lot of use in this way , such as struts in vo objects inside that if a getUsername (), can be used in the page to the value , I think it was the middle of the reflection to find the getUsername () method , and then obtain the value of it , the same spring \ hibernate are also widely used in this way , may I ask , reflections do not say that it is inefficient ?

3. make a custom label tld also write their own configuration files , sometimes looking at some java related books mentioned above, zero- configuration, I felt very funny , I do not know the so-called zero-configuration reflects the spirit in the end Where ? Maybe write a configuration file is also not so difficult, but the key question is , technically speaking this tld obviously can not , ah , tld which describes mainly on what was the name of this tag which attributes , namely, what type , these information which is entirely possible in class , as long as the class is to implement the Tag interface, it is automatically recognized as a custom label it bad ? By identifying the class what getXX (); setXX (); ( better solution is to have get; set; property ) to determine what this custom tag attributes , and what type, so do not you ? Why bother to put forward a tld configuration file ?
there is a problem is that if I wrote a MyTag class inherits a custom label class , I would like to write a corresponding tld MyTag configuration, I do not know what there no other developers will inherit my MyTag, maybe even I warmly welcome others to inherit my MyTag, but when people see me MyTag in nearly forty getXX (); setXX (); later , the thought that you want to write tld the appropriate configuration files and hope born of confidence now .

4. data access in my opinion, should be a very simple thing, simply come on , that is, execute SQL statements, a bit more complex , it is coupled with the physical mapping framework to solve all the problems , the first is to be easy to use in used hibernate , I feel it is too complicated for me in . net has a data access layer , only in the specified configuration file to configure the connection string , you can call anywhere in the program DbHelper.Execute (sql), DbHelper.ExecuteDataSet (sql), DbHelper.ExecuteDataTable (sql) , and very simple to use , of course, have a physical mapping , DbHelper.save (entity), DbHelper.delete (entity or key), DbHelper.select ( condition ) set of methods that can operate this entity object , select returns a list of entities , the entity through its associated element attribute tables and fields , outside the middle in addition to the connection string , there is no other configuration files . In contrast , hibernate configuration file ye need so many ? I know you can configure hibernate annotations , you do not need a hbm configuration file , but even so, as far as I know still still need a lot other than the connection string in addition to the relevant configuration file.

5. saying there are so many years java , hibernate there for so many years , and in the end I will not use, or whether it really is such , hibernate support for stored procedures , it drove me crazy , actually does not support stored procedures, on the Internet looking hibernate call a stored procedure , the answer is that the majority of cross hibernate, but only from hibernate to obtain a connection, then use the jdbc way to call a stored procedure to do so there is a problem , the transaction can not be controlled , because the I'm still relatively water , hibernate transaction control is secret operations , seems to be as long as the business service layer to write code in a transaction, so I can not get my stored procedure call and hibernate code string in a business transaction which , while in many cases , I want to make them a failure on all failed .
In addition , there are not crossed hibernate while calling a stored procedure approach , there are two , but also to write the configuration file , one must have to return a result set , I am very puzzled why must be the result set , many of my stored procedures just to deal with some data , no return result sets , the most painful is actually oracle stored procedure returns a result set is not supported , you must use one kind of perverted way to return a cursor , so do what I feel is extremely nausea. Another way is by modifying the entity insert \ update \ delete the default behavior , for example, I insert an employee, was supposed to be executed sql statement insert into employee values ​​(?,?,?,?) Of I can modify this default behavior configuration file , change the {call myproc (?,?,?,?)}, this approach is clearly not what I want, I just want to call a stored procedure , perform a business treatment . These two methods are secret operations of the firm would be manageable, but it does not meet my needs , how do I do ?

6. data access result set object ResultSet, RowSet, CachedRowSet and so has not been widely used, each frame is more inclined to support a list of entities , do cause a problem that I can only return to the known structure of the result set , if you want to return a temporary thing in the entity must also add the appropriate attributes getXX (); setXX (); methods, such as in hibernate , to access the employee table , employee table had only department ID no department name, department name you want to have , you must add a deptName employees entity attributes , all results are known to be structured, this is very painful , if not to return to the list of entities , you can also return to ArrayList in , but such data is not column name , do not understand why not direct inquiries to the ResultSet , then let more framework support ResultSet, such as struts, writing pages use struts tags , you can list the same operation as the operating entity of the ResultSet.
... , ( or was it to support , but I do not ? would blush ! ) just want to make the framework supports more result sets of unknown structure , allowing the programmer designed well in advance of the result set structure is very tiring , even code generation , can only generate a database table corresponds to each entity , but often we need to select unkownSchema from myTable get the result set of unknown structure , not always select *.

7. Besides ResultSet, why not just use this , and use the list of entities to replace, I think it is not also indirectly shows , ResultSet inconvenient to use this class ,. net in the DataSet and DataTable to get a lot used because they are easy to use and practical. Perhaps the biggest difference lies in the place , DataSet is a disconnected style exists in memory micro database, a database ResultSet simply -connected reader equivalent . Net in the DataReader, must remain connected in order to read the data , I know there CachedRowSet can disconnect the type of data stored in memory , well, this is not a problem . But another problem nuisance me, as a container for storing the result set , give us manipulate the result set way too little, and even obtained the total number of rows in the result set methods , we all need to start small brains, so write : rs.last (); int count = rs.getRow (); rs.first () is responsible for the case, it requires at least three code to get to the total number of rows . Maybe this is just a small problem, this should perhaps by the brave, industrious , intelligent us to achieve.

8. In my opinion , struts greatest significance is that it allows each jsp page has a corresponding java class methods , that is, that the action method . You will tell me , struts function is not only that, but I said , I've seen a lot of ( small companies ) project , struts sense just like this, I imagine that in our country , there are tens of thousands of the use of java technology companies , struts for their meaning , which is to have a jsp code behind . If only just so , is it not official , directly jdk support so advanced to compensate jdk struts behind you ? Just trying to hide something .
Or you may say , even struts is to provide a jsp page so that each has a corresponding action method, which is also very great, do it , has revolutionized the way people develop web project approach , and pages from the original business code mixed into solution even separation , very successful . I want to say , do not take your glory a decade ago to run again today , and has been out of the die.

9. Besides myeclipse, this ide java system in almost become the standard , I have seen all the java developers are using this IDE, but in comparison, it is with visual studio on the difference too much, performance is not to say , if not optimized , it is slow to die , saying why not publish it in one of the default settings is to optimize it ? What if we need to plug-in components , and then to load it , so do not even understand ?
In addition myeclipse plugin installation really makes me ashamed , 6.x, 7.x, 8.x versions of these plug-ins installed in different ways , I think , why not simply double-click installation ? vss2005 is simply double-click the installation. So far I have not figure out how to install svn plugin , well , I am water, the plug-in installed sometimes you want to copy files to a specified directory , and sometimes you start myeclipse , select help menu under software updates, sometimes to choose what myeclipse configuration center, sometimes you want to connect to the Internet online operation , worse still , to give you a java file to your compiled into class files , and then steps , I was served.


10.out output parameters , partial classes , extension methods , lamuda expression of these very good thing , java are not, or I would not do ? Hope correction.
spring, in fact, I still do not know what it is doing , well, this is my sin.

look fierce , hot discussions, we can use the Chamber Kang Lai , Weiweijiuzhao , House of Flying Daggers , singled , hit other means .



------ Solution ------------------------------------ --------
also, I disagreed with the business logic written stored procedures, small systems can certainly do so , if the volume of business increases with time , then the database lateral expansion of capacity is limited, pressure of all stored procedures in the database , the system had to reconstruct

If the business logic into the java program, then do a cluster , the expansion would be much easier
------ Solution ------------------ --------------------------
agreed as part of the other do not understand
For example, the result set , when I want to get the result set count, and then I take it for granted there should be a getCount () or getRows ()
TNND court death find
------ Solution ------------------------------- -------------


return what this thing looks like and JVM implementation is a relationship .

String s1 = "abc";
String s2 = "abc";

s1 == s2 ;/ / This results in a different JVM is not the same under the
------ Solution ------------------ --------------------------
my program where there is no framework , why should frame it ?

framework is also a mess of people write out, not java official out, uneven level

I do not need someone to write the framework , I use jdk stuff comes on OK chant


------ Solution ------------------------------------ --------
they blame HIBERNATE, I can use other methods doors connecting to the database ,
And the way ECLIPSE always been this way , with the use of it used to , but not a big problem ,
not ten sins so serious it
------ Solution ----------------------------- ---------------

which svn plugin ? BTW, suggested the direct use eclipse for j2ee

frame problem is this . No one perfect frame. As a habit , " his hands and clothing ," the javaer, using the. NET also has an inconvenient time , there are a lot of dissatisfied grumbling . But this does not affect . NET and its users.

do more projects will naturally summed up a framework for their own custom too , it may be based on SSH, it may not be based on any framework . . NET , too, a lot of companies , and over time there will be byte control library , framework .
------ Solution ---------------------------------------- ----
landlord thought of spending so much stuff is really very good
mind not so much to find a reply

10.out output parameters , partial classes , extension methods , lamuda expression of these very good thing , java are not, or I would not do ? Hope correction.
spring, in fact, I still do not know what it is doing , well, this is my sin.

first to judge if java , java is it ? java class library can not represent java, because the library is always in constant development and improvement , and I think there java itself relatively stable mechanism that can truly represent the java, or that the concept of java

out output parameter , using the output parameters for the resulting output I feel very good, because it is contrary to intuition , the method returns the value of the resulting output is better than it , this personalized attention programmer ( Program staff ) to improve efficiency so I think the idea should be in the affirmative, in fact, the overall efficiency is higher , the object language pop to prove this point , I do not know partial classes , extension methods , lamuda expression these are What may have alternative java bar, unclear
------ Solution ----------------------------- ---------------
not JAVA not, is the landlord level too times.
1. Already said , without duplication.
2. getXX () is only JAVA Bean specification , nobody did have to write regulations . Achieve their own get (XXX) is not enough.
3. JSP Tag 2. 0 can not write tld
4. Hibernate has SQLQuery.
5. Hibernate has beginTransation series of transaction control , is that you will not use.
6. Hibernate SQLQuery have addEntity and addScale method, Mapping arbitrary schema of the result set to the physical or List
7. Landlord is not know SQL? Rows statistics should be used SQL count () aggregate function , JAVA pishi off . Count finished , Hibernate query uniqueResult () to get the results chant
8. struts dry JDK anything , JAVA do not understand the basic concepts in this pure nonsense .
9. Others said, it pays for chanting.
10. I do not know what you're saying . These JAVA have, or have equivalent alternatives , but you dish it.
------ Solution ---------------------------------------- ----


Can you talk about the idea of ​​using pure jdbc it ? Before I would also like to use pure jdbc, then think too much trouble , they think of themselves write some helper methods , I kept thinking I felt : I did so might as well go to hibernate a
------ Solution - ------------------------------------------
this little helper method dbutils tool bag already , the other should be similar. I personally think that the traditional way of good dao


------ Solution ------------------------------------ --------

lz fair to say I am here : < br />



public class test {

public static void main(String[] args) {
String str1 = new String("abc");
String str2 = new String("abc");
System.out.print(str1 == str2);
}

}

public class test {

public static void main(String[] args) {
String str1 = "abc";
String str2 = "abc";
System.out.print(str1 == str2);
}

}



we look at the results of these two codes , and then criticize lz, arbitrary criticism lz, only show you half a cup of java based more water that you can, to explain the reasons appear above .
------ Solution ---------------------------------------- ----
languages, frameworks, since the value of its existence , there appears

If you have used or a more in-depth understanding of some of the language or framework , I absolutely should have no qualifications comments

Since it exists, is still used by people that he must have a unique place

such as tofu, you first glance a smell , ugly and smelly , and when you tasted , how to know in the end ( of course, different people different tastes )

Now I feel bad a choice to completely abandon it in two is to understand he found her good !
------ Solution ---------------------------------------- ----
I have come to holding the landlord ~
------ Solution -------------------------- ------------------
landlord , I support you, that you give points too low. Otherwise, I 'll help you dish them.
------ Solution ---------------------------------------- ----

seeking grass brother shot I came to the sub .
------ Solution ------------------- -------------------------


really give points do ?


1.
"abc" == "abc"
not have a Java- speaking book tells you what it returns , it will only tell you not to compare strings with == .
language standards will not require this thing . That is the standard answer is "do not know " is the wrong answer true , false answer is also wrong.
say poorly designed Java this is the NB ! Such as landlord !

2. This thing returns true and false, it does not matter . Because Java programmers can not be so over , so no more than the basic equal significance.

3.
You know Java1.1 inside "abc" == "abc" returns true it is ?
Even Java1.1 this returns true, then Java 0.9 may also return false.
completely depends on the compiler how to achieve , you can guarantee that Android's Java also returns true?
Do not be too confident and said the landlord not the level


4.
"abc" == "abc" =? JVM not claim to have seen it in depth point ?
If I write a . java files , which appeared more than 70,000 string constants how to do ?

CONSTANT_String_info {
u1 tag;
u2 string_index;
}
u2 is unsigned short, on 70000 this number string constant , constant pool how you deal with the property ?
Each string constants will be found in the constant pool do ?
So you better answer results for " unknown "


------ Solution ------------------------------------ --------


how a given method ?
------ Solution -------------------------------------- ------
for IDE and various optimizations , I also served
In addition , LZ give points too little, not enough men to war , motivation you know
------ Solution --------------- -----------------------------

4.
"abc" == "abc" =? JVM not claim to have seen it in depth point ?
If I write a . java files , which appeared more than 70,000 string constants how to do ?

CONSTANT_String_info {
u1 tag;
u2 string_index;
}
u2 is unsigned short, on 70000 this number string constant , constant pool how you deal with the property ?
Each string constants will be found in the constant pool do ?
So you better answer results for " unknown "


"70000 this number string constant " is a compilation pass drops . . . Is because of the restrictions that u2 , another method code length is limited





------ Solution ------------------------------------ --------
LZ, your attitude is really good too , I have read your text , hee hee , http://www.cnblogs.com/zhouyou96/archive/2011/06/17/ 2083566.html
------ Solution ------------------------------------- -------
Jacks test suite Java compiler checks whether JLS. It consists of a large number of small test cases , each test focused on a specific part of the JLS . Compiled with the specified behavior by generating a small test case , and then automating the execution of each case , the author or compiler debugger can quickly find the Java source code to byte code conversion problems .

Only through compatibility testing jvm are accepted and approved , otherwise it is pseudo- java, but like "abc" == "abc" If false , then pass it


------ Solution ------------------------------------ --------
good this reply : "abc" == "abc" this issue should be the most basic right java , jvm as String this type specifically set up a pool, aimed String improve performance .

Java is the essence of Java EE, and spring struts do not understand because you do not have an overall framework from the point of view of a system , but the syntax is basically just stand scrutiny.

If you said . Net has DbHelper, then Java is more NB. Injected directly into the DataSource, in addition to separate configuration documents , JAVA can also ignore the database type, Java developers who do not care about is the Oracle or DB2.

Java EE with JPA, storage process is no problem , hibernate should also be supported by the JPA , I do not know why you do not support stored procedures. Transactional operations , Java EE with JTA, combined with the JPA to use .

If you want the official struts, then that JSF, struts jsf writer is one of the architects .

As for why certain open source framework is not included in the official technology , that would show that you do not understand the Java world truly wonderful place - open source and innovation . Have you seen JDK, Java EE should know which are the relevant package interfaces and abstract classes , the official did not provide the appropriate implementation.
Take JSF , its implementation will have the oracle adf, sun of Mojarra, Apache 's MyFaces Core, JBoss 's Seam , etc. These implementation on the basis of the official compatibility has its own characteristics and innovation.
Java world flourishing while . Net community lifeless , look at that codeplex, ASP plug-in extensions , and then Bibi same Oracle ADF and JSF's JBoss Richfaces.

earlier a project requires sftp to transfer files ,. net actually look better than a free library , sad !

Java EE is the essence of one of the EJB, OOP emphasis is on low coupling , high cohesion , EJB is a manifestation of this idea . All Bean are container managed by injecting use a bean worry about the other bean's life cycle. Familiar with Java EE EJB can experience wonderful . And . Net it, talk JAVA EE 4 than it
------ Solution -------------------------- ------------------
you this ten crimes there are a lot of frames , not of JAVA , huh.
------ Solution ---------------------------------------- ----
recommend a book . " Java FAQ "
which describes in JAVA 95 magic of " cases "
------ Solution ------------------------ --------------------
watch , the landlord is quite profound , dare challenge is good.
------ Solution ---------------------------------------- ----
Why did not get; set; property , but the use getXX (); setXX () method instead, do not reflect the cost of it ?


how this became reflected ?
obviously it is a method call , c # attributes method call is not real , but why come up with c # attributes this form , this was the place I was wondering .
eat stays
------ Solution ------------------------------- -------------
on your first nine stresses the ide
I have to say , vs function and it is a big change compared to eclipse

I'm just saying that there are several eclipse , vs can not be found
outlook class outline ctrl + o
hi ... class hierarchy f4, ctrl + shift + h
open type open type ctrl + shift + t
open resource open resource ctrl + shift + r
find references ( references refer to the program , rather than vs string matching ) ctrl + g
...

You say the above functions , vs there do ?
If there is , I am very happy to know, because it is a good use

In addition , eclipse only 100M look , myeclipse also less than 1G
vs2010 there are several G

------ Solution ------------------------------------ --------
sometimes I feel is a java middleware, in various environments transformation language middleware . Complex functions and effects can not, the bottom too.
------ Solution ---------------------------------------- ----
me paging. . .
------ For reference only -------------------------------------- -
Haha, fun, onlookers wait
landlord , I support you
------ For reference only ----------------------------- ----------
I onlookers watch the
------ For reference only ------------------- --------------------
landlord powerful ah , java really profound ah
------ For reference only ------- --------------------------------
1. "abc" == "abc" returned results is false
first time I heard , you can not even one language data structures are ignorant and blatantly talk about ten sins !
------ For reference only -------------------------------------- -
some sin is not Java , but of the man.
such as the TMD myeclipse
------ For reference only ---------------------------- -----------


In java, "abc" == "abc" is indeed returns false, according to conventional thinking, understanding , it should return true fishes, what you said data structure , what mechanism , I do not care , I do not want to control , I only know one language should be humane. Do not put it to use a non- human : "This is my mechanism" to cover up .



------ For reference only ---------------------------------- -----

"" this thing is a string ah , on the C use a char * or char [] expressed it, with == would get what ?
This " conventional wisdom " is often we take it for granted it.
------ For reference only -------------------------------------- -




landlord to put this code is executed once again to speak :

public class Test {
public static void main(String[] args) {
System.out.println("abc"=="abc");
}
}

------ For reference only ----------------------------------- ----
actually launch their own performance is good , more time-consuming in the Find Method, but this can be a buffer solution
------ For reference only ----- ----------------------------------
Khan landlord in which to see the "abc" = = "abc", returns false
------ For reference only ------------------------------ ---------

hey , the landlord with a cup
------ For reference only ---------------- -----------------------
myeclipse can double-click the installation , and for a fee , the landlord you will want to download the plug- in the form of what do ?

ssh
In addition to these frameworks , nobody is saying you have to use, I do java so many years, never used ssh, do not write jsp. From this , the landlord 's horizons somewhat narrow
------ For reference only ----------------------------- ----------


This returns true it. Do our JAVA not the same?
------ For reference only -------------------------------------- -
my opinion , if there is such a method , if necessary, iterate over the result set , if the database pressure, to obtain a large set of results , this method can be fatal

I 'd rather select count it, sometimes select count should be a lot of seconds or even minutes , if you can imagine the cost of traversing the result set


------ For reference only ---------------------------------- -----
other hibernate, struts, jsp not used , do not speak
------ For reference only ----------------- ----------------------
very sorry, but the first 1:00 on the "abc" == "abc" returns false I was wrong , in java, is to return true , I did after the experiment said so , so sorry. The reason I say that is because I do not remember which one , because I'm using a string comparison == carried out , the results and did not return to me with the results, and then ask the elderly, old people have admonished said: best use equals to compare instead of == , so there is emotion.


------ For reference only ---------------------------------- -----
another point I want to say , hibernate also supports . NET , if . NET using hibernate may also have the same problem , hibernate just a tool, no one forced you to use , I never used, are operated directly jdbc
------ For reference only ----------------------------- ----------


Now the domestic large projects or, small projects , it is all to do with java up ( there . net or anything else ) , the tragedy is that I just do small projects.

small project , then use the stored procedure is still very convenient .

------ For reference only ---------------------------------- -----
famous a series of books called Think in XXX
I want to say is that if learning a language , or framework , in accordance with its way of thinking .

If you learn English , people have verb conjugation in English , what singular and plural nouns , and grammatical structure , and Chinese after the big difference , you must follow the grammatical speaking English?


java is in accordance with the idea to compare two objects , always use equals. Possible . NET users, accustomed to . NET, syntactic sugar , but I want to say too much operator override will eventually make the code can not understand. But the other way round , why not let Microsoft VB.NET realize if (condition) {} but still IF (condition) THEN END IF? ? ? Year for the first time with VB.NET, C #, all information online , I told my colleague said, " really TMD idiot, emerging keywords , why not c # and vb.net unity" - if I remember correctly is the override / Overrides. But as long as used to it, no problem ah.

------ For reference only ---------------------------------- -----


I said myeclipse plugin , such as svn plugin , that is more difficult to get to know in the end how the installation.

when you said that the first two questions , the question is what I want to say , that people who engage in java java flourishing like to say , there are many choices , it also provides a good their escape problems excuse.
When I feel bad for an open source framework , criticize , flew to someone speaking, nobody forced you to use this framework, you do not know the other frames ah , but in fact , when I actually went with another a framework, still there will be this kind of problem is not from another frame ?


------ For reference only ---------------------------------- -----
talking behind the XXX into jdk, that belongs to a joke .
------ For reference only -------------------------------------- -










------ For reference only ---------------------------------- -----



------ For reference only ---------------------------------- -----






------ For reference only -------------------------------------- -









------ For reference only ---------------------------------- -----

! ! ! !
------ For reference only -------------------------------------- -

  
------ For reference only -------------------------------------- -


Haha.

   ! !



------ For reference only ---------------------------------- -----





.


. . . .

没有评论:

发表评论