• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is it possible to convert a program written in C++ to Java

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the program below written in C++ andI want to have it in Java so that I can use it in any operating system
 
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Algorithms and data types can certainly be ported (or reimplemented) in other programming languages. This looks like an array/list kind of class; does it do anything Java's built-in ArrayList class doesn't? Using that would make it interoperable with the rest of the Collections framework.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c++ to java is probably the easiest port IMO.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would have thought C# is easier to port to Java®.
 
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A tricky part of this conversion would be the handling of overloaded operators. You'll end up creating some methods to emulate the overloaded operators. The difficult part will be the combing of the C++ code, trying to determine if an operator is overloaded or not.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I stand corrected Campbell. Of course c# would be easier. But c++ is a lot like Java was my point.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Randall Twede wrote:I stand corrected Campbell. Of course c# would be easier. But c++ is a lot like Java was my point.



Some syntax, maybe, but I think the similarity is mostly illusion.

It's been a while since I had to rework C++ into Java, but it always involved understanding the problem rather than simply attempting a translation, which is how any other conversion works, whether 'similar' or not.  The only thing that converts are fairly basic algorithms, and even then there are plenty of pitfalls.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:

Randall Twede wrote:. . . But c++ is a lot like Java was my point.

Some syntax, maybe, but I think the similarity is mostly illusion. . . .

Agree. But we do see people here who think the similar syntax means the same thing in both languages, and they end up with dangerous confusion.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I just remember that learning c++ was a breeze since I knew java. I've never ported a program before. It sounds a little daunting. I would probably draw a class diagram, and then just write it again in the new language.
 
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic