Java Language Features

The Java language is based on C++ and shows considerable similarity to it. In particular, Java code is case-sensitive. There are, however, significant differences between the two languages.

Because it is interpreted instead of compiled, Java cannot process #define directives. This means that the constants defined in the CDO and CDO Rendering type libraries cannot be used in a Java program. You have to use numeric equivalents, which can be found in the Error Codes, MAPI Property Tags, and Microsoft Exchange Property Tags appendixes.

Java does not provide any error trapping mechanism equivalent to the Microsoft® Visual Basic® On Error GoTo statement. All errors must be anticipated and explicitly tested for after each call that could generate them.

Like all alphanumeric elements in Java, the keywords are case-sensitive. Their predefined values are all lowercase, such as true, false, and null. This means Java does not recognize capitalized keywords such as True, False, or Null, which you may be accustomed to using in Visual Basic.

Java objects expose only methods and no properties. CDO library properties are referenced through accessor methods defined for each property by prefixing get or put to the property name, for example getInbox and putSubject. Parameters to methods are referenced by accessor methods with get or put prefixed to the data type, such as getString and putBoolean.

Read-only properties use the corresponding get accessor method. The Inbox property of the Session object, for example, can be read with the getInbox method:

Variant inboxFolder = new Variant(); 
  inboxFolder = session.getInbox(); 
 

Read/write properties use the corresponding get and put accessor methods. For example, the Subject property of the Message object can be read with getSubject and written with putSubject, after the parameter is prepared with the help of the getString and putString methods:

Variant inSubject = new Variant(); 
  StringBuffer newSubject = new StringBuffer( "RE: " ); 
  Variant outSubject = new Variant(); 
 ... 
  inSubject = inMessage.getSubject(); 
  newSubject.append( inSubject.getString() ); // already have "RE: " 
  outSubject.putString( newSubject.toString() ); 
  outMessage.putSubject( outSubject ); 
 

The property accessor methods such as getInbox always return a Variant object. If your code assigns them to another Variant object, as in the preceding code fragments, the types already match. If, however, you cast an object returned from an accessor method to another object type, you need to use the getDispatch method to obtain a type match:

Folder inboxFolder; 
  inboxFolder = (Folder) session.getInbox().getDispatch(); 
 

The CDO libraries support the IDispatch interface, which allows a program to access the underlying messaging and rendering objects. Invocation of the getDispatch method signals Java to call QueryInterface on a Variant object and obtain the appropriate messaging or rendering interface for it. For more information, see IDispatch.

Java methods do not allow for optional parameters. Calls to methods must present every parameter included in the definition of the method. The equivalent of a Visual Basic Null parameter can be achieved by using the noParam method on a Java Variant object:

Variant nullPar = new Variant(); 
  nullPar.noParam(); 
  object.Method( firstPar, nullPar, thirdPar, nullPar, nullPar );