Read this section if you are building a Java application with Aspose.Words. This section explains the “standard” differences between Aspose.Words for .NET and Aspose.Words for Java. Given this knowledge, you will be able, if needed, to use the documentation and code examples written for Aspose.Words for .NET while building a Java application.
Close Porting
Aspose.Words for .NET was released first in December 2003 and then Aspose.Words for Java followed in February 2006. The Java version is a very close (almost one-to-one) port of the C# version of Aspose.Words.
We take a lot of effort to maintain very strong similarity between codebases and APIs of Aspose.Words for .NET and Aspose.Words for Java. As a result, the object models of the two products are virtually identical.
We continue to develop new features in Aspose.Words for .NET and continue close porting them to Aspose.Words for Java. Whenever a new feature becomes available in Aspose.Words for .NET, you can expect that feature will be available in Aspose.Words for Java within a few months.
Due to the time lag between release of a particular feature in the .NET and then in the Java version, some features available in Aspose.Words for .NET are not yet available in Aspose.Words for Java. For a detailed list of features, see Aspose.Words Features.
Differences in the APIs for .NET and Java
While trying to keep the APIs of the two products as similar as possible, we decided to recognize and honor development practices of the two different platforms. Therefore, Aspose.Words for .NET follows coding guidelines widely accepted by .NET developers and Aspose.Words for Java follows guidelines accepted in the Java community.
Namespaces vs. Packages
The names of packages in the Java version of Aspose.Words are different from the namespaces in .NET version:
|
Namespace in Aspose.Words for .NET
|
Package in Aspose.Words for Java
|
|
Aspose.Words
|
com.aspose.words
|
|
Aspose.Words.Drawing
|
com.aspose.words
|
|
Aspose.Words.Reporting
|
com.aspose.words
|
As you can see from the above table, there is only one package in Aspose.Words for Java.
Classes
Class names are same between .NET and Java versions.
|
Class Name in Aspose.Words for .NET
|
Class Name in Aspose.Words for Java
|
|
Document
|
Document
|
|
Paragraph
|
Paragraph
|
Some classes are available only in the Java version. For example, ResultSetHashMap is available in Aspose.Words for Java to mimic the DataSet class available in the .NET Framework.
Enumerations
We ported .NET enumerations to Java as classes with public integer constants.
|
Enumeration in Aspose.Words for .NET
|
Constant in Aspose.Words for Java
|
|
BorderType.Left
|
BorderType.LEFT
|
|
TextFormFieldType.DateText
|
TextFormFieldType.DATE_TEXT
|
|
ProtectionType.AllowOnlyComments
|
ProtectionType.ALLOW_ONLY_COMMENTS
|
The main reason why we did not use Java enums is to stay compatible with J2SE 1.4.2 as Java enums appeared only in J2SE 5.0.
All constants are integer values in Aspose.Words for Java. Where in the .NET version a parameter, return value or a property was of an enumerated type, it has been ported as integer to Java. In such cases, the documentation for the parameter will specify what class contains the constants applicable for this parameter.
Example SaveSignature
Shows difference in .NET and Java in signatures of a method with an enum parameter.
[C#]
// The saveFormat parameter is a SaveFormat enum value.
public void Save(string fileName, SaveFormat saveFormat)
[Visual Basic]
' The saveFormat parameter is a SaveFormat enum value.
Public Sub Save(ByVal fileName As String, ByVal saveFormat As SaveFormat)
[Java]
// The saveFormat parameter is an integer. The values are defined in the SaveFormat class.
public void Save(String fileName, int saveFormat) throws Exception
Methods
Method names follow the accepted practices for each platform and therefore differ in the coding style.
|
Method Name in Aspose.Words for .NET
|
Method Name in Aspose.Words for Java
|
|
Document.Save()
|
Document.Save()
|
|
CompositeNode.GetChildNodes()
|
CompositeNode.getChildNodes()
|
Most methods are different in the casing only (method names in the Java version start with a lowercase letter). Several methods had to be renamed as they got into conflict with some Java runtime methods. For example, Document.Clone() in .NET was renamed to Document.deepClone() in Java.
Properties
Properties of .NET classes were ported to Java as getter and setter methods. The original name of the method had "get" and "set" prefixes added to it.
|
Property Name in Aspose.Words for .NET
|
Getter and Setter in Aspose.Words for Java
|
|
Font.Bold
|
Font.getBold(), Font.setBold()
|
|
PageSetup.LeftMargin
|
PageSetup.getLeftMargin(), PageSetup.setLeftMargin()
|
Indexed Properties
Indexed properties in .NET were ported to Java as get() and set() properties in most cases.
|
Indexed Property in Aspose.Words for .NET
|
Getter and Setter in Aspose.Words for Java
|
|
Style[int]
|
Style.get(int)
|
|
Style[string]
|
Style.get(java.lang.String)
|
In some cases, if a class had several overloaded indexed properties, porting to Java created a conflict between different overloads because enumerated values were ported as integers. In such cases, the property was given a more descriptive name in the Java version.
Example CollectionItemSignature
Shows difference in signatures of collection indexers in .NET vs Java.
[C#]
public class HeaderFooterCollection
{
// Get by index is an indexer.
public HeaderFooter this[int index]
// Get by header footer type is an overloaded indexer.
public HeaderFooter this[HeaderFooterType headerFooterType]
}
[Visual Basic]
Public Class HeaderFooterCollection
' Get by index is an indexer.
Public ReadOnly Default Property Item(ByVal index As Integer) As HeaderFooter
' Get by header footer type is an overloaded indexer.
Public ReadOnly Default Property Item(ByVal headerFooterType As HeaderFooterType) As HeaderFooter
End Class
[Java]
public class HeaderFooterCollection
{
// Get by index is a method accepting an integer index.
public HeaderFooter get(int index)
// Get by header footer type is a method accepting an integer headerFooterType parameter.
// Possible values are defined in the HeaderFooterType class.
public HeaderFooter getByHeaderFooterType(int headerFooterType)
}
Events and Delegates
There is no language support for events and delegates in Java. Delegates from the .NET version are ported as listener interfaces and events are ported as add/remove listener methods.
Example EventsAndDelegates
Shows difference in event handling in .NET vs Java.
[C#]
// Represents the method that handles NodeInserted, NodeInserting,
// NodeRemoved and NodeRemoving events.
public delegate void NodeChangedEventHandler(object sender, NodeChangedEventArgs e);
public class Document
{
// Occurs when a node belonging to this document has been inserted into another node.
public event NodeChangedEventHandler NodeInserted;
}
[Visual Basic]
' Represents the method that handles NodeInserted, NodeInserting,
' NodeRemoved and NodeRemoving events.
Public Delegate Sub NodeChangedEventHandler(ByVal sender As Object, ByVal e As NodeChangedEventArgs)
Public Class Document
' Occurs when a node belonging to this document has been inserted into another node.
Public Event NodeInserted As NodeChangedEventHandler
End Class
[Java]
// Represents a listener interface for the NodeInserted event.
public interface NodeInsertedListener
{
// This method is called just after a node was inserted.
void nodeInserted(java.lang.Object sender, NodeChangedEventArgs e);
}
public class Document
{
// Adds a listener to the list of subscribed listeners for the NodeInserted event.
void addNodeInsertedListener(NodeInsertedListener newListener)
// Removes a listener from the list of subscribed listeners for the NodeInserted event.
void removeNodeInsertedListener(NodeInsertedListener oldListener)
}
Implementations of Internal Interfaces
In Aspose.Words for .NET, only about 150 classes are public while the other 900 or so classes and interfaces are internal. It is possible in C# for a class to implement an interface in two ways: declare the methods of the interface as public or declare them as explicit interface implementation methods. Most of the time we used explicit interface implementations so you don't see methods of the internal interfaces in the public API of Aspose.Words for .NET.
In Java, however, all members that are implementations of interfaces are public methods of the class. This makes some methods visible (that were not intended to be visible) in the public API of Aspose.Words for Java. We will include a corresponding remark in all such methods or will try to remove them from the documentation completely.
For example, the public Border class implements internal interface IComplexAttr and the Merge method is visible in the public API. You should not use such methods. In this case you cannot use this method altogether because the IComplexAttr interface is not public and its declaration is not available to you.