Reprint: Do Java Development this year (Dragon fruit software)

Source: Internet
Author: User

Reprint:http://www.uml.org.cn/success/201410205.asp

From last year to the present, moving from. NET to Java development (just because of project reasons, absolutely not related to the platform or not) almost a year. Through this year time also have some feelings, want to compare these two platforms from a few sides. Hope to be objective and impartial.

Language

I used to use the C # language, compared with the current Java language, the current Java language syntax is stuck in the C # 2.0 era. The grammatical structure is very traditional, very good. The obvious point is that because of the lack of support for closures, some are easy to do in C #, and Java needs to write a lot of nonsense code.

A few days ago, Infoq published an article in the British Guardian's gradual adoption of Scala to replace Java in a good sentence: Look at Java code is easy to let you trees, trees. Because you need too much support code to implement a feature, the key code that implements it is lost.

For example: I need a prioritized list of users, sorted by user name. It's a very simple requirement, no. The natural code must be this:

Ilist<user> users = ...
Users. user = user. Name);

And if you implement the same functionality in Java, you might want to write 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 the use of static auxiliary classes

Second: Without the support of closures, it is not to write an ugly anonymous class

In fact, we only need an order by order, a look at the understanding, but now more than so many "useless" code, but the core of the value of (the) is not so important. This is a very simple example, in the actual project you will pay more price, you have to write a bunch of bland code to achieve the function you want, and that function is actually very obvious.

So at the language level, Java does not have any bright spots, just feel gibbering.

On the language level of comparison, Lao Zhao wrote a lot, and very exciting, suggest to enjoy.

But Java also has a little bit of little meaning: like static import (the mind reminds me that this thing is very early in VB), and Java's special support for annotation allows us to do a more interesting thing.

Concept flying

In Java, what struck me most was the idea of flying around in the Java world. ORM,IOC,AOP, these few are. NET in the world, but have not seen such a strong, but if you do Java applications, you are not familiar with these few you are embarrassed to go out to greet people, so in addition to learning Java itself there is a lot of open source framework waiting for you to study.

What else is the View model,presentation Model,validator,bro (Business Rule object), the BPO (Business Process object), BDD. The key is not only the concept of the existence of such a noun, it is also a large number in the code. The code describes the concept in its most vivid and orderly sense. Maybe my old hat, I developed. NET three years, never the whole thing. But I have no doubt that my code is difficult to read and difficult to maintain.

Configuration file, can you get a little more?

