Document directory
- Language
- Concept
- Configuration File. Can you add more?
- Open source, which I like
- IDE
- JVM vs CLR
- Developers
- Postscript
One year of Java Development(From blog)
By yundao tianxiao
From last year to now, it has been almost a year since I switched from. Net to Java Development (it is definitely irrelevant to the platform quality for project reasons. Over the past year, I felt a little touched and wanted to compare the two platforms. We hope to be objective and fair.
Language
I used to use the C # language. Compared with the current Java language, the current Java language syntax stays in the C #2.0 era. The syntax structure is quite traditional and quite satisfactory. It is very prominent that, due to the lack of support for closures, some of them are easily implemented using C #. Java requires a lot of coding nonsense.
A few days ago, infoq published an article by the British Guardian about gradually replacing Java with Scala, which is very useful: it is easy for you to see the Java code without looking at the trees. In order to implement a function, you need too much code to support it, but the key code to implement the function is lost.
For example, I need a sorted list of users based on the username. This is a simple requirement. The natural code must be like this:
Ilist <user> Users =...
Users. orderby (user => User. Name );
If you use Java to implement the same function, you may want to write it like this:
List <user> Users =...
Collections. Sort (users, new comparator <user> (){
Public int compare (User left, user right ){
Return left. getname (). compareto (right. getname ());
}
});
First, there is no support for extension methods. Only static helper classes are supported.
Second, there is no support for closures, so you have to write an ugly anonymous class.
In fact, we only need one orderby statement, which can be understood at a Glance. However, with so many useless codes, the value of the core (order by) seems less important. This is a very simple example. In actual projects, you will pay more for it. You need to write a pile of code that tastes the same as chewing wax to implement the function you want, and that function is quite obvious.
Therefore, at the language level, Java does not have any bright spots, but only feels Luo liarge.
Regarding the comparison of language, Lao Zhao has written a lot and is wonderful. I suggest you enjoy it.
However, Java also has a few interesting little things: for example, static import (the head reminds me that this thing has appeared in VB for a long time) and Java's special support for annotation allows us to do something more interesting.
Concept
What impressed me most since I started Java is that the concept of the Java World is everywhere. Orm, IOC, and AOP. net is also available in the world, but you have never seen such a strong, but if you are a Java application, you are not familiar with these, you are embarrassed to say hello to people, so in addition to learning Java itself, there are a lot of open-source frameworks waiting for you to study.
What are the view model, Presentation Model, validator, bro (Business Rule object), BPO (Business Process object), and BDD. The key is that such a term exists not only in terms of concept, but also appears in the code. The concept is fully described in the Code and well-behaved. Maybe I have been an old man. I have been developing. Net for more than three years and have never done all these things. But I have no doubt that my code is difficult to read and maintain.
Configuration File. Can you add more?
I hate spring configuration files (although you say this is just a framework, it seems that the Java Community has this trend ). Although spring now supports annotation, there are still some unknown and unknown reasons, there are a large number of configuration files in the project. A small configuration file contains several configuration files for "adequacy. If the Controller is configured, the DAO is configured, and the service is configured. And the damn hibernate HBM file. I think the complexity of the system comes from the accumulation of such 1.1 points.
ASP. NET configuration files have also become more bloated at one time, but they are still greatly reduced (the default web. config in. Net 4.0 is very small ). In addition, attribute is available in the first version of. net. Many configurable items provide attribute APIs and XML APIs, so there is no historical burden.
Open source, which I like
The open-source software in Java far exceeded. Net (this may have something to do with Microsoft ). If you want to complete a job, there will always be an Open Source Software suitable for you. For example, if we want to create a scheduled task, quartz will immediately jump to your field of view. You only need to implement several interfaces and configure them in the configuration file (which is also a damn configuration file ), for example, if you cannot use Lambda like in C # in Java, a person who has the same idea as you will immediately develop a lambda4j (the Java people say: the language library is insufficient to complete, but the Java language is too insufficient, so sometimes the class library is not well supplemented ). You can find the most appropriate open-source framework and open-source library, and then open this Pandora box. The most important thing is that she is still open. You can not only learn its code ideas, but if you find any problems, you can even submit the code. I don't feel the sense of accomplishment when developing. net. For example, if you want to develop a high-performance server. net has not seen such open-source projects, but in Java you can learn netty, Mina, and you can even follow your own specific business scenarios, make appropriate changes to these open-source software. Of course, you can say that the idea is the same, which is good. However, because the I/O model is in Java and. net is not the same, so there are many differences (of course I think. net asynchronous Io is easier to use. Java NiO is a shit-like API ).
IDE
Development is definitely inseparable from IDE .. Net IDE is well deserved for Visual Studio. However, I think Visual Studio has been getting farther and farther away from developers over the past few years, as if he wants to develop software development tools throughout the entire life cycle. So not only is it bloated, but it is not very friendly to developers (of course, her visualization designer is unparalleled, but I don't think the visual designer is a "powerful tool" for developers "). For example, a large number of combined shortcut keys are used in. This not only makes the shortcut key too long, difficult to remember, but also difficult to use, you must press twice, and the time interval cannot be too long. The reconstruction function of VS is too weak.
There are a variety of IDES in Java, there are free, there are charges. I like intellij idea very much. Idea gave me the impression that she was really focusing on the developer (write code) role. All the shortcut keys are simple and easy to remember. For example, most things can be solved by pressing Alt + enter in idea (this shortcut is context-aware and knows what to do in different contexts ).
The other is idea's support for refactoring. If you are familiar with it, you don't need to manually modify any code for a large refactoring, And you can simply rely on IDE's support, this is very important in security refactoring. Manual modification of code refactoring is highly risky if the test is incomplete.
Of course, vs also has many useful plug-ins to improve development efficiency. For example, the well-known resharper comes from the same company of intellij idea. With this plug-in, you can see how idea focuses on the efficiency of code writers.
JVM vs CLR
Generally, Java runs on JVM and C # runs on CLR. In terms of technical implementation, they have their own advantages. We cannot evaluate their advantages. It can only be said that JVM is better than CLR on XXX, and CLR is better than JVM on xxx. In addition, there are many similarities between JVM and CLR, and most things can be found on the other side.
So they cannot compare? No. After one year of study, I said I prefer JVM.
JVM (here it is assumed that it is Oracle/Sun hotspot JVM) Exposes a large number of configuration parameters to developers. You can use these parameters to indirectly control JVM running. For example, GC. JVM has various parameters to control the size of each generation. It also allows JVM to adopt garbage collection policies. Different types of applications, such as desktop, server, and memory, are suitable for different garbage collection policies. The CLR only provides developers with few controls such as workstation (whether it is concurrent GC,. Net 4.0 is background GC)/server (but it is rarely used) in garbage collection ). Of course, if you want to maximize control over CLR, you only have your own host.
CLR, and then call the host API for control, but that is much more difficult.
I would like to admitCLR is adaptive. It can automatically and intelligently identify your needs and then adjust them automatically. But here I mainly think that Microsoft plays the nanny role here. When you are very young, nannies can protect you to a certain extent and avoid harm. But you cannot always live in the arms of a nanny. If you want to become more powerful, you need to go out alone.
Note: This section does not compare JVM and CLR, because I do not have that capability. I just want to see some "invisible things" from the differences between JVM and CLR ".
Developers
The above mainly talks about technical aspects. Now let's talk about people in software development.
My current company interview has a special feature: it will allow the interviewer to do a homework assignment, and then let the company colleague code review. In the past year, I have read a lot of Java code and a lot of C # code. However, I am sad to find that:
1. Although Java also has bad code, Java code pays more attention to the beauty of the Code. Everyone is very careful to select method name, variable name, class name and so on. I am also very willing to write some small, easy-to-understand methods and classes with a small purpose. But most of my dear. Net colleagues are casual in this regard. 200 rows in a method is not long, and even a function is implemented in a method. I can't see the end. Let alone a single class of responsibility.
2. Most Java code tests are conducted. Although some tests are not very good, there are at least several core test functions. But what about. Net code? It is hard to see several tests (is it because vs joined the support for unit test very late ?). I'm not saying we must have a test. I just want to describe this phenomenon.
3. You are too casual. I have seen several. Net codes. I know that you have created a winform project, but you have not deleted the form1.cs and form1.resx automatically generated by.
4. Building is even more problematic from the build level. Most of the Code submitted by Java students has a build script, whether ant or Maven, so you only need to type a command line, you can see the results immediately. The. NET files are basically sln files. This is not to say who is better or worse, because I have never automatically built scripts for. net before. I just want to say that the two communities are somewhat different.
Postscript
I am not here to belittle the developers of a community, nor to drag them into any platform dispute. This is just a phenomenon I have seen, and many others I have not seen, and it is also seriously affected by my colleagues around me, so it is inevitable to be partial.
If you have any shortcomings, please do not hesitate to advise.