D Documentation [ Log in ]
From Java
Switching from Java to D is not a big step. There are a few differences because D is compiled for native code. As both languages are somehow influenced by or inherited from C or C++ syntax, there won't be a big problem :-)

Let me show you some D code that works and is very similar to java code:

// a class called Foo
class Foo
{
  // a variable
  int myInteger;

  // this is the constructor!!
  this()
  {                  
    myInteger = 1;
  }

  // a function :-)
  int bar()
  {               
    for (ubyte i=0; i<2; i++) {
      myInteger *= 2;
    }
    return myInteger;
  }

} // end of class Foo

void main()
{
  // creates a new class of Foo
  Foo myFoo   = new Foo();   

  // calls the function bar in foo three times.
  writefln("%d",myFoo.bar()); 
  writefln("%d",myFoo.bar());
  writefln("%d",myFoo.bar());
}

Output:
4
16
64

Difference: In D, we don't have to use a class name that is same name as the file and we import std.stdio to write to the display:

// Import standard-in-out
import std.stdio;

// Main function
int main(char[][] args)
{
  char[] world() {
    return "world!";
  }
  writefln("Hello "~world());

  // We have to return with a int to exit the program (0 means "no error").
  return 0;
}

Difference: The main function must return an int to the system.

Difference: In D "+" and "~" are not the same! The first one (plus) is only for numbers (int b=5+3, int a=2+b) and the concatenation ("~") is only for arrays (which strings are):

char[] str   = "Paradise";
char[] text  = "Welcome to "~str~".";


See also:
Language Reference, An advanced tutorial: File read and write, Java to D
PHP docwiki written by Markus Dangl. Best viewed with Mozilla Firefox.
This is the inofficial wiki for documenting the D programming language.
- Profiler -
Time for site generation: 0.0788 s