Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Java has really come a long way. I'm not sure why it's not hyped more. I guess it's like C++ (another widely used old man's language that runs the world).


It needs no hype. I think 90% of enterprises use it in lot of ways. Pre-hype and post-hype people know Java gets shit done. People who believe in hyped cool functional language which ultimately runs on JVM are not going to listen anyone who claim is Java is just fine for lot of work.


Java isn't perfect but it's the defacto language for anything that doesn't need to be compiled.

I personally really like Java and I've used a ton of languages over the years. Not a perfect design but it's hard to think of any big downsides. The syntax is annoying at times but once you learn to use the IDE to poop out boilerplate it's not an issue


"Java isn't perfect but it's the defacto language for anything that doesn't need to be compiled"

Java is a compiled language.


I tend to group languages into machine-code, VM, and interpreted. This tend to lead to similar tradeoffs within the group...with the exceptions of Golang.

in my mind: interpreted = why would you ever use a language like this? VM = fast, safe, but going to use a lot of memory machine code = fastest, low level HW access, usually unsafe


Also Swift and Objective-C. For some reason people think they are fast because they are compiled. Yes, they are fast so long as you only write C in them. Actually using their features is typically way slower than Java.


> I tend to group languages into machine-code, VM, and interpreted.

This distinction doesn't make much sense in 2017: most languages are blends of all these things with technologies like VM's, JIT, Ahead-of-time compilation, etc...


Underneath they're still divisible. AoT is always native machine code. JIT/VM/Bytecode is VM, basically machine code on demand.

Then there's interpreted code which has worked the same way for forever


Compiled to bytecode, I'm guessing the GP meant compiled to native.


Java is complied to native code, this is just delayed until execution. There are drawbacks like slower start-up performance due to the required JIT compilation but there are also advantages like being able to optimize for the exact machine you are executing on or even recompiling at run-time after profiling the running application and determining useful optimizations based on the actual work load.

A really important aspect of using an intermediate language like Java, .NET but also LLVM does is that it reduces the amount of required code. If you have M languages each targeting N different platforms, then you need M * N traditional compilers. If you first compile to a common intermediate language and then from there to the targeted platform, then you only need M + N compilers.


> advantages like being able to optimize for the exact machine you are executing on or even recompiling at run-time after profiling the running application and determining useful optimizations based on the actual work load

Do you have examples (incl. measurements) for optimizations actually performed by a Java JIT compiler, which an ahead-of-time compiler can't perform due to a lack of runtime info? It is my understanding that those analyses and transformations which eke out the last few percentage points are so expensive that they're infeasible to do at runtime.


The JVMs profile-guided optimisations are generally a 10-20% win for Java and more for Scala, I believe. They aren't that expensive to do. When you get into languages like Ruby or Python it just goes off the charts, you are getting orders of magnitude better performance from profile-guided JIT compilers.

