views:

6072

answers:

38

I've become very curious lately, what is it about Java that made it so popular? I've avoided learning it in detail because it seems like a very poor language at a very basic level. A good language should make simple operations simple (not too much boilerplate to do something simple and common like loop over a collection, create a helper function, or read in a file, plenty of syntactic sugar) and provide lots of powerful abstractions for when complexity has to go somewhere (think real macros, templates, dynamic typing, good support for multiple paradigms). Obviously, there are some trade-offs between these two, since they basically boil down to doing a few things well vs. handling the general but more complex case gracefully, but it seems Java does neither. Simple operations aren't simple because it's so verbose, generally avoids syntactic sugar, and adopts OOP as a one-size-fits-all paradigm. It's also not very expressive when complexity has to go somewhere, again because it insists on a very one-size-fits-all approach to programming, namely class-based OOP.

I'm honestly not trying to start a flame war here. I'm just very curious what the other side of the story is. What are Java's virtues, other than inertia and the wide IDE/library/etc. support that comes with it? When you make the trade-off of using a language that neither makes simple operations particularly simple, nor gives many powerful and versatile abstractions for complexity has to go somewhere, what do you get in return?

Edit:

I appreciate the responses I've gotten here, and I actually do understand the trade-off now. To summarize, by choosing a language without much syntactic sugar and with only a single paradigm, you achieve a very simple language. This has practical benefits in that the language has very few dark corners, meaning that the implementations are more consistent across platforms. It also means that code is portable from programmer to programmer, since almost the whole language is in the sane subset, and that, because of the verbosity and explicitness of Java, snippets of code are very easy to grok and reason about in isolation. I'm not sure this is a trade-off that I would make very often, but I do now accept the fact that it is a legitimate trade-off and that you do gain something by avoiding the types of features that Java avoids. Thank you.

+18  A: 

Portability. Lanquage is the same no matter what environment your are developing for. One of the reasons .NET is so popular.

Helps save on training and learning costs.

Nick
Further, the compiled bytecode is platform independent.
Chris Noe
Portability is not one of the reasons .NET is popular, lol. Its popular because MS did it, and a lot of shops are MS-only.
gbjbaanb
Do you attribute the portability of Java to the rigidity of the language? Is portability part of the tradeoff, or does it simply compensate for what I mentioned in the original post?
dsimcha
when I can write .net programs for WPF, Winforms, services, console apps, web services, mobile devices, and can run on other platforms with a little help from Mono, and do it all in a multitude of languages using the same BCL...I'd call that portable.
Nick
It is portable until MS decides to kill Mono. Also Mono is always way behind the official .NET release. I would say Java is portable...
Cervo
@Cervo - why are you still rolling out the same old FUD. It's be political suicide for MS to kill Mono. Mono has its own libraries and is based on ECMA standard, kinda hard for MS to roll that back now.
Kev
The team working on C# (and I assume the breadth of .NET) actually talks with Mono developers. There are reasons Microsoft put the .NET spec out there for people to see even if they won't share their source. One of which is, that it makes the "cross-platform" argument plausible.
akdom
@Kev C# is an ECMA standard, not the .NET libraries... I don't think MS will kill Mono, but they can (they no doubt have enough patents). All it takes is an executive or CEO to decide they need to get better lock in to windows...
Cervo
@kev I changed my answer below. I'm not trying to spread FUD about Mono. I'm just acknowledging that it carries some risk, even if it is 1%. Obviously if you are a big MS customer or even a Novell customer you have nothing to fear. But if you are not the possibility is there....
Cervo
@Cervo:every corporation has the capability to pull the plug out with regard to whatever OSS project they may be sponsoring or collaborating with. Specifically singling out MS gets boring and there's a place call /. for all that kinda thing. I kinda like to think SO is immune to this kind of thing.
Kev
+1  A: 

A clear, well organised specification.

Liam
+19  A: 

No pointers or gc worries, strongly typed, portability, easy intermediate level language, powerful enough to be competitive with C++ for the average app.

Josh
Compared to C++ java is a huge step up for many of these reasons. .NET had the advantage of learning from Java.
Cervo
Java had Perl to learn from.
J.J.
I am grateful to our Java overlords for not learning about $_
Cervo
If you REALLY care about performance (i.e. a console game or database) you would never choose Java of C++, Garbage COllection kills performance
David Frenkel
Garbage collection kills predictability. GC is an easy way to increase the throughput of an application without putting too much work (the hotSpot VM GC is implementing the 'memory-arena' pattern for the young objects which reduces mem fragmentation and heap compaction times)
ddimitrov
+11  A: 

Well, Java did have the biggest marketing push of any computer language ever. Even people outside the industry heard about it. It was billed as the "Language for the web" in the midst of the dot-com boom, so many people felt compelled to learn it.

The monopoly suit against Microsoft was in full swing, so "write once, run everywhere" sound like just the thing we needed. Of course, within a year, I was hearing talk that "Java on the client is dead; the future is Java on the server!" But, server-side platform are usually stable enough that cross-platform support isn't that important.

