Java Q&A by Jacob Gsoedl Listing One (a) // Source Code Start import java.util.Date; class ADispatchSample{ public String SayHi(){ return("Hi Dr.Dobb's reader!"); } public Date curDate = (Date)new Date(); } (b) import java.util.Date; class ADispatchSample{ public String SayHi(){ return("Hi Dr.Dobb's reader!"); } public Date curDate = (Date)new Date(); } Listing Two (a) /** @com.register ( clsid=4F49E33D-A813-4171-97D9-EEE7AD9C2F69, typelib=136C0E92-AF90-4365-8071-47D52152762B ) */ public class tips { private static String[] ComTips = { "An Automation interface is slower than a Custom Interface", "All COM objects are derived from IUnknown", "IUnknow Methods: QueryInterface(),AddRef() and Release()", "IDispatch Methods: GetIDsOfNames,Invoke(),GetTypeInfoCount,GetTypeInfo", "COM components can implement a 'Custom Interface', Automation Interface or Dual Interface", "A GUID is 128bit unique identifier for a COM component", "If a progid is defined for a COM object, it can be used instead of a CLSID to instantiate a COM object", "COM+ is the next incarnation of COM. It is part of Windows 2000" }; private static String[] ASPTips = { "ASP stands for Active Server Pages", "The Response object returns information to the client!", "The Request object is used to get information from the client!", "ASP is used to call COM components from a scripting language", "The VBScript and JavaScriptscripting engine are part of Windows", "ASP supports sessions to maintain state information", "ASP sessions use cookies to maintain state" }; public String getComTip(){ return getTip(ComTips); } public String getASPTip(){ return getTip(ASPTips); } private String getTip(String[] source){ int index = (int)(Math.random() * source.length); return source[index]; } } (b) <%@ LANGUAGE="VBSCRIPT" %> Tips Test <% Set objTip = CreateObject("TipServer.tips") %> COM Tip:
<%= objTip.GetCOMTip()%>

ASP Tip:
<%= objTip.GetASPTip()%> <% Set objTip = Nothing %> Listing Three import "oaidl.idl"; import "ocidl.idl"; [ object, uuid (3D7BFA13-EBF9-418c-B6A8-F2182E7AA03E), dual, helpstring("IDualTipServer Interface"), pointer_default(unique) ] interface IDualTipServer : IDispatch { HRESULT getComTip([out, retval] BSTR* ret); HRESULT getASPTip([out, retval] BSTR* ret); }; [ uuid (7AF622C6-BD7F-4638-AB1B-82537FEABB38), version(1.0), helpstring("DualTipServer 1.0 Type Library") ] library DualTipServerLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid (FF551EA5-812B-4297-8068-118ADE65E718), helpstring("DualTipServer Class") ] coclass tips { [default] interface IDualTipServer; } }; Listing Four // Auto-generated using JActiveX.EXE 5.00.2918 // ("C:\Program Files\Microsoft Visual Studio\VJ98\jactivex.exe" /javatlb /c2j /creg /xh /wfc /w /xi /X:rkc /l "C:\DOCUME~1\JGsoedl\LOCALS~1\Temp\jvc44.tmp" /nologo /d "C:\Documents and Settings\JGsoedl\My Documents\Visual Studio Projects\DualTipServer" "C:\Documents and Settings\JGsoedl\My Documents\Visual Studio Projects\ DualTipServer\DualTipServer.tlb") // // WARNING: Do not remove the comments that include "@com" directives. // This source file must be compiled by a @com-aware compiler. // If you are using the Microsoft Visual J++ compiler, you must use // version 1.02.3920 or later. Previous versions will not issue an error // but will not generate COM-enabled class files. package dualtipserver; import com.ms.com.*; import com.ms.com.IUnknown; import com.ms.com.Variant; /** @com.register(clsid=FF551EA5-812B-4297-8068-118ADE65E718, typelib=7AF622C6-BD7F-4638-AB1B-82537FEABB38, version="1.0", description="DualTipServer Class")*/ public class tips implements IUnknown,com.ms.com.NoAutoScripting, dualtipserver.IDualTipServerDefault { private static String[] ComTips = { "An Automation interface is slower than a Custom Interface", "All COM objects are derived from IUnknown", "IUnknow Methods: QueryInterface(),AddRef() and Release()", "IDispatch Methods: GetIDsOfNames,Invoke(),GetTypeInfoCount,GetTypeInfo", "COM components can implement a 'Custom Interface', Automation Interface or Dual Interface", "A GUID is 128bit unique identifier for a COM component", "If a progid is defined for a COM object, it can be used instead of a CLSID to instantiate a COM object", "COM+ is the next incarnation of COM. It is part of Windows 2000" }; private static String[] ASPTips = { "ASP stands for Active Server Pages", "The Response object returns information to the client!", "The Request object is used to get information from the client!", "ASP is used to call COM components from a scripting language", "The VBScript and JavaScriptscripting engine are part of Windows", "ASP supports sessions to maintain state information", "ASP sessions use cookies to maintain state" }; public String getComTip() { return getTip(ComTips); } public String getASPTip() { return getTip(ASPTips); } private String getTip(String[] source){ int index = (int)(Math.random() * source.length); return source[index]; } } Listing Five /** This class can take a variable number of parameters on the command line. * Program execution begins with the main() method. Class constructor is not * invoked unless an object of type 'Class1' created in the main() method. */ import tipserver.*; public class Class1 { /** The main entry point for the application. * @param args Array of parameters passed to the application * via the command line. */ public static void main (String[] args) { tips objTips = new tipserver.tips(); String aspTip = objTips.getASPTip(); String ComTip = objTips.getComTip(); System.out.println("\n\nToday's ASP Tip: " + aspTip); System.out.println("Today's COM Tip: " + ComTip + "\n\n"); } } 1