As an example of what they can do, take de-virtualisation. Virtual method calls are expensive. Java method calls are virtual by default. The JVM profiles method calls and analyses the class hierarchy to discover which ones can be de-virtualised. That's a big win. C# requires programmers to manually specify which methods are virtual because .NET doesn't use profile-guided JIT compilation. In some cases (admittedly I've only seen artificial examples) this optimisation is so powerful you can write Java programs that completely trash C++ programs, e.g. a program that uses a command line switch to pick a subclass of a virtual base class and then runs method calls on that object in a tight loop. Java will devirtualise the call based on the observation that only one target is ever used, then inline it, then do loop opts on the inlined version.


I'd say C# makes methods not virtual by default because it's a saner default. When writing a class you shouldn't make everything virtual, that should be a conscious decision to actually design a class for extensibility.


There are many. One really useful one is that final variables will be pulled out along with their dead code branches. Say I have a library which allows different "sizes" of a list. The fastest way to sort that list depends on the number of max entries.

With JIT you can set the size when you create the object, and if JVM knows that value can't change it will pull out all the branches for different sizes and run only the one for selected size.

There's no way to know which sizes will be selected at compile time if the lists can be dynamically created, so a static compiler can never pull out all the checks the list size.

This is a simple example but the JIT is very smart and makes a big speed difference in practice. It's the main reason Java is faster than C in some benchmarks


Inlining of hot, small methods. Call site specialization (for virtual calls, reflective calls and invokedynamic calls). There are others but I'm not an expert on hotspot.


HotSpot does some optimizations based on runtime information [1] but no numbers given here. For .NET Microsoft build SPUR [2] and the paper has a performance evaluation section although I just skimmed the paper and am not sure it contains the relevant comparisons.

[1] http://www.oracle.com/technetwork/java/whitepaper-135217.htm...

[2] https://www.microsoft.com/en-us/research/publication/spur-a-...


IIRC Java Numerics was a dead end precisely because the required optimizations went against the 'write once, run anywhere' ideal. I have heard of specialized Java runtimes that can do interesting things to approximate BLAS/Atlas, but never seen them first hand.

I wanted to cite "Improving Java Performance Using Dynamic Method Migration", Lattanzi 2004, but the site hosting the paper isn't loading at the moment.

-- http://math.nist.gov/javanumerics/


Possibly, just wanted to make sure there's no confusion.


Type erasure

Forcing all objects to be heap allocated which makes things like Optional introduce even more memory indirection because thrashing your cache is totally fine

No primitives in generics which therefore means no primitives in containers

Which then leads to the fun of autoboxing so that way your bools can be true, false, or null!


Over the last few years I have developed templates/scaffolding for my Java projects based on my typical Java usage for small projects. It is mainly inspired by Go and I fear hopelessly outdated. It does not use maven/gradle or any latest Java functional patterns etc. I have an ant build, bash scripts and few Java files.

This whole setup helped me develop surprisingly large number of useful tools and apps which proved successful enough that snippets of my code and pattern are copied in proper 'enterprise class' projects at our company.


I feel like it's coming back as the "just use this" after the flashes in the pan of the last few years. C# seemed like it had a shot at the throne but the ecosystem is in deep disarray these days, tooling wise.


C# is fine if you stick to the Windows ecosystem, the cross platform stuff was released far too early in my opinion.


I agree - even with the VSCode stuff, they're missing their major competitive advantage: Visual Studio.


I use C# at work, the syntax is better than Java but there's one huge issue: good luck getting it to work without Windows and Visual Studio.

.NET core is still very immature, we had to back out every time we tried to use it in production. Maybe in a few years it will be good.

Java on the other hand has support for many IDE's, package managers, web servers, JVM's, OS's. You can swap out pretty much everything, no vendor lock in issues at all. The open source community is far stronger as well. So many times I wanted to use a cool database and found out there's no official C# client


I thought Java was the 'default' language in most companies.


I realky like it as well. I started to use Kotlin lately which interops with Java seamlessly and addresses a lot of Java's warts without wanting to be more than it is: Turbo Java.


- Oracle has hands on it and does questionable things like suing google

- Everything Java does, C# does as good or better. In general for everything in Java you could easily find a better way to do it.

- Java has lots of warts, many to have the language be backwards-compatible. (switch-case, enums, UTF-16 encoding, generics, null, difference between objects and basic types,...)

- Java is tied to old technologies. There are no standard JSON libraries, however even XSLT is included in java se.

- You need to use Java with an IDE. Eclipse is horrible to use (even scrolling lags here) and IntelliJ costs money.

Still java is a mature and solid language. There is just nothing to hype about it.


You must not have used eclipse for a while :) . I use Visual Studio at work and Eclipse at home and they're comparable these days. I agree that years ago Eclipse was awful.

- Every language has switch-case and enums? I don't get what you're trying to say there.

- Generics are fine?

- Every language supports null on objects?

- Nearly every language treats null and primitive types differently for performance reasons

- Java has three popular JSON parsers and they're all faster than .NET's builtin serialization. To get similar performance you need to use Newtonsoft which isn't builtin to C# either :).

- You don't need an IDE, it's just stupid to develop without one because they're so helpful. Nothing is stopping you from running javac on the command line.

You can't do a LOT of things java can do in C# because third party library support pales in comparison. A lot of databases and open source software don't have c# clients. If you're dealing with big data or ML you'll find almost nothing in C# land.