James Curran
I believe you got it backwards: client-side is much more stable - it means x86 Windows. While with the server you theoretically have more direct control, the choice of platform is subject to a lot of technical, business and political considerations that can shift. Having the option to easily switch from an x86 Windows server to Linux on a zSeries mainframe is very, VERY attractive to companies.
Michael Borgwardt
+14  A: 

Originally Java was hot because it offered managed code/garbage collection, treated new technologies such as the WWW as a first class concepts, and it promised build once run anywhere (tm) among other reasons.

Nowadays it is chosen for toolset, language/library maturity, and framework maturity.

Daniel Auger
+50  A: 

1) Looping over a collection:

for (ElementType element : collection)
{
    // Do stuff
}

Hardly tricky.

2) Reading in a file - if you just want to read a whole file in one go as a byte array or as text in a particular encoding, it's pretty easy to do that in a method once and then call the method from anywhere else.

3) Helper functions - if you're referring to the pretty poor support for closures in Java (anonymous inner classes are ugly as heck) then I agree. However, writing a utility method is pretty straightforward.

Yes, I'd like more syntactic sugar in Java - I think C# has done a marvellous job here, particularly with C# 3.0. But Java is still a pretty simple language to work with, IMO - and it's portable, has a huge library behind it (both the standard libraries and 3rd party ones), and performs pretty well, particularly on the server side.

I think it's an exaggeration to call it "a very poor language at a very basic level." It could be better, sure - but so could many languages. It's proven itself as a good work-horse for many developers. I don't recall anyone ever claiming it to be the ideal language for every task, but it's pretty good for an awful lot of them.

Jon Skeet
Jon, it's *clearly* the ideal language for every task :)(Kidding)
MetroidFan2002
Clarification: When I mentioned helper functions, the point was that Java doesn't allow free functions. Therefore, you either write a class whose only reason for existing is to hold your helper function (requires boilerplate) or you put it in a class it really doesn't belong in (just plain bad).
dsimcha
What exactly do you mean by a "free function" though? One which isn't part of any type at all? Like a global variable, but applied to a function instead? If so, I'm glad you can't do that. I like the fact that everything belongs in a type. I'd still like closures though...
Jon Skeet
I bet he was talking about lambda functions. Something that Java will probably support at some point.
carson
Jon: as they say, if Java were a car, it would be the 4 door family sedan :)
Alan
+1  A: 

As Josh said, no pointers or manual memory management is a big plus. But another huge factor is the rich set of standard libraries (for example, knowing that your Swing app will look and work the same in any environment is very helpful, even if you think Swing is ugly).

Michael Myers
+15  A: 

It was there at the right place and time. It felt like C, but with built-in memory management and OOP. That, plus the "write once, run anywhere" angle, was the perfect sales pitch at the time. And Sun made a serious sales pitch.

If Microsoft had started its .NET efforts at the same time Sun was working on Java (rather than five years after the fact) we'd all be coding in C# right now.

savetheclocktower
Only if MS (and other companies) had put the same amount of effort into making it cross-platform. For me, that seems the biggest barrier to the more widespread adoption of C#, despite Mono. Of course, there's anti-Microsoft paranoia and "stick with an existing investment" (latter is reasonable) too.
Jon Skeet
It is in Microsoft's best interest to release the newest and best stuff for Windows. It is in Sun's best interest to release the newest and best stuff in Java and get it into all their ports. I prefer sun's interest.
Cervo
Isn't everyone already "coding in C# right now"...!!
Tall Jeff
@Jon I'm not so sure. If C# had hit the market at the same time as Java it's very possible that the Windows platform would have become much more dominant than it is today. That's rather academic though since web dev. on windows has only really worked well within the past ~5 years.
Wedge
@Wedge: I don't buy it. There are still plenty of big companies who really don't want to run their servers on Windows - I don't think C# would have changed that.
Jon Skeet
Sun had a Java VM for their own operating system and for the most popular OS, and had other OS vendors write their own. Microsoft did exactly the same thing with .NET (except "their own" and "the most popular" was the same OS)
James Curran
Microsoft started .NET because they were not allowed to take over Java. Look at the history for Visual J++ - http://en.wikipedia.org/wiki/Visual_J%2B%2B
Thorbjørn Ravn Andersen
+3  A: 

not too much boilerplate to do something simple and common like loop over a collection

for(String name : names) {
  System.out.println(name);
}

That doesn't get much shorter.

But I do see your point. Java does a lot, but it's not the best for everything.

Java has LOTS of advantages, which has been discussed MANY times before. I agree that some stuff (like reading a file) is more complicated than it needs to be, but that rarely makes any difference to me.

Only when working on a very small project is it annoying. So either make (or use) a library of convenience methods, or use something else for small projects.

