Microsoft Visual J# .NET Tony Goodhew Product Manager Visual J# .NET Microsoft Corporation - PowerPoint PPT Presentation

albert
microsoft visual j net tony goodhew product manager visual j net microsoft corporation n.
Skip this Video
Loading SlideShow in 5 Seconds..
Microsoft Visual J# .NET Tony Goodhew Product Manager Visual J# .NET Microsoft Corporation PowerPoint Presentation
Download Presentation
Microsoft Visual J# .NET Tony Goodhew Product Manager Visual J# .NET Microsoft Corporation

play fullscreen
1 / 55
Download Presentation
Microsoft Visual J# .NET Tony Goodhew Product Manager Visual J# .NET Microsoft Corporation
873 Views
Download Presentation

Microsoft Visual J# .NET Tony Goodhew Product Manager Visual J# .NET Microsoft Corporation

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Microsoft Visual J# .NETTony GoodhewProduct ManagerVisual J# .NETMicrosoft Corporation

  2. Product Goals • Provide a Java language for the Microsoft® .NET • Bring the power and richness of the .NET Frameworks to programmers using Java • Carry forward existing skill and code investments • Seamless upgrade path for Visual J++® developers • Full integration with Visual Studio® .NET

  3. Visual Studio .NET VB C++ C# JScript J# Common Language Specification ASP.NET Web Forms Web Services Windows Forms ADO.NET and XML Base Class Library Common Language Runtime Operating System .NET Framework

  4. J# Compiler J# IDE in VS Visual Studio.NET JBIMP J# Class Libraries (JDK Subset) COM Inter-op and WFC .NET Frameworks (ADO.NET, ASP.NET, Windows Forms, Web Services …) Common Language Runtime Operating System Visual J# .NET

  5. Technology Overview • Java language • Microsoft Visual J#™ .NET compiler • Support for .NET CLS • Properties, events, and delegates • Class libraries • Subset of JDK 1.1.4 class libraries • Base libraries, collection classes • AWT, JDBC, Beans • Visual J++ support: Java/COM, J/Direct, WFC

  6. Technology Overview (2) • Binary converter • Class files to .NET assemblies • Full access to the .NET Framework • ASP.NET, ADO.NET, Windows Forms, and so forth • Integrated with Visual Studio .NET • IntelliSense®, designers, debugger • Usability improvements

  7. Visual J# .NET Compiler • Compiles Java-language sources to Microsoft intermediate language (MSIL) • Supports all key features of the Java language • Fully supports consuming .NET Framework • Preserves Java language, scoping, and class hierarchy semantics • Supports extensions in Visual J++ • J/Direct • Attributes

  8. CompilerLanguage Support • Classes • Inner classes, nested classes, anonymous classes, local classes • Throws clause and checked exceptions • Static initializer blocks, synchronized blocks • .NET CLS compliance • Full CLS consumer • Limited CLS extender

  9. Compiler CLS Consumer • Natural Java-language syntax for accessing • Properties – through property accessor methods • Delegates – permits creation of delegates over any Visual J# method • Events – through event accessor methods • Enums • Value types • Attaching attributes

  10. Consuming .NET Meta Data • Properties – use property accessors form.set_Text(“Hello”); form.get_Text(); • Delegates – just create the delegate over a Visual J# method myHandler = new EventHandler(OnClickOK); • Events – use event accessors okButton.add_Click(myHandler); okButton.remove_Click(myHandler);

  11. Consuming .NET Meta Data Value Types and Enums • Using value types • Automatic boxing and unboxing DateTime dt = new DateTime(); dt = DateTime.Parse(“01/01/2002 12:00”); System.Object obj = dt; // This boxes value type dt DateTime dt2 = (DateTime) obj; // This unboxes obj • Using enums • Casting to underlying primitive type int iStyle = (int) AnchorStyle.Left; AnchorStyle style = (AnchorSytle) iStyle; • Using bitwise operations AnchorStyles style = AnchorStyle.Left | AnchorStyle.Bottom;

  12. Attaching .NET Attributes • Attribute suffix is optional • @attribute /** @attribute WebMethodAttribute(true) */ String GetStockQuote(String symbol) • @attribute.method /** @property */ /** @attribute Description(“Property Size”) */ /** @attribute.method Description(“Get accessor”) */ int get_Size() { return 0; } • @attribute.return /** @attribute.return MarshalAs(UnmanagedType.BSTR) */ System.String getString(); • @assembly /** @assembly AssemblyVersion(“1.*”) */

  13. Using Other .NET Primitive Types • ubyte ubyte [] bytes = new ubyte[100]; File.Read(bytes); • Unsigned types not in Visual J# System.UInt32 uint = (System.UInt32) 100; • Managed pointer type System.IntPtr intPtr = System.IntPtr.Zero; // null • Boxing and unboxing of primitive types System.Object obj = 10; // Won’t work // Will work and will box the integer 10 to a Sysem.Object. System.Object obj = (System.Int32)10; int j = (int)(System.Int32) obj; // Unbox

  14. Code Sample for IntPtr import System.Runtime.InteropServices.*; public class A {       public static void main(String [] args) {       byte [] barray = new byte[20];       GCHandle gch = GCHandle.Alloc(barray, GCHandleType.Pinned);       System.IntPtr iptr = gch.AddrOfPinnedObject();       test(iptr);       }       /** @attribute DllImport(“sample.dll") */       static native void test (System.IntPtr iptr); }

  15. Using Delegates J# class:  class Consumer {       public static void main()  {       CreateDelegate del = new CreateDelegate();       // Consume the .NET Delegate in J#       del.myD.Invoke();    } } C# class: using System; public class CreateDelegate  {    // Declare a delegate for a method that takes no params and returns void    public delegate void myDelegate();    // Define a method to which the delegate can point    public void myMethod()  {        Console.WriteLine("Delegate called");    }    public CreateDelegate() {             // Create a delegate for above method             myD = new myDelegate(myMethod);    }     public myDelegate myD; }

  16. Code Sample for Boxing Primitives int i = 10; System.Object obj = (System.Int32) i; // Boxes i to an object int j = (int)(System.Int32) obj; // Unboxes obj to an integer

  17. Compiler CLS Extender • Supports authoring .NET properties, events, and delegates • No new keywords: uses @ directives to mark members as properties, events, delegates • Accessor methods follow CLS naming conventions (get_, set_, add_, remove_) • Can be consumed from other languages • No support for enums or value types • In Beta 2, use the /extender option

  18. Authoring Properties // A property ‘Size’ of type int /** @property */ public int get_Size(){…} /** @property */ public void set_Size(int size){…} // An indexed property ‘Item’ of type // System.Object; the index type is a string /** @property */ public System.Object get_Item(System.String key){…}; /** @property */ public void set_Item(System.String key, System.Object value){…}

  19. Authoring Events And Delegates // Creates an Event called PropertyChanged // PropertyChangedEventHandler is the handler, // (a delegate) /** @delegate */ delegate void PropertyChangedEventHandler(); /** @event */ void add_PropertyChanged(PropertyChangedEventHandler eventHandler){…} /** @event */ void remove_PropertyChanged(PropertyChangedEventHandler eventHandler){…}

  20. Object and String in Visual J# • Base objects (object, string, exception) • Seamless mapping • All semantics are maintained • Cross-language Interop automatically maps these object types • java.lang.Object(JLO) can be used instead of System.Object to access .NET Frameworks • java.lang.String(JLS) is exposed as ‘string’ data type in MSIL

  21. Using .NET Framework • Strings • Auto marshaling of Java String and .NET Strings System.String hello = “Hello”; String helloJava = hello; • Calling methods that take by ref parameters String str = “Hello” callMethodThatAppendsWorld(str); // by ref parameter Console.WriteLine(str); // prints “Hello World” • Getting the System.Type for a class class sampleClass = Sample.class; System.Type sampleType = Sample.class.ToType(); // Calling sampleClass.ToType() will be slower

  22. Using .NET Framework (2) • Keywords as identifiers – use @<keyword> class @class {} // class defined in J# int i = obj.@synchronized // accessing field named synchronized • Signing assemblies /** @assembly AssemblyKeyFile(“key.snk”) */ • Declarative security /** @attribute FileIOPermission(SecurityAction.Demand) */ ReadFile(); // demands for the permission before allowing // the call

  23. Java-byte-code class file (.class, .jar, .zip) Java-language source file (newcode.jsl) .NET Framework JBIMP Binary Converter VJC J# .NET Compiler Subset of JDK Class Libraries .NET Assembly (MSIL) convclass.dll .NET Assembly (MSIL) newcode.dll .NET Framework Common Language Runtime Win32 Binary Converter .Class (Byte-Code) to MSIL

  24. Binary Converter (JbImp) • Converts .class files to MSIL • Reports unresolved references • And permits you to automatically find them • /usestubrefs option • Creates stub types for unresolved references • Useful for unused unresolved references • J/Direct • Supports archive files - zip/jar/cab format • Signed assemblies • Use /keyfile, /keycontainer, /delaysign

  25. Class LibrariesJDK Subset • Visual J# Redistributable includes subset of JDK 1.1.4 class libraries in MSIL • JNI and RMI are not supported • Key functional areas are: • Base libraries • (lang, util, math, io, net, text, ...) • AWT • JDBC • Beans • Collection APIs (AP subset) • Set, Map, List, Collection, and so forth

  26. Visual J++ Style Java-COM Interop • Visual J# supports most key Java/COM Interop scenarios of Visual J++ • Applications using COM components • @com.class, @com.interface, @com.method, and so forth • Applications hosting Microsoft ActiveX® controls • Exposing components to COM • Must have @com.register

  27. Visual J++ Style Java-COM Interop (2) • Support for this is layered on .NET Framework COM Interop • In most cases, existing Visual J++ applications using Java/COM will not need any changes to run • The Upgrade Wizard fully automates all steps of the upgrade • Newly written Visual J# applications must directly target .NET Framework COM Interop semantics and tools

  28. WFC • WFC is supported in Visual J# • Existing Visual J++ WFC applications • Hosting of WFC controls • No source code changes required • New Visual J# applications must target Windows Forms instead

  29. Integration with Visual Studio .NET • Full integration in the Visual Studio shell • Project system • Editor, Solution Explorer • Compile/build, execute/debug • Project wizards • Language services • Designers – Web Forms, Windows Forms, XML Web Services • IntelliSense, Colorizer • Debugger • Java-language exceptions • Java-language expression evaluator

  30. Visual Studio .NET Power • Well integrated designers for rapid application development • Using HTML, Data, XML, server-side components • End-to-end application debugging support • Web applications • Cross language • Across processes, machines, and stored procedures • Customizable and extensible IDE components • Using macros

  31. Visual Studio .NET Power (2) • Deployment support for packaging and installation • Deployment projects • Merge modules, setup, Web setup • International-ready application development • Localization projects, localized setup projects • Resource files with full unicode support

  32. Environment Tips and Tricks • Solution Explorer • IntelliSense • Class view • Object browser • Outlining • Toolbox • Command window • Displaying miscellaneous files • Task list

  33. Productivity • Dynamic Help • Microsoft Visual SourceSafe® Integration • Automating the build process • Command-line switches • Build macros • Batch builds • Command-line tools • VJC – Visual J# command-line compiler • JBIMP – Java byte-code to MSIL converter

  34. Debugging • Cross language • .NET, Unmanaged, ASP, SQL • Cross process and machine • Rich debugger automation • Windows • Autos, Locals, Watch, Memory, Call Stack • Exceptions dialog • Expand your types automatically • Vjsee.dat

  35. Visual J# Redistributable Package • Installs on .NET Redist • Complete runtime for deployment of Visual J# applications • Compiler • Class libraries • Deployment support for packaging

  36. .NET Power in Visual J# –Common Language Runtime • Version aware assemblies • Cross language Interop • Native code Interop (PInvoke) • COM Interop

  37. .NET Power in Visual J# – Frameworks • ADO.NET • XML/relational views, in-memory cache • ASP.NET • Authoring controls in Visual J#, • Data binding using ADO.NET and XML • Multiple client support

  38. .NET Power in Visual J# – Frameworks (2) • Web Services • Proxy generation, UDDI integration • Support for HTTP – GET, POST, and SOAP wire formats • Windows Forms • Performance, GDI+, rich platform integration • Controls can be hosted in Internet Explorer 5.x

  39. Native Interop Using PInvoke • Use .NET PInvoke attributes • DllImportAttribute, MarshalAsAttribute, StructLayoutAttribute, and so forth /** @attribute DllImport("USER32") */static native int MessageBox( int hwndOwner, System.String text, System.String title, int MyStyle);

  40. .NET COM Interop • Supports native .NET Framework semantics for COM Interop • Newly written Visual J# applications must directly target .NET Framework COM Interop semantics and tools • Tools: TlbImp, AxImp, TlbExp, RegAsm • Attributes and classes in System.Runtime.InteropServices package • Visual J# enables all scenarios that are supported by other languages on .NET Framework • For example: • Using COM or ActiveX controls • Exposing WinForms components as ActiveX controls

  41. Web Control Authoring VJSControl.ascx file: <%@ Control Language="VJ#" AutoEventWireup="false" Codebehind=“VJSControl.ascx.jsl" Inherits="WebApplication1.VJSControl"%> Codebehind file: // VJSControl.ascx.jsl public abstract class VJSControl extends System.Web.UI.UserControl { private System.String customername = ""; /**@property*/ public System.String get_customerName() { return customername; } /**@property*/ public void set_customerName(System.String s) { customername = s; } }

  42. Web Control Authoring (2) Using a Web Control in a Web Forms page: <%@ Page language="VJ#" Codebehind="WebForm1.aspx.jsl" AutoEventWireup="false" Inherits="VJSWebApp.WebForm1" %> <%@ Register TagPrefix="uc1" TagName="VJSControl" Src="VJSControl.ascx" %> ... <uc1:VJSControl id="VJSControl1" customerName="Thomas" runat="server"> </uc1:VJSControl>

  43. Data Binding in Web Applications <%@ Page language="VJ#" Codebehind="WebForm1.aspx.jsl" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %> ... <asp:DataGrid id="DataGrid1" runat="server" DataSource='<%# DataBinder.Eval(dataSet11, "get_Tables().get_Item(Customers). get_DefaultView()") %>'> </asp:DataGrid>

  44. Web Service Proxy Generation <%@ WebService Language="VJ#" Class="VJSWS1.Service1" %> Package VJSWS1; ... public class Service1 extends System.Web.Services.WebService { /** @attribute WebMethod() */ public int AddOne(int x) { return x+1; } }

  45. Proxy Generation Command line for proxy generation: wsdl.exe /l:"Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" http://localhost/VJSWS1/Service1.asmx Generated File: // Service1.jsl public class Service1 extends System.Web.Services.Protocols.SoapHttpClientProtocol { ... /** @attribute System.Web.Services.Protocols.SoapDocumentMethodAttribute(...)*/ public int AddOne(int x) { System.Object[] results = this.Invoke(("AddOne").ToString (), new System.Object[] {(System.Int32)x}); return ((int)(System.Int32)(results[0])); } ...

  46. Upgrading from Visual J++ Visual J++ to Visual J# • Upgrading is as simple as pressing F5 in most cases • Upgrade Wizard in IDE • Opens Visual J++ solutions and projects • Automatically detects missing references • Class files – and locates them if present • COM references – runs Tlbimp and adds managed wrapper • Upgrade Report lists issues with prescriptive links • JBIMP to convert class files to MSIL

  47. J/Direct • Visual J# compiler fully supports J/Direct • @dll.import, @dll.struct, @dll.structmap • Callbacks • All existing Visual J++ applications using J/Direct can be compiled and run without change • Binary Converter (JbImp) supports converting classes that use J/Direct • The com.ms.dll and com.ms.win32 packages used with J/Direct are fully supported

  48. Upgrading Visual J++ Projects Using Java/COM – Calling COM from Java • Two simple steps: • Generate managed wrappers for the type library of the COM component using TlbImp tool TlbImp COMComponent.tlb • Compile the Visual J++ application together with the JActiveX wrappers, referencing the managed wrapper generated by TlbImp vjc <AppSources> <JActiveXWrappers> /reference:managedWrappers • Full debugging support

  49. Upgrading Visual J++ ProjectsUsing Java/COM – Calling Java from COM • As simple as recompiling the Visual J++ component and registering it!! • For components implementing JActiveX templates (/c2j option): • Generate managed wrappers for the type library of the COM component using the TlbImp tool TlbImp COMComponent.tlb • Compile the VJ++ component while referencing the managed wrapper generated by Tlbimp vjc <AppSources> /reference:ManagedWrappers • Register the component using the RegAsm tool • COM clients are transparent to the fact that the Visual J++ component is now hosted in the common language runtime

  50. Unsupported Visual J++ Java/COM Features • Custom marshaling • Monikers • Exposing components to COM as ActiveX controls • Exposing components to COM that do not have the @com.register attribute • Conversion of class files that use Java/COM