Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java vs. C++ for building a GUI which has a C++ backend [closed]

Tags:

I currently have a C++ backend that I need to connect with a GUI, and since I've never built a GUI before, I was confused on where to start.

I'm comfortable writing code in C++ and Java, so I'd prefer my GUI to be in one of those languages. Also, the GUI has to be reasonably OS independent over Windows and Linux (and hopefully, hence Macs).

Now I understand that if I use Java to do it, I'll need some wrappers to do it - but I've also heard (strictly second hand) that writing a GUI in C++ is a pain.

I don't want to rewrite too much of my backend code in Java (who does??) and I was hoping for input on:

  • Does either language offer serious advantages/disadvantages compared to the other?
  • How serious is the wrapping issue, and how much rewriting would come in if I used Java.
  • Are there any specific resources I should look at that people think would be relevant?

Thanks and Cheers All :)

like image 951
sparkFinder Avatar asked Jul 08 '10 19:07

sparkFinder


People also ask

Is C good for GUI?

While there are cross-platform GUI libraries available for C/C++, they are not the easiest to use simply due to their complex nature compared to other languages. Therefore, you may want to consider using C/C++ in a graphical environment if speed is very important.

Is Java good for GUI development?

Even Java, while it is self-contained, does not currently provide great GUI designer capabilities.

Which is better for GUI Java or C++?

Unless you need C++ for other reasons (of which there are plenty), choose Java for the GUI. The cross-over coding is trivial for someone who knows both languages, but it can get messy to manage, so you'll want to minimize the native interface as best you can.

Which language is best to create GUI based application?

Java seems to have the best built in support for GUI programming, however, C++ using the MFC libraries has more than adequate tools for GUI development and may be a better choice when speed and efficiency are important.


2 Answers

Have a look at Qt.

In my experience communicating between two different language runtimes is always challenging. If you have a non-trivial application to build the following often pose challenges:-

  • Error Handling.
  • Memory Management.
  • Multithreading and Synchronization Semantics.

Apart from increasing one level of indirection due to wrappers, it requires a lot of thinking like circumstances where you need to pass data structures across GUI and backend etc.

For example:- Consider passing a Java String from GUI to backend C++. Essentially, we have to extract the characters from a Java String object and make them available to the C++ developer without leaking the memory which holds them. This is an example of a basic problem (there are other aspects too like the encoding in which the characters are to be returned).

like image 170
Abhay Avatar answered Sep 19 '22 03:09

Abhay


You say you already know C++ and Java, and that you never did a GUI before. That means:

  • no matter if you go for a Java GUI or a C++ GUI, you will need to learn how to handle the GUI framework
  • if you chose Java, you also need to learn how to interface between the two languages

So staying in C++ saves you one thing to learn. Well, it's always a good idea to learn something, but might be a bad idea to learn two new concepts at the same time. Anyway, the learning might be the smaller burden, I guess there is a lot of actual work involed, even when you use tools like SWIG.

You might want to know if writing a GUI in Java or doing it in C++ is easier. It depends on the chosen Framework. For Java, you have AWT and Swing which are part of the default Java distribution, and then there is SWT which is used by Eclipse, for example. For C++, there are many toolkits, with Qt, GTK and wxWidgets being the most popular ones, and all three support every major platform. Most of those "C++" GUI toolkits also have a Java binding or even a Java port, so you could use them with Java as well.

So far I've used Swing, Qt and a few others which don't help in your situation (The UI thingy that came with Borland C++ Builder and WinForms on .NET). Basically, the concepts are the same for all those frameworks, and I found none of them being harder or easier than the other. The only exception maybe Java, because I never got those LayoutManagers to work, even though the other toolkits have equivalents to LayoutManagers that are easy to master. But maybe thats just me.

People also will tell you that Java GUIs are always ugly and don't fit the host system. Well, most Java GUIs really are, but IMHO thats not because of Java, but because of bad programming. It takes two lines of code to let a Swing app adapt to the look and feel of the OS, and most programmers simply don't put enough effort into their Java GUIs to copy and paste those two lines... you can imagine how much they care about the rest of their GUI design.

For your current situation, I would recommend a C++ GUI, but if you know how your future plans look like, and if you know you will doing Java GUIs for the rest of your life, then it's probably ok to start that now and take the extra effort of .

And if you chose C++ for the GUI, people will tell you all kind of things to pull you in any direction. All of the three big portable frameworks have their pros and their cons, but I don't believe there is any single best or worst one among them. I'd recommend Qt simply because I already used it - but if I'd happten to have used GTK or wxWidgets instead, I'd probably suggest that.

like image 33
Lena Schimmel Avatar answered Sep 17 '22 03:09

Lena Schimmel