myplacedk
Fair enough, I was just giving canonical examples, rather than pointing out what Java is particularly bad at. It does still require tons of boilerplate to get anything done in Java,though.
dsimcha
How can you insist on that, while you are pointing out that you don't really know it? I work with Java every day, and the only boring "boilerplate" stuff I notice is getters and setters. I can live with that. Other than that, it's no problem when you use Java for something it's good for.
myplacedk
Throws declarations? The requirement that everything be declared inside a class no matter how little sense it makes? No operator overloading? No passing functions to functions unless you simulate it with interfaces? No static type inference?
dsimcha
Most of that is what's good about Java. It sound more and more like you just want to use it for something where a better tool is available. Java is great, but it's not a golden hammer.
myplacedk
Don't understand where these would be good things. They all make common use cases much more direct and readable, since you have to slog through less boilerplate to find the important parts of the code. What's the advantage?
dsimcha
That is a huge question, not something I can elaborate in 300 chars.
myplacedk
A: 

I think it was a lucky combination of factors - it appeared when the web was in its infancy and became known as a web-development language. Suddenly everyone wanted to do web dev, and java was the language that either promoted it, or provided an excuse for it.

Its platform-neutrality helped, as non-MS based companies realised it could reduce their development time, when they had to support their unix platforms as well as Windows, and I guess it just grew from there.

gbjbaanb
A: 

It provides multi-platform, memory management, and wide applicability from console applications to large-scale web applications. It was also the first to provide features such as embedded applets in the browser. Also, because of it's early success, a lot of developers know the language.

Turnkey
A: 

When .Net first came out, it was regarded as risky by many CTOs. Java was already around, and was proven. So, one conservative approach was to go with Java. In fact, I was working for a large company that took the leap into .Net. Its cross-town rival said "no .Net, stick with Java".

Today, both companies have huge installed bases of desktop and web apps in their respective languages. It would be hugely costly to convert existing apps to another language for not much benefit. If they wanted to start coding all new apps in the other language, they would struggle with supporting legacy code in the other language. So, each continues with its chosen language. Neither has a problem hiring competent developers in their respective languages.

So, it's partly a matter of momentum. Or inertia.

Initially, the company that went with .Net said "no C#, only VB". While that may sound humorous now, they were worreid about being stuck with a bunch of code in a failed language that they couldn't hire developers for. After a year or two, they switched, so that all new development was done in C#. The legacy VB code was left alone. For a C# developer, it isn't that hard to maintain VB, if you can just stop that twitchy pinky from adding all those semi-colons at the end of every line.

DOK
+3  A: 

It's great as a teaching language because there's so little magic but such strong consistency. Magic scares new people away and clouds the learning process, at least when you're trying to do it in a formal class environment.

