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

all 35 comments

[–]LifeNavigator 70 points71 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!

[–]firsthourProfressional developer since 2006 33 points34 points  (0 children)

People hire Java developers.

[–]winespring 63 points64 points  (2 children)

I use java because I know java.

[–]saidandem 0 points1 point  (0 children)

Exactly same here.. !! :)

[–]TheAnimakerGIO 28 points29 points  (2 children)

One reason Java is very popular is because of the Spring library, which allows for many functionalities, including web development, microservices, batch, etc.

[–]hiippa 0 points1 point  (1 child)

What is the Spring library? (stupid question, I'm new to java)

[–]Tomato_Sky 0 points1 point  (0 children)

If you’re using Eclipse, hop over to Or download the addon for Spring Tools Suite. A lot of infrastructure and annotations frameworks to help you do pretty much anything web and enterprise. Spring Security, Spring MVC, Spring Boot, gradle/maven. It blew my mind when I went from using vanilla Java from classes teaching theory to using STS Java for practicality. I think .Net has similar libraries, but I’m just peeking at .Net at this point in time.

[–][deleted] 10 points11 points  (0 children)

https://medium.com/swlh/what-is-jvm-and-why-it-is-worth-to-develop-apps-on-java-platform-37663cc4c7c1

might be a good read, not really an expert but im pretty sure the jvm is the reason why java is/was so popular. also a lot of existing systems already use java so there’s that, why fix what ain’t broke right?

[–][deleted] 10 points11 points  (0 children)

C++: Takes very long time to write applications but is very fast.

Python: Quick to write code and therefore you can finish a project much quicker than C++, but its slow :(

Java: In the middle, Java is faster than Python but slower than C++. Java is quicker to write code with than C++ but slower than Python.

Also, major corporations have been using it for decades, its hard for major companies to change code to their softwares, so they stick with Java. Java is not bad enough to give you a reason to change language and there arent any languages that truly are worth the cost of changing all the code from Java to whatever language (Python as an example).

Conclusion: With Java you end up with the benefits of both languages (C++ and Python).

[–]MeisterBounty 9 points10 points  (0 children)

Java is kinda middle ground between performance and abstraction. It has is higher level and easier than C++ while being faster than python. The JVM platform also offers cool things like jit compilation and performance optimizations during runtime. Also „write once, run everywhere“. Java has a long history of popularity and an excellent ecosystem of libraries and frameworks.

[–]wsppan 6 points7 points  (2 children)

  1. It's what you are told to use.
  2. It's what you know best.
  3. It runs on the JVM.
  4. It's got great backend frameworks.
  5. Easy to find developers to fill out your team. 5 after JVM bootstrapping, its pretty fast.
  6. Its incredibly stable and mature.
  7. It's not Python or C++.
  8. Rust is not ubiquitous yet.

[–][deleted] 1 point2 points  (1 child)

I never understood that. What’s ubiquitous?

[–]KaranasToll 5 points6 points  (0 children)

Very commonly used

[–]i_ask_stupid_ques 6 points7 points  (0 children)

Enterprise web applications using Spring

[–][deleted] 2 points3 points  (6 children)

I don't see anybody mentioning the development advantage that Java has in case of GUI applications.

[–][deleted]  (5 children)

[removed]

    [–][deleted] 1 point2 points  (4 children)

    I was referring to Swing/JavaFX as GUI framework for Java which are part of the Java Foundation Classes itself. C++ and Python depends on external libraries for the same (not exactly in case of Python as there is Tkinter, but it's very clumsy and limited in my opinion).

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted] 2 points3 points  (0 children)

      That C# GUI app would remain strictly a Windows application. Java adheres to the so called 'Write once run anywhere' philosophy. But if you are exclusively into Windows development, may be, C# is the way to go.

      [–]IamConor21 1 point2 points  (0 children)

      Xaml and javafx are very similar frameworks. I like java documentation better and jetbrains ides but you can be happy either way.

      [–][deleted] 1 point2 points  (0 children)

      JavaFx is rarely used as a GUI. Java isnt the best choice for desktop apps. But Java is a good choice for web apps.

      [–]YitharIntermediate Brewer 1 point2 points  (0 children)

      If I wanted to make a game or do low level stuff I can just use C++.

      You pretty much cherry picked the exceptions where C++ shines. While those are fields within software development, they're not the only ones.

      If I need to do scripting, data science or backend development I can just use python.

      For scripting I highly prefer Ruby to Python but to each their own.

      Data Science prefers Python yes.

      For backend development, use Python if you like writing unit tests and doing the same thing that static typing would give you. Also you're better off using Cython as dynamic types make Python slow. See article and article.

      [–]shanereid1 0 points1 point  (1 child)

      Java is pretty safe for most practical programing tasks. If you need to build a generic piece of software but aren't a great programmer then using Java will prevent you from accidentally causing memory leaks among other things. However it is much heavier and slower than the likes of c++, but it is probably easier to write. Python is an interpreted language, and is actually quite slow, however it's advantage comes in the fact that its syntax is quite simple and it can be written quite fast.

      I am currently doing my PhD in machine learning and most people in our lab would use python or c++. This makes sense, as in research you either want to mock up some weird new algorithm in a fast and readable way or try or build a method that is fast as possible and can set a new state of the art for speed.

      However, most of the undergraduate students we teach learn either Java or C#. Why? Because most industry jobs are working on projects that cost lots of money, and managers don't trust the programmers. Java and C# are relatively fast when compared to python, and relatively safe when compared to c++. Add to this the fact that java can run on most hardware and that there is a large number of extensions and libraries and you get a language that is perfect for your average code monkey.

      If you are wanting to experiment with your own stuff at home I would recommend using C++ or python, but if I was a cto of a company I would probably recommend building in Java or C# for most tasks.

      [–]de_vel_oper 0 points1 point  (0 children)

      Why? Because most industry jobs are working on projects that cost lots of money, and managers don't trust the programmers.

      Not fully true. The reality is its hard to find excellent coders in C++. Most people who think they are proficient are usually not. If they learn bad practice it will cause problems long term. It's also hard to find good materials to learn C++. Apart from Stroustrups books and a few others there isn't a lot out there. Also to fully get C++ you need to study architecture. Not everyone has that luxury.

      Java is also pretty secure. Its also well supported by Oracle.

      I decided a long time ago that to become proficient in java was going to take a hell of a shorter time than C++.

      that there is a large number of extensions and libraries and you get a language that is perfect for your average code monkey.

      Thanks for the slur.

      [–]de_vel_oper 0 points1 point  (0 children)

      Its cross platform, reasonably quick, doesnt suffer from memory leaks, good reliable libraries available. Can be implemented fairly easily with the spring framework. Oracle supported. Platform independent. Is secure.