C++ or java

Discussion in 'Programming/Html' started by Shadowsoldier, Jan 26, 2011.

  1. naike

    naike Ancient Guru

    Messages:
    2,021
    Likes Received:
    0
    GPU:
    Asus EAH5870
    I asked this question, and the answer I got was, go Java if you don't need C++ features like better memory management and pointers, but if you plan to develop games and such then definitely C++.
     
  2. Xendance

    Xendance Ancient Guru

    Messages:
    5,551
    Likes Received:
    1
    GPU:
    Nvidia Geforce 570
    I wouldn't necessarily say that C++ has "better" memory management. From a programming standpoint it's more like a chore that you have to do sometimes. But from performance standpoint it's pretty obvious why you sometimes need to do it.

    Pitfalls? Also == in java only checks for reference equality, not if the actual object is equal, for which you need to implement your own equals() method.
    Also all languages I've tried use = for assignment and == for equality. Though I have only programmed with Java, Scala, C, C++ and done some python scripting.

    And you probably mean C++0x, not "Cx0x". It's a new standard for C++, not C. At least I couldn't find anything related to "Cx0x" on google.
     
    Last edited: Feb 9, 2011
  3. gamerk2

    gamerk2 Ancient Guru

    Messages:
    2,108
    Likes Received:
    0
    GPU:
    NVIDIA 570 GTX 1.2 GB
    ^^ Yeah, I meant C++0x; was thinking of the C99 standard at the time, and got the two mixed up [never a good practice! :D]

    And most languages that do not follow the C syntax use either := for equality [as has been done for over 1000 years in mathematics], or use = for both assignment and equality. == was, and still is, just a bad synatical choice, as the number of times you would set a variable inside an if statement is extraordinarilly small...

    As for manual versus automatic memory management, its a classic argument that exists in other languages as well [DirectX and OpenGL, for instance...]: Who handles resources: The developer, or the implementation?

    And to note: Java is NOT immune to memory leaks; I have a debugger for another language written in Java at work with a MASSIVE memory leak, so it crashes after running from the 20th breakpoint. I *think* what is happening is the garbage collector is so low priority, our high-priority threads keep pre-empting it [remember, in Windows, the highest priority thread ALWAYS runs], and thus, garbage collection never occurs. Farther, its worth noting the C++ standard includes a provision for automatic memory management, though its almost never implemented in practice.
     
  4. Karie777

    Karie777 New Member

    Messages:
    7
    Likes Received:
    13
    GPU:
    GTX 600
    C++ is not so poplar as Java nowadays, especially among the beginners. But many well-known products were developed in C++, and it's not easy to find a peron who can rewrite the working code into another programming language. As for Java, it is known to be a dominant among other languages because of its learning advantages, suitability for creating desktop apps, cross-platform interoperability, powerful traffic opportunities and its success in the mobile apps market. Recently I've read a good article about the reasons for Java's dominance - https://diceus.com/10-reasons-why-java-is-dominant/. Maybe someone will find it interesting. I should say, it persuaded me to choose Java for learning.
     

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    4,530
    Likes Received:
    497
    GPU:
    GeForce GTX 1070
    @Karie777 I guess the question is not relevant anymore (seeing no activity since 2011).

    Btw, I have never seen desktop application written in Java.

    As a developer I am doped and addicted to .Net and C# for last 6 years (and don`t want to deal with C++ anymore).
     
  6. sverek

    sverek Ancient Guru

    Messages:
    3,667
    Likes Received:
    448
    GPU:
    NOVIDIA -0.5GB
    Nobody want to mess with memory.

    C# is aimed for windows, so if you want your application to be cross platform, you gonna have a hard time.
    I use Golang now, still getting used to it, but I really like how easy you can compile code across platforms without major issues.

    Comparing languages to building a house:

    Python/PHP/JS is like asking company to build house for you. You may not like the result, but you didn't consume much time.

    Golang/C#/JAVA is buying parts / tools and building house by yourself. Bought parts might not be the best, but you can design your house better.

    C/C++ is like making tools from raw material, growing trees -> cutting them down, prepare parts and then build a house.
     
  7. mbk1969

    mbk1969 Ancient Guru

    Messages:
    4,530
    Likes Received:
    497
    GPU:
    GeForce GTX 1070
    @sverek
    Windows is the only platform I worked for (except for DOS).

    C# feels so much more comfortable and friendly comparing to C and even to C++. .Net framework with its huge library is definitely for lazy guys. And generic types in .Net is so much more usable than templates in C++. Plus huge benefit of .Net assemblies with types info incorporated within (comparing with binary + header files combo in C/C++). The list can go long...
     
    HK-1 and sverek like this.
  8. Alessio1989

    Alessio1989 Master Guru

    Messages:
    910
    Likes Received:
    48
    GPU:
    .
    I barely use "new/alloc/malloc/calloc" on C++, and usually only on rapid prototyping for binary parsing... After defined the needed custom allocator ( here platform syscalls and intrinsics may be needed, though you can still obtain good performance without them, at least compared to the naive heap allocation..), everything can be automatized (which means no manual memory allocation and deallocation at all).
    Unfortunately C++ needs a longer learning curve compared to other languages to obtain what you can best achieve with the language... Especially if there are tons of crap books written by monkeys coming from other banana languages...
    Yes modern C++ (C++11/14/17) made the language a lot better compared with the 98/03 "C with classes and some template mess", but most of the learning materials cover mostly the first standard. And yes, the "compatibility" feature means "we are going to kill a things or two in a decade" - not because they are simply "horrible" but - "since we need to recycle a keyword and some syntax" (this is the reason there are like 6 or more way to initialize an integer .-.).
     
    Last edited: Apr 11, 2018
  9. Stickynote

    Stickynote New Member

    Messages:
    9
    Likes Received:
    0
    GPU:
    Iris Pro/128Mb
    I started with Java and still use it for most of my programming projects. I think it's more popular.
     
  10. sverek

    sverek Ancient Guru

    Messages:
    3,667
    Likes Received:
    448
    GPU:
    NOVIDIA -0.5GB
    3 Billion Devices Run Java.
    OMG, 3 Billion Devices Run Java...

    I never wrote Java, but had to deal with servers that run on Java servlet. Getting those to run can be tricky. I once ended up debugging java server platform for 2 days, only to realize it takes 30 minutes for java application to start up. So stupid.
     

  11. mbk1969

    mbk1969 Ancient Guru

    Messages:
    4,530
    Likes Received:
    497
    GPU:
    GeForce GTX 1070
    You mean smartphones?
     
  12. RealNC

    RealNC Ancient Guru

    Messages:
    1,628
    Likes Received:
    184
    GPU:
    EVGA GTX 980 Ti FTW
    If you want your UI application to work on multiple platforms and look nice and integrate well, your only choice is using a language that offers bindings for the Qt toolkit. C++ and Python are the main ones. If you want to target Android and iOS too, then it's just C++. (Yes, you can use C++ on Android and iOS just fine.) Using Java for this will result in applications that look and behave like abominations on many platforms.

    If you're only interested in Windows, you can use C#. If you later want to port to a non-Windows OS though, you're gonna have a bad day.

    Java is pretty much for legacy Android apps right now. For new apps, Java is being replaced by Kotlin, Google's "next gen" Android language.

    Knowing Java is still useful. However, this is true for pretty much any language.

    Edit:
    If you need to develop performance critical code, then obviously you should be using C++.
     

Share This Page