Jim Puls
+11  A: 
  1. A Huge library.
  2. Write once. Run everywhere. (it's not simple as that, but it can be made with two or three little modifications)
  3. No memory manipulation.
  4. It's simple. If you want to make simple tasks you can do it with your favorite script language.
unkiwii
+6  A: 

If you weren't around for all the Java hype in the 90's, this hilarious article may help . It was written by Billy Hollis, renowned VB guru. It's the history of C languages.

To be fair and balanced, here's his other hilarious article skewering VB and VB.Net. It's the history of BASIC languages.

DOK
Yeah, I only know history from books/old webpages,not from memory. By the time I started programming somewhat seriously, "new" languages like Python, D, and Ruby were on the map.
dsimcha
+4  A: 

Java has one thing going for it that C++ and Perl also have: it's old. Alright, so it's not "old" in the same sense as Fortran or Lisp, but Java had a huge launch and was around for years before .NET arrived, just as Perl was around and had a user base built up before Python or Ruby matured. So if you're wondering why so many people originally chose to use Java instead of C#, Python, PHP, or whatever, the answer may simply be that C# and Python didn't exist at the time (or at least they didn't exist in a stable, popularized form).

Parappa
+45  A: 

Syntactic sugar, macros and "powerful" abstractions are all good if there are a lot of highly skilled coders to use them. In reality most programming is done by less skilled mortals while gurus handle the really hard stuff. Java is about as simple as programming language can be, so it is possible for a company to have hordes of adequate programmers to do simple coding tasks.

Another thing about having a simple language is that there is good chance most people will use it the same way. With more complex languages, like C++, people end up using some subset of all possible features and may have difficulties understanding each other's code.

From what I know about Java, I have the impression that most of the verbosity comes from "enterprisey" frameworks. Most things in Java would be simple if there was a simple API for often needed simple things.

Bloodboiler
Amen. I think Java has acquired a really bad reputation for verbosity thanks to many people using overengineered but still overspecific frameworks. It's bad when people need to use the term "POJO" to refer to a normal, non-bean, non-proxy, non-whatever Java object!
Zarkonnen
Nah.. If just reading from a file requires stacking 3 classes, then something is very wrong on the basic level.
bart
Having come back to Java after 2 years of not working in it, I can tell you that it's definitely not just a reputation. I keep missing stuff like closures and property syntax...
Vojislav Stojkovic
I work mainly in Java - writing additional code due to lack of syntactic sugar is not nearly the biggest time waste for any project I've worked on. The OP and his chosen answer (this) misunderstand that code complexity is not necessarily a language virtue.Aside, I wonder whether language interpreters ask why they use English. After all, it's not phonetic like many European languages, it's inconsistent, and inefficient, some Asian language can fit words in a single symbol (or possibly they are a bit more pragmatic).
Pool
@bart, if you want to separate buffering streams from actually physically reading from a file, you have to put them in separate classes. I think the Reader/Writer and OutputStream/InputStream concepts is well contrieved and implemented.
Thorbjørn Ravn Andersen
absolutely. I find it annoying too, but I understand why it's that way for flexibility.
John
I'd say that this isn't the reason, because other languages (C# for example) are just as easy to code in and actually are nicer.
RCIX
A: 

Java is much better object-oriented language than C++. Pick up a design patterns book, and think about how to apply it to your code design. It gets tricky.

C++ is missing a concept of interface in its intrinsic language construct. Of course, you could get around it using Microsoft COM. But uh-oh, it's Microsoft-platform specific. C#? I like C# better than Java, because C# has much more convenient language constructs. But uh-oh, again, it's Microsoft-platform specific (Forget about Mono), and it's hard to find quality open-source libraries.

I won't go so far as to compare Java to Python, Lisp, Perl, Haskel, etc.

yogman
Wrong: c++ has classes with pure virtual methods which function *exactly* like interfaces. If you inherit from a class with pure virtual methods, then it is a compiler error if you do not implement them in the subclass. no COM required at all.
Evan Teran
Why do I have to forget about Mono?
John
+76  A: 

Java Vs .NET

Price - .NET has tons of licensing associated with it while Java is under a more free license

Cross Platform - .NET has Mono but it is typically far behind Microsoft .NET and does not have the entire .NET library included in it. Also Microsoft can kill Mono at any moment. They probably will not but the risk will always be there....Java has ports in multiple platforms and encourages more ports. The java library is usually ported to various platforms almost in its entirety. Also many of the ports are out almost immediately.

Java Vs C or C++

Garbage Collection - This is a pretty big advance and saves development time big time. I don't think this needs more explanation.

Huge standard library - In C and C++ you need libraries to do almost anything useful. Load XML? Get a library. Regular Expressions? Get a library. Cross Platform GUI? get a library. Not all libraries are available on all platforms and it is not unusual to use one and suddenly have it stop being maintained and have to switch. In Java the standard library is huge. It includes data structures, GUI libraries, xml libraries, web libraries, networking libraries, regular expression libraries, etc... Now with Boost C++ gets some of these things in a cross platform way but even C++/Boost is lacking compared to Java's library....

Cross Platform - It is much easier to port Java than C and C++. I don't think this needs more explanation.

Java VS Perl/Python/Ruby

Speed - The complaint against Java used to be speed. Compared to C and C++ it was slow. Still for most business apps this really didn't matter. Now Java tends to be very close to C in speed. Still for most business apps even Perl/Python/Ruby are fine though they are sometimes 20+ times slower than C. Java is sometimes 4 times slower than C or less. Basically an order of magnitude improvement.

The Library - I know both Perl/Python have huge libraries. I'm not 100% sure about Ruby but I'm sure that one has a big one too. Perl has CPAN as well. But in terms of standard library it is hard even for these language to compete with Java. In Python/Perl TK is included as a standard GUI library. Java includes Swing, AWT (and now I think SWT too). Java includes concurrency libraries, web services libraries, xml libraries, etc. all built in. Java also includes enterprise frameworks, sound, graphics, etc.. I don't think I have found a language with a bigger standard library yet. But with Perl/Python/Ruby I think this is less of an issue with data structures and other more standardishy things. Still the java library is tough to beat. And it is all pretty efficient.

Also when comparing with .NET don't forget that .NET was founded after Java and to a large degree copied much of Java. It also had the benefits of learning from many of Java's shortcomings (I would take delegates over nested inner classes 10 out of 10 times). But compared to what else was available at the time Java was revolutionary. Compared to C and C++ it is much more productive to built an enterprise application in Java. Although with Boost and other great efforts C++ (including the newer ISO standards) C++ is slowly catching up. But C and C++ are so powerful that it is easy to shoot yourself in the foot. The garbage collector has such a huge productivity advantage in programmer time.

I think now with processors becoming more powerful the speed issue of C and C++ versus Java is becoming even less important. Also there have been many advances in Java technology (like the Just In time Compiler). Someday the speed difference between Python/Perl/Ruby may become less important too. When that day comes then maybe there won't be a reason to use Java now. But until it sometimes speed necessitates Java or .NET (or C++/Common Lisp/anything on the level) and Perl/Python/Ruby just don't cut it...

** ABOUT MONO **** It has come to my attention that I seem to have offended people saying Mono might be a legal risk. My point is not that MS is planning to shut down Mono. It is that the possibility exists. C# is an ECMA standard but not the .NET libraries. Also Mono is catching up with MS .NET, it has made good progress and Microsoft has warmed up to it as well. But the fact is that MS and Mono are in a business relationship. And that is subject to the whims of people at business. If tomorrow MS decides MONO is enemy #1, they may be able to kill it. Even if they cannot kill it, they can develop a lot of stuff for .NET and not share the technical details with MONO. Remember how long it took MONO to get winforms implemented? I'm not knocking MONO. They made great progress. But still it took a long time to get MONO up to speed. Without MS help adding their new features will take time. Also ADO.NET, ASP.NET, WinForms are not ECMA standards. There is a patent agreement not to sue Novell customers. If you aren't a Novell customer then there is no agreement. I'm not saying you will get sued. But I'm saying that it is a risk (even if a 2% risk). And to deny that is to be stupid. At the same time most windows developers are using ADO.NET to talk to databases, WinForms to create GUIs, etc.. So you really need those technologies to port most normal applications. That's what is great about Java. JDBC, AWT, Swing. There is no dark cloud.... Again I mean no disrespect to Mono. I think they have made great progress since the early days. Compared to when it could only compile a little C# and most of the .NET library was not implemented to now where it has many features of .NET 3.0 it is a HUGE effort.

Also, if you use MONO and make your GUI in GTK and stay away from the less controversial API's then you probably have 0 legal risk even if you are not a MS or Novell customer. If I developed in Mono I would probably use winforms and ado.net because that's what I use in Microsoft environments at work. But admittedly I could just GTK. And not worry.

Cervo
Microsoft can kill Mono at any moment? It's open source, and the source code has millions of copies? Who exactly do you sue to kill Mono? If they have a successful lawsuit against one company, the offending code will be removed and the project will continue, or get forked. It's not owned by Novell.
postfuturist
It's true, but who will fork it. The fact is we don't know. Also if I am a small company and they sue me out of existence that is bad. With Java I don't need to worry about that. Also the offending code may be ASP.NET, WinFORMS, and ADO.NET which are needed for interop...
Cervo
I am not saying MS WILL kill mono, only that it could kill. Or at the very least severely hurt it. The chance may be 1%, but it is there. MS could get a new CEO who suddenly decides they want everyone locked into windows. With Java (c++, lisp, etc.) you are not dependent upon their good graces..
Cervo
Also I'm not sure the full extend of Mono's deal with MS. But if now they see the MS source code (instead of reverse engineering like they used to) that creates other legal issues too. As far as I know the patent deal only covers Novell customers (and I'm sure MS customers are covered by MS).
Cervo
Anyway my point is not the death of Mono. It is that for Java cross platform is a top priority. For Microsoft Mono is not a MS top priority. It is in Java's interest to be cross platform (and if MS sues someone over Java to protect them with Sun patents). For MS lock in is better.
Cervo
It was a long time before Mono got support for Mono supported winforms. It started with just a C# compiler before adding VB. After MS .NET 2.0 came out, it was a while before MONO supported 2.0. Cross platform is not MS priority. Mono is great and they are brilliant to reverse engineer.
Cervo
But it takes time to reverse engineer things. IF MS stops helping it will take time for even the best developers in the world to reverse engineer MS features. Sun makes it a priority to ensure all releases are compliant with Java. To make sure everyone has AWT,Swing,etc..
Cervo
So I'm not saying quake in fear and avoid Mono like the plague. I'm saying for me these issues manner and they are reasons that I would pick Java over .NET.
Cervo
Licensing? for .NET? I don't recall paying any licensing fees for the .NET based apps I've launched.
jcollum
jcollum - I notice your questions seem MS centric so you are probably not talking about MONO. Basically (excluding expresses) you need to buy VS, Windows, and any other MS tech you use. Even with MSDN the deployment server is often licensed differently. So that means Windows at least...often more
Cervo
Also as Visual Studio is upgraded you need to buy the upgrades from Microsoft or be a MSDN subscriber (which means you pay anyway) to get the updates. VS.NET, VS.NET 2003, VS.NET 2005, VS.NET 2008, etc...With Java you just visit java.sun.com and download the next version.
Cervo
Visual Studio has always had a fully functional free version and you've never had to license anything to write a windows app in .net.http://www.microsoft.com/express/vcsharp/
Echostorm
Echostorm - Did you not see the page http://msdn.microsoft.com/en-us/vstudio/products/cc149003.aspx which lists the limitations of the express editions? I also remember something about not being able to connect to non local machines with databases in in VS 2005 (maybe that is gone now?).
Cervo
@Cervo, you posted that ".NET has tons of licensing associated with it while Java is under a more free license", which is untrue. You cite that the IDE and MSDN subscriptions are not free, but those are *not* the .NET framework. You do not have to license .NET apps. What is a "more free license"?
JoshJordan
+2  A: 

Now the latest thing is that I like the idea of the Google Web Toolkit. Writing Javascript is cumbersome because of all the different web browsers. Google Web Toolkit seems like a huge advance in abstracting away these differences.

Also the android platform for mobile phones has some stuff in common with Java. It's not fair to say it is Java. But java knowledge definitely helps to program for android. Before this, many mobile phones already were running the embedded version of Java.

A lot of places make Java libraries that do stuff. So it may be worth learning Java so you can use some of these libraries. Google Web Toolkit has me particularly excited....

Cervo
+3  A: 
  1. Spring Framework
  2. Maven
  3. Apache Commons (and similar)
tunaranch
+1 for apache commons. Almost every little thing missing from standard JDK is available here. FileUtils.toByteArray(File file) is just one exemple
Frederic Morin
Frankly, I love Java, but these things you listed only caused me pain (Apache Commons less so). IMO, Java would be better off without them.
Rogerio
So don't use them. Then you _are_ 'without them'.
John
@John: The same argument can be made on e.g. C++ features: "Just don't use them if you don't like them".
Sjoerd
@Sjoerd: that's a vacuous argument. Spring, Apache, etc are library frameworks not part of the langauge; Maven is a build tool. That's not the same as not using a language feature, or even the same as discussing the standard libraries.
John
+8  A: 

Well I think it was a language that allows enterprise applications be developed very easily.

Back in 1997 - 2000 only UNIX servers were very very reliable and at the same time flexible. We had mainframes but the programming language was hard to upgrade. And windows OS well... everybody knows what was the state of Windows 10 yrs ago in the server ( today they are very competitive )

When a solution ( perhaps C++ or Objective-C ) was created, it was first programmed on a PC and then recompiled on the server for the specific architecture ( AIX, Solaris , etc ) That process was very very risky, since the build may fail, or a lot of flags has to be configured in the build file ( make )

With Java all this change, now the binaries built on the CPU may run unchanged!! And this is true. No recompilation, no nothing. You just upload the jar ( or later the war or ear etc ) A lot of pc's may be used for the developers and a 10 CPU's server monster with up to ... ( heard this ) 8 gb or RAM ( he he ) was used to production.

Java was popularized for applets, that's correct, but never did it well. The fact that everyone created it's own JVM implementation was the main reason of the failure, thus "Write once debug everywhere" raised and applets never came very far as was initially though. But he conquered the server-side.

Of course, .NET appear years later, with the CLI and a new language C# came into play, but it was only after Sun sue MS that they came to this great idea. Nowadays .NET is a very good platform to enterprise systems, and Windows Server is as reliable as most UNIX servers, but IMHO C# & .NET is like a MS evolution to the Java environment it self.

Everything you said of java may sound strange nowadays, when languages like ruby, python, C# and other are much more flexible. But at those days, java was like a oasis for C++ developers, very dynamic, very easy to work with and with to promise ( now concreted ) of run very fast, that was the reason types as , int, char, double etc where primitives and not objects.

Years have passed and java is in very good shape. Its slowness ( mainly attributed to client side applications ) is not longer a problem ( but the bad reputation still exists). New technologies arose , and now a 10 CPU's machines with 8 gb or RAM is very very reachable for any of us ( Actually kids game consoles have this much power ) But java was already popular and I think this will be true for at least another 10 yrs. That doesn't mean .net platform won't be better in the same time.

OscarRyz
Geez, that's the anwser I wanted to make. +1
e-satis
Sjoerd
+2  A: 

I've avoided learning Perl in any detail because there's so much syntactic sugar it's impossible to know where to start. I'm extremely skeptical of languages that hype themselves up based on syntactic sugar.

When you write C++, you're really writing assembler. This leaks through into the basics of the language's design -- inheritance and virtual functions are a big one, let alone memory management. This is a big reason why C++ is fragmented into different toolsets (Visual Studio, GNU, Intel, AIX...) and never seems to get the traction for IDE and tool support that Java and C# have. Factor in the preprocessor and all bets are off. I write C++ at my day job and I enjoy it, but I'm well aware that I'm writing assembler code and I use assembler-level tools to debug it.

Now, Write Once Run Anywhere is just wrong for a lot of Java applications. Write a business application that does any real work and has a GUI, and you're locked into one version of the JVM. Look at all the shops still running Java 1.4.2. I still target 1.4.2 as the de facto "standard" for any Java code I write. You might be able to migrate between different environments running the same minor version of the JVM, but that's not always guaranteed either. A lot of that's down to sloppy code, but not all of it.

Tools matter. Inertia is a huge deal, the code base at any shop quickly outgrows the number of programmers assigned to maintain it. I don't love Java for its aesthetic virtues, but I use it because I know it runs on the vast majority of machines, and other people with basic OOP knowledge can maintain it. If you need Java code to do something, write an API with classes and interfaces to do it. I'd rather use an API for stream and file I/O than rely on syntactic sugar that gets exponentially more convoluted as you need more options. Most people can't write good APIs, let alone handle more complex language features.

twblamer
+13  A: 

The great thing about the Java platform is that you don't have to program in Java!

postfuturist
+1  A: 
Brandon DuRette
+6  A: 

Readability - the language is simple. There is no operator overloading, which makes (most?) use of operators intuitive. General use tends towards verbose and meaningful identifiers, which further enhances readability. C syntax made it approachable in the early days.

Writability - Garbage collector. Decent compiler error statements. Built in stack traces make for easy debugging (at least on some level - big up vs C/C++, at least in my bumbling experience with the latter). Array bounds checking, and all those other dinky little improvements from C/C++.

Documentation - the documentation system is STANDARDIZED AND BUILT IN. It's also pretty dang decent. The javadocs are easy to generate, present well, and don't explicitly require the programmer to document his/her code (not that I know of anything that does). Further, the standard library is very well documented. Couple this with the tendency of Meaningful Identifiers and other design patterns, and Big Code can become fairly accessible even with crummy documentation. Really, I'm surprised this hasn't been mentioned elsewhere. Maybe everyone takes it for granted. I sure did. Then I learned XXXXXX (censored to prevent flames - but take your pick: I really think java's documentation shines versus other languages').

Libraries - the standard libraries provide a very solid base. Discussed elsewhere.

Openness - Open source (kinda, sorta, not really, never mind..) The specs are open, the standard library sources are open, etc. The fact that the standard edition came cerveza libre for desktops probably didn't hurt. (And I know that Sun has opened up the jvm more recently)

Portability - enough said.

Scalability - Huge applications are more practical/easier to write given OOP et al. Why do you think good IDEs exist for java?

Marketing hype - this one definitely doesn't hurt an objective of massive adoption, and was probably more responsible than the technical details. And right away, its C syntax targeted an already large community. Anyways, it's been discussed elsewhere.

Really, I'm probably about as perplexed as you are about the adoption of java. It is annoyingly verbose and definitely not well suited to key areas (scripting, intense numerics, to name a few). However, holistically, these are fairly minor concerns given all the advantages enumerated here and elsewhere. I find I can approach huge units of code in java without my eyes bleeding (okay, I only tried this once in C++ and quickly gave up).

Ellery Newcomer
+1  A: 

Great code reflection and introspection. Makes it far easier to share libraries than uisng DLLs for example.

Hans
Now we're talking. I'm only vaguely familiar with Java's reflection API, but I guess that actually does fall under the category of "powerful abstraction," since a good reflection API can be used to implement duck typing.
dsimcha
.NET DLLs are just as easy to reuse. Not to mention the Global Assembly Cache..
Andrei Rinea
A: 

I personally believe that explicitly-typed languages make it easier to develop large-scale systems in a corporate environment. If you want a completely type-safe, explicitly-typed language that is object-oriented, has built-in garbage collection, and is cross-platform, then Java is one of your only choices.

Granted, there are many software tasks that do not require type-safety, or an OO language, or garbage collection--but if you're looking for a language with all those features, Java is one of the strongest contenders in that space.

Ross
A: 

You answered the question: "inertia and the wide IDE/library/etc. support."

Some time ago the New Yorker magazine noted that New York city, a hotbed for finance and publishing was still thriving. They asked the question why that would be true in the digital age which made "location" much less important. Their answer was simply: "that's where the people are".

Java gained market share and inertia because the promise(real or perceived) of "Write Once Run Everywhere" coincided with the dawn of the internet. Now people use Java because that's where the people are.

Oh, and without pointer syntax it's safer than C++.

+2  A: 

I think it mainly comes down to the history of the language - you need to understand its history to understand how it became popular. It still retains popularity as a result of that initial momentum. There are various factors.

Java became popular in the late '90s, when the majority of software was written in C/C++. Even if you're a fan of C++, you have to admit that it is, overall, a fairly complicated language because of the number of features that it incorporates. As a result, it's a difficult language to master; Java, by comparison, is much "cleaner" and easier to learn. C++ is also plagued by a number of common problems, all of which Java solves. These include: lack of bounds checking for arrays (leading to buffer overflow attacks), manual memory management (leading to memory leaks and crashes from double frees) and the fact that portable software is difficult to write (Java provides a platform which is intrinsically portable - mostly, at least).

When you take all of these into account, Java came across as a much "cleaner" language and was especially attractive to universities teaching introductory programming courses. When I was at University (2000-2004) all programming was taught using Java, for example. This has a big influence when those students go out into the real world to work.

Nowadays there are a number of common languages that have become popular, and - importantly - acceptable to managers, to use. These include Python, C#, Ruby, etc. At the time that Java came out, though, none of these were popular or well-known enough to be accepted for use in serious software.

You should also factor in the influence of the web. I remember back around 1999-2000, there was a lot of "buzz" around the use of Java applets - small Java programs that could be embedded into webpages. Nowadays, it's incredibly rare to see Java applets used. Microsoft even removed the Java VM from IE. Back then, the fact that Java was available inside all of the major web browsers was a pretty important thing.

Finally, it's worth considering the fact that Sun put out a big marketing campaign for Java, which helped to cement its reputation among both programmers and managers. Plus, the fact that it was developed by a big company like Sun helped to give it some credibility.

So, I agree with you that there are things that are annoyingly complicated to do in Java (although it has improved over time). The fact is, though, that people continue to use Java now because it's already popular, and it became popular because 10-15 years ago it was, in many ways, a lot better than many of the other options available.

Simon Howard
A: 

For me, it is not just the great strict type-system (I personally hate the weakly typed languages), but the development tools. You would have to prey IntelliJ out of my dead cold hands. So far, Microsofts VisualStudio is just inferior to the refactoring power I have with the team of Java/IntelliJ. This is largely to blame to the strange text manipulations the C/C++ system enforces by the #define macros. For computers, this stuff is next to impossible to comprehend and so they cannot support me writing code fast.

Yes, Java is more verbose, but that is offset by the fact that Java is easier to debug, the libraries are clean and the language is simple without any evil taps (until JDK 1.5, that is. Auto-Boxing and the way generics are implemented are a different dark chapter).

A: 

java is so popular because everything is already available via vast libraries and we just ought to use the methods defined in classes to achieve our goal .

arshad
+1  A: 

I would add more two advantages:

  • Open Source
  • Community suport
Skubs
Equally valid for C++.
John
+2  A: 

It depends whether the question is about Java, the language, or Java, the technology. The discussion so far seems to have focussed on the language. Although the Java language has merits of which many are arguable, one of the main reasons for choosing Java as a language has little to do with any of that.

Until recently, and ignoring "off-beat" technologies, Java was the only readily available language for accessing Java technology. This has changed recently and is likely to continue to change as other languages become available.

By "Java technology", I am referring to the facilities involved in the Java Virtual Machine executing Java bytecode. This underlying technology is not dependent on the Java language in any way - you can generate Java bytecode by other means - although the Java language compiler is a good choice because it is likely (guaranteed?) to generate verifiable Java byte code.

So - why do people use Java technology?

Some advantages have been cited here: portablility, garbage collection, library coverage, speed (yup!) ... but there are two which seem to be very important and are less often cited.

These are in the areas of: security and deployment.

Security:

The standard of the security of Java is captured well in the preface of the book "Inside Java 2 Platform Security" by Li Gong, et al.: "Java technology is possibly the only general-purpose secure computing platform to become commercially successful. This would never have happened had the designers not taken security seriously from the start. The security properties of Java technology are many, and the Java platform builds on itself to create a reliable and secure platform."

Java is, arguably, the most secure generally available computing platform that we have ever had! This not only means that low level things do not go wrong, but also that higher level facilities can be built on top of it.

But you have to be in it to win it! Hint: install a SecurityManager! That is - as a crude starting point - either: run your program using "java -Dsecurity.manager" or execute at the start of your program "System.setSecurityManager(new SecurityManager());" but not both!

Actually, of course, there is more. Policies need to managed. Also the whole security model is extensible for the programmers purposes.

Deployment:

The fundamental model for network-based class loading in Java is extremely powerful. And it is becoming increasingly valuable in our increasingly connected world.

Perhaps the greatest strength of Java is that it combines excellent security and deployment capabilities in the same technology.

That is the way that I see it anyway!

A: 

Most people will say garbage collection & write once run anyware.

IMO it was the same deeper reason that also made COM a huge success: binary standard and compatibility. Generic C++ has always been plagued by this tiny little detail that few seem to pay serious attention.

That and the ability, because of the VM, for your code to crash without taking the whole proccess down with it. That was crucial for the success of the J2EE as the server and the various applications share the same proccess.

+1  A: 

Java had a big company backing it and was around at the right time. It was a massave advance over c++ do to things like garbage collection and the standard librarys. It gained market share and it's not practical to rewrite all the existing Java code in Ruby or Python even if it may be a better language. SInce Java has so many programmers that know it and has so much existing code it is still used to maintain old programs as well as writing new software instead of having to retrain programmers in a new language.

Jared
A: 

As mentions Skubs (above); Open Source ;)

Look around and you will find a lot of Open Source projects implemented in a multitude of languages or combinations of languages. Picking one language combination; most of the projects written in C/C++ addresses "lower level" problems (compilers, data transformation, etc).

Above anything, Java seems to have become the language of choice for projects addressing "higher level" use cases involving databases with complex schemas; cf. Nuxeo, Alfresco, ...

For what reason I don't know, but .NET is almost invisible in this realm. Maybe it is cultural - people or organizations developing in .NET not contributing to the Open Source community, or the lack of .NET Open Source components implying that most .NET projects may be made proprietary?

Being able to build on existing Open Source products and components is a major reason why Java have become so important, and since there is such a mass of Open Source written in Java it will probably remain so for a long time.

Frode Randers
+4  A: 

It's a "right place, right time" thing. It became popular at the time it was available because of the landscape back in the 90's.

  • garbage collection. No more malloc() and free(). The joy!
  • a net library. The language came plugged into the internet as standard.
  • it fixed the insane C language thing where the number of bits in a primitive type was platform dependent. No more grovelling through include files and preprocessor directives!
  • it supported unicode out of the box. Away with code pages!

It was simply much better than what was already there, and it incorporated new things as part of the language that other languages did as third-party libraries. It's difficult to describe to someone who is used to it how incredible it was that I could develop on a PC and drop my compiled binaries on a Sun box, and they simply worked.

paulmurray