I feel like you haven't used Java in a long time. Things are much better than Java 6 days


Maybe I should expand a bit on my points, as the problems do not seem so apparent.

- Java has the same horrible switch case with the error prone break as C. If you want exhaustive matching on enums you will end up with a useless default case. If you ever worked with a programming language with pattern matching you will feel the pain.

- This might be a bit opinionated but I think enums are not enough. Sum types/tagged unions/variant types/disjoint unions/whatever you like to call them are pretty useful.

- Generics in Java are highly limited. Part of that is because generics were added as an afterthought and are implemented using type erasure. Both functional programming languages like Haskell or imperative programming languages like C++ or Rust offer more powerful generics that can sometimes help abstract things more elegant.

- The problem is that all objects are nullable by default and you cannot specify that e.g. parameters or results are never null. This leads to boilerplate null checking and missing handling of null cases. Everybody that touched java probably saw quite some amounts of NullPointerExceptions. Kotlin for instance offers types that by default cannot be null, with TypeScript this exists if you turn on an option of the compiler.

- You can offer pretty much everything you offer for objects also for primitive types. In fact, this is what Project Valhalla tries with value types and specialisation.

- My comment on IDEs was more about the need to use an IDE being bigger with Java than for instance C, while eclipse is often annoying. I am using eclipse daily currently because I work on some Java code for my Master's thesis.


"IDE being bigger with Java than for instance C "

Really, why ?

I can't imagine working without an ide for any language. Back in the dark days I did html/javascript in notepad.


The big drawback with C# is being handcuffed to a Microsoft ecosystem, and will still probably be for a while. I also wonder how the Java ecosystem of tooling and available libraries looks compared to C#.


After I switched over from Eclipse to Intellij I think at least the IDE tooling is pretty much equals nowadays. I used Resharper in VS so in many ways you are using the same thing.

As others have said the open source community for Java is still leaps ahead of C#. It's not often you find a library which doesn't have a Java connector/implementation. For C# on the other hand you tend to be much more limited in your options.

I guess this used to be a lot due to the platform dependence of C# (and probably still is). Hopefully .Net Core can help with that, but it's not ready for prime time yet IMO.


intellij is free


IntelliJ is free for the community edition, but that one is limited in it's features. If you're doing anything web, you'll want the paid-for edition. However if you're just working on some Java SE, you could use the free version.


There's always Eclipse. It's a bit clunky at times but full featured nonetheless.


You can get the EAP (early access program) for free if you want to be a cheapskate.


i do web stuff and the community edition works just fine


> Everything Java does, C# does as good or better.

It's really true. It's so refreshing switching from Java to C#. I mean, they're both statically-typed-OOP-garbage-collected-bullshit-enterprise languages, but if you're gonna go with one of those, C# is far more pleasant than Java.


It has added some half assed okish stuff into a language that is still massively hard to use, super ceremonious and all that for not a lot of security.

Yes it is better than a lot of things, but it is also a super low standard. It get things done if you are ready to deal with all its problem... But it is still the child of its history, and its shows.


Java is easy to use once you understand it. I can code Java just as fast as C# or Python. In fact C# and Java are close enough to be mutually intelligible. The ceremony is all optional crap that most people don't worry about, it happens to any language used a lot in corporate.

The security issues were mostly in Java applets. The language itself is pretty damn secure. I can't remember the last time I saw a web exploitable issue in the JVM.


Well said. I'll add on that if you use a framework like Play with hot swap built in, you don't have to worry about restarts.


I'm messing with running Jersey on Jetty right now so I can get HTTP/2 before java 9. Netty and Jetty have both supported it for a while :)

There's still a lot of innovation going on in the Java community you just don't hear about it.


For Jersey + Jetty, it's hard to beat dropwizard (dropwizard.io). I'm sure you've heard of it though ;)


By security, i was more thinking of dealing with exceptions and error. I should have used Fault tolerance.

And i was not comparing Java to C# or Python here, but that is probably due to my personal background, which is more with OCaml, Erlang, C, Rust and co.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: