SafeD & Java

Jonathan M Davis jmdavisprog at gmail.com
Wed Jul 7 22:51:33 PDT 2010


On Wednesday 07 July 2010 21:46:01 fantasticfears wrote:
>  I know Java programs can be machine-translated into SafeD from
> http://www.digitalmars.com/d/2.0/safed.html.
> But what's the difference between SafeD and Java?

SafeD is the safe subset of D. So, it disallows stuff like pointers, but most of 
the language qualifies as "safe," so asking what the difference between SafeD and 
Java pretty much amounts to asking what the difference between D and Java is, and 
since they're two separate languages, that's a fair bit. Now, for the most part, 
D has more than Java, so it would be easier to convert Java to D than the other 
way around (for instance, D has structs while Java doesn't, but they both have 
classes; so converting the Java classes to D classes would be fairly 
straightforward, but converting D structs to Java classes would not). Generally 
speaking, I think that a Java program will have pretty much the same semantics 
as D if you tried to compile it as D (though there are bound to be differences - 
like how they char types are totally different). The main problem that you're 
going to run into is that the libraries are completely different.

So, while the language itself might convert quite easily, as soon as you're 
using the libraries (as you inevitably will be), you're going to have to figure 
out what libraries in D do the same thing, and given the size of Java's standard 
library, depending on what you're doing there's a good chance that you'd have to 
implement a fair bit of it yourself in D. D has some great library stuff, but 
it's nowhere near as complete as Java's libraries.

In any case, while Java should be fairly easily converted to D automatically (at 
least as far as the language itself goes - not the libraries), I'm not aware of 
any project that's designed to do that.

- Jonathan M Davis


More information about the Digitalmars-d mailing list