I'm super-disgusted with spring's configuration file (although you say it's just a framework, it looks like the Java community has this trend). Although spring now adds support for annotations (Annotation), there are a number of configuration files in the project that are known and not known. And for "modularity", a small configuration file contains several configuration files. There are configuration controllers, with configuration DAO, with Configuration service. Well, there's the damn hibernate hbm file. I think the complexity of the system is the accumulation of such 1.1 points.

Asp. NET profile has been a trend that has become more bloated at one point, but in the end it was much thinner (the default Web. config in. NET 4.0 was small). and attribute in the first version of. NET, many configurable things provide attribute API and XML API, so there is no history legacy burden.

Open source, I like it.

The open source software in Java is far more than. NET (this may have a certain relationship with Microsoft). If you want to complete a job, there will always be an open source software for you. For example, we want to do a scheduled task, immediately there is a quartz run to your vision, you only need to implement a few interfaces, and then configure in the configuration file (again the damn configuration file), or you are in Java in the same way as in C # to use lambda, There's a man who thinks like you right now. Developed a lambda4j (Java people have a saying is: The language is not enough to fill the library, but the Java language is too weak, so sometimes the class library to fill the wrong). You can find the most suitable one in the wide range of open source frameworks and open source libraries, and then open this Pandora's box. The main thing is that she is still open, you can not only learn its code ideas, if you find that there are problems you can even submit code, that sense of accomplishment I am in development. NET is not felt. For example, you want to develop a high-performance server, in. NET has not seen this kind of open-source projects, but in Java you can learn Netty, you can learn Mina, you can even according to their own specific business scenarios, the appropriate changes to these open source software. Of course, you can say that thought is the same, which is good. But because the IO model is not the same in Java as in. NET, there are a lot of different (of course I think that. NET asynchronous IO is easier to use, and the Java NiO that's what the Crap API is).

Ide

Development must not be inseparable from the IDE. The IDE in NET is a well-deserved Visual Studio. But I think Visual Studio has been a long way from being a developer for years, as if he were going to have a full lifecycle software development tool. So not only bloated, but also not very friendly to developers (of course, her visual designer is unmatched, but I don't think the visual designer is what the developer's "weapon"). Take two examples: The combination shortcut keys are used extensively in vs. This not only makes the shortcut keys too long, difficult to remember, and fortunately difficult to use Ah, you have to press two times, and the time can not be too long. and the refactoring function of VS, it's too weak.

There are a variety of ides in Java, free of charge. One of my favorite is IntelliJ idea. The idea gave me the impression that she was really focusing on the role of the developer (who wrote the code). All the shortcut keys are very simple, good to remember. For example, most of the things in idea can be solved using Alt+enter, the Universal shortcut (the shortcut is context-aware and it knows what to do in different contexts).

And then the idea of support for refactoring, if you are skilled, do a large refactoring you do not have to manually modify what code, directly rely on the support of the IDE can be done, which is very important in the security refactoring, manual to modify the code refactoring if the test is incomplete in the case of the risk is very high.

Of course, the VS also has a lot of very useful plug-ins, can improve development efficiency. For example, the famous ReSharper comes from IntelliJ idea, the same company, from which you can see how idea is concerned about the efficiency of people who write code.

JVM vs CLR

In general, Java runs on the JVM, and C # runs on the CLR. From the technical realization of their two shares, each has its advantages, we can not evaluate their good or bad. It can only be said that the JVM is better than clr,clr on XXX over the JVM on XXX. And the JVM has a lot in common with the CLR, and most things can be found in each other.

So they can't compare? No, after a year of study I say I prefer the JVM a bit.

The JVM (where only assumed to be the Oracle/sun Hotspot JVM) exposes a number of configuration parameters to the developer. These parameters allow you to indirectly control the operation of the JVM. Like the GC, there are various parameters in the JVM to control the size of each generation, and what garbage collection strategies can be used by the JVM with parameters. Because different types of applications: desktop, server-side, memory-small, and so on, different types of applications are suitable for different garbage collection strategies. However, the CLR gives developers only workstation (whether concurrent gc,.net 4.0 is background GC)/server and so little control (though it is rarely used) on garbage collection. Of course, if you want to maximize control of the CLR you only have your own host CLR and then call the host API for control, but that's a lot more difficult.

I would like to admit that the CLR is adaptive, she can automatically identify your needs intelligently, and then automatically adjust. But what I'm here to think about is that Microsoft is playing a nanny role here. When you are very young, the nanny can protect you to a certain extent, without you being harmed. But you can't live forever in the arms of a nanny, if you want to be stronger you need to go out and see for yourself alone.

Note: This section is not a comparison between the JVM and the CLR, because I do not have that ability. Just want to look at some "unseen things" from the differences shown by the JVM and the CLR.

Development staff

The above is mainly about the technical aspects of things. Now talk about the people in software development.

My current company interview has a feature: will let the interviewer do a homework, and then let the company colleague code Review. In the year I read a lot of Java code, but also read a lot of C # code. But I was sad to find:

1, although Java also has rotten code, but Java code mostly pay more attention to the beauty of code. Everyone is very careful to choose the method name, variable name, class name, etc. Also very willing to write some small, easy-to-understand methods, small purpose-definite classes. But my dear. NET counterparts, mostly in this regard is very casual. A method of 200 lines is not long, even a function is put into a method implemented. I can't see the end. Not to mention a single class of responsibilities.

2, test Java classmate Code most of the test, although some of the test is not good, but at least there are a few measurement core functions. But. NET code? It's hard to see a couple of tests (is this because VS is late to join the support for unit test?) )。 I'm not saying there must be a test, I'm just describing the phenomenon.

3, you are too casual. I've seen so few. NET code, I know you created a WinForm project, and then you don't delete the form1.cs,form1.resx that are generated by vs automatically.

4, the construction from the level of construction from the point of view, the Java classmate submitted the code is mostly built script, whether it is ant or maven, so you just need to knock a command line, you can see the results of others immediately. The. NET students are basically sln files. This is not to say who is good who is bad, because I did before. NET has never built scripts automatically, I just want to say that two communities are a little different.

Postscript

I am not here to belittle the developers of a particular community, nor do I want to be involved in any platform dispute. Because this is just the phenomenon that I see, there are many I did not see, and this is seriously affected by my colleagues around, so it is inevitable to generalize.

If there is insufficient place please feel free.

Reprint: Do Java Development this year (Dragon fruit software)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.