Why should I use Java

Depending on your operational needs, there may be better than the Java language, but I have not seen any language I can away of.

I remember I was using Java since 1997, and in Java 1.1 just released soon after. Since then, in general, I like to use the Java programming; although I have to admit, these days I often like to write "serious code" written in Java as Groovy scripts.

From FORTRAN , PL / 1 , Pascal and finally C language background, I found a lot of things I like Java. Java is my object-oriented programming first major experience. Until then, I have been programming for about 20 years and I can say that what is important and what is not with a few comments.

Debugging is a key language features

I really hate to waste my time tracked by iterative code does not accidentally end of the array to blur caused by errors, especially in the era of FORTRAN programming on an IBM mainframe. Another subtle problem is that from time to time when to call a subroutine, this subroutine with a four-byte integer argument, and is expected to have two bytes; on the small end architecture, which is usually a benign error, but in on big-endian machines, the value of the first two bytes are generally not always zero.

In that batch debugging environment is also very inconvenient, from a core or insert debugging print statements, these statements themselves will move in the wrong location or even make them disappear.

So I'm using Pascal's early experience, first in MTS , and then in the IBM OS / VS1 using the same compiler on MTS, make my life easier. Pascal's strong typing and static typing is an important part of obtaining this victory, I use every Pascal compiler checks for plug-in operation on the metes and bounds of the array, so that errors can be detected in the event. When most of our early work to the Unix system in the 1980s, transplant Pascal code a simple task.

The right amount of grammar

But for what I like Pascal, my code is very lengthy and grammar seems even more than the code; for example, use:

if ... then begin ... end else ... end
复制代码

Rather than C or similar language:

if (...) { ... } else { ... }
复制代码

In addition, some things difficult to complete in Pascal, is easier in C. But when I started to increasingly use C, I found myself experiencing the same types of errors I have encountered in FORTRAN, for example, beyond the bounds of the array. In the original point error is not detected until the end of the array, but only detect them until late adverse effects of the implementation of the program. Fortunately, I no longer live in that batch environment, and do have good debugging tool. However, C for me a bit too flexible.

When I met awk , I found that it compared with C is another kind of way. At that time, a lot of my work involves converting field data and create reports. I found that by awkadding other Unix command-line tools, such as sort, sed, cut, join, paste, command so on, can do amazing things. In essence, these tools gave me a document like text-based relational database manager, a text file with columns of this structure is the way we save a lot of field data. Or, if not this format, most of the time can also be exported from a relational database or some kind of binary format to the column type structure.

awkSupport for string handling, regular expressions and associative arrays , as well as awkbasic characteristics (it is actually a data conversion pipeline), suits my needs. When faced with binary data files, complex data structures and key performance requirements, I would still be back to C; but as more and more I use awk, I found the very foundation of C strings to support more and more orders frustrating. Over time, more often I will only be used only when C, and is widely used in the rest of the time in awk.

Java level of abstraction appropriate

Then Java. It looks quite good - relatively simple syntax reminiscent of C, or at least better than this similarity Pascal or any other language early is more obvious. It is strongly typed, so a lot of programming errors will be caught at compile time. It does not seem to need much knowledge of object-oriented will be able to start, this is a good thing, because I was on OOP design patterns without familiar. But even just the beginning, and I like the simplified inheritance model behind the idea. (Java allowed to use interface provides a single inheritance, to some extent rich examples.)

It seems that with a rich library of functions (that is, the concept of "self-battery"), at the appropriate level directly meet my needs. Finally, I found myself quickly think of the idea of ​​a combination of data and behavior together in an object. This seems to be a good way to explicitly control the interaction between data - than a lot of the argument list or uncontrolled access to global variables is much better.

Since then, Java has become the Helvetic saber in my programming toolbox. I still occasionally in awkthe preparation of the program, or use the Linux command-line utilities (such as cut, sort, or sed), because they apparently direct way to solve the problem at hand. I suspect that over the past 20 years I could not have written 50 lines of C code; Java fully meet my needs.

In addition, Java is constantly evolving. First, it has become more efficient. And it adds some very useful features, for example, can try to test the resource , it can be a good clean up lengthy and somewhat confusing error handling code during file I / O; or the lambda , it provides a function declaration and as the capacity of the transmission parameters, the old approach requires the creation of a class or interface "managed" these functions; or streams , which encapsulates the behavior function iteration, can create efficient data transformation pipeline implemented in the form of a chain function call.

Java getting better and better

Many language designers studied ways to improve Java experience fundamentally. For me, most of which did not cause me too much interest; again, this is more a reflection of my typical workflow, and (more) reduces the functionality of these languages brings. But I have become an evolutionary step programming tools integral part: Groovy . When I encountered a small problem that requires a simple solution, Groovy has become my first choice. Moreover, it is highly compatible with Java. For me, Groovy Python to fill the same utility offered by many others - it is compact, DRY (Do not Repeat Yourself) and has expressive (lists and dictionaries have full language support). I also used Grails , which uses Groovy offers a simplified Web framework for very high-performance and useful Java Web applications.

Java is still open it?

Recently, OpenJDK growing support to further improve my comfort of Java. Many companies in a variety of ways to support OpenJDK, including AdoptOpenJDK, Amazon Hat and Red . In one of my larger, more long-term project, we use AdoptOpenJDK to generate custom runtime environment on several desktop platforms .

There is no better language than Java? I'm sure there are, depending on your operational needs. But I have always been very satisfied with Java, I have not come across anything that might make me disappointed.


via: opensource.com/article/19/…

Author: Chris Hermansen topics: lujun9972 Translator: wxy proofread: wxy

This article from the LCTT original compiler, Linux China is proud

Guess you like

Origin juejin.im/post/5d7d9bffe51d4561d54dea11