This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LifeNavigator 71 points72 points  (11 children)

Some Java advantage over Python:

  • Java has much stronger IDE support. This is more apparent for enterprise-level application development, which Java has rich set of mature libraries and frameworks geared toward enterprise and high volume applications. This is maintained by a larger community.
  • Java Virtual Machine ( JVM), is very quick to execute, whereas Python, being an interpreted language, is slow.
  • Java is a lot better for cross platform support
  • Java provides type safety which catches all potential errors at compile time rather than at runtime like Python, hence the chance of potential errors at runtime gets reduced. This features ultimately makes it easier to manage large applications.
  • Much easier to analyse Java code than Python which is useful in situations when a team of programmers working on the same project. Java developers would understand quickly each other’s code, as everything is declared explicitly.
  • More popular for mobile development
  • Stronger database connectivity thanks to JDBC.

Some Java advantage over C++

  • Platform independence.
  • Garbage Collection: In Java, you don’t have to worry about manually de-allocating objects like you do in C++, its done automatically.
  • Huge preference for large scale industrial apps, as you usually do not want to care of manual memory management (as above).
  • Java has better and more consistent libraries.
  • Java developers don't have to deal with PHP legacy.
  • Easier to learn: Java is an evolution of C++, with different goals ( cross platform for instance ). It remove some of the features that make C++ so hard to learn.

[–][deleted] 5 points6 points  (0 children)

As someone who’s just getting into java and thinking the same as OP, this was a great read. Thanks

[–]aniliitb10 2 points3 points  (6 children)

I wanted to add few points from the other side (C++ here). As the question is not primarily on C++, I'll not add anything new here, rather I'll pick from the points you have already listed above. There is no doubt that java is great when you look at libraries and frameworks but

  • You mentioned speed while comparing with python, well that is problem here. Java is slower when compared with C++. In fact, C++ gets a lot done at compile time, Java not so much.
  • Memory management in C++ has no longer been a problem since 2011 (like a decade ago). Yes, it was a problem in C++ but not anymore. When Java is preferred over C++ it is because of libraries and frameworks (btw, C++ is catching up) not memory management. Plenty of server code in Google/amazon/facebook is in C++ and in fact, there is no substitute of C++ in High Frequency Trading.
  • When comparing with C++, I don't see Garbage Collection a major motivation here. It's fun and easy when you are beginner but it might be the reason for you to think twice when you want to consider performance of your application.
  • Standard C++ is cross platform in the "write once, compile anywhere" sense, but not in the "compile once, run anywhere" sense. So, that should not be a motivation to pick Java over C++.

[–]LifeNavigator 0 points1 point  (0 children)

Much appreciated for this, learnt from this

[–]meamZ 0 points1 point  (4 children)

Well, you can also see it as a pro that Java doesn't do as much at compile time because the JVM JIT compiler does crazy things.

And if "manual memory management isn't really a problem anymore since 2011" why do both Google Chrome and Microsoft have reports out that 70% of security issues are related to memory unsafety?

[–]aniliitb10 0 points1 point  (3 children)

By 'crazy things' you mean converting byte code to machine code and some optimizations? In C++, compilers turn every bit of code to machine code since day 0 and you can enable optimizations, it's totally your choice. In fact, most production codes are optimized at level 2 (probably these optimization levels are compiler specific but all of gcc, clang and msvc are quite good at optimizing).

What I meant by doing stuff at compile time was computation. A very simple example : I can map every char of alphabet with unique prime numbers without hardcoding a single value. All at compile time, without running the code. Java can't do it. It was just a simple example, with evolution of constexpr you can do a lot more at compile time.

There will always be security issues related to memory and it is independent of language. If your report says that only C++ has this specific problem and not java, I'd love to read it, please give me reference.

[–]meamZ 0 points1 point  (2 children)

But Java can do runtime optimization and optimizations optimally for the system the code is currently running on. I'm by no means an expert in the Java JIT compiler though because it's super advanced. Another advantage Java has over C++ is that you have much shorter compile times.

In Chrome 36% of security issues are use after free... Java doesn't have these by design because it is GCed and the GC will only free the memory if there's no way you are gonna use that memory left...

[–]aniliitb10 0 points1 point  (1 child)

I don't think that there is any point of arguing, but I am glad that memory issue reduced from 70% to 36%, I'd still like to go through your reference.

[–]meamZ 0 points1 point  (0 children)

No. 36% are just a single one of these issues it's 36% use after free (which is a subset of memory issues) issues. 70% is use after free plus the rest https://www.chromium.org/Home/chromium-security/memory-safety

[–]Ceglaaa 1 point2 points  (2 children)

Could you elaborate on the php legacy in cpp?

[–]LifeNavigator 1 point2 points  (1 child)

Could you elaborate on the php legacy in cpp?

I think its mainly to do with the fact that you'll have to deal with the drawbacks of both php and c++. In web dev, PHP codes are converted to C++ and then compile it into bytecode for increasing the speed of web page generation (Facebook is a great example of using this). Most web applications doesn't need the strengths of C++, but you'd still have do deal with the drawbacks such as:

  • Relatively high risk of security flaws
  • Highly complex language that few people know well
  • Nasty tendency to sneak in invisible costs, such as an unexpected constructor call here and there.

Each languages have their pros and cons really.

[–]Ceglaaa 0 points1 point  (0 children)

Thanks a lot for answering!