Microsoft Visual J - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

Microsoft Visual J

Description:

int j = (int)(System.Int32) obj; // Unbox. 14. Code Sample for IntPtr ... J/Direct. Supports archive files - zip/jar/cab format. Signed assemblies ... – PowerPoint PPT presentation

Number of Views:243
Avg rating:3.0/5.0
Slides: 56
Provided by: MicrosoftC8
Category:
Tags: microsoft | visual

less

Transcript and Presenter's Notes

Title: Microsoft Visual J


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
.NET Framework
4
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 1200)
  • 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
  • _at_attribute
  • / _at_attribute WebMethodAttribute(true) /
  • String GetStockQuote(String symbol)
  • _at_attribute.method
  • / _at_property /
  • / _at_attribute Description(Property Size) /
  • / _at_attribute.method Description(Get
    accessor) /
  • int get_Size() return 0
  • _at_attribute.return
  • / _at_attribute.return MarshalAs(UnmanagedType.BST
    R) /
  • System.String getString()
  • _at_assembly
  • / _at_assembly AssemblyVersion(1.) /

13
Using Other .NET Primitive Types
  • ubyte
  • ubyte bytes new ubyte100
  • 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 // Wont 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 byte20
  •       GCHandle gch GCHandle.Alloc(barray,
    GCHandleType.Pinned)
  •       System.IntPtr iptr gch.AddrOfPinnedObject(
    )
  •       test(iptr)
  •      
  •       / _at_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")

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 _at_ 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
  • / _at_property /
  • public int get_Size()
  •  
  • / _at_property /
  • public void set_Size(int size)
  • // An indexed property Item of type
  • // System.Object the index type is a string
  • / _at_property /
  • public System.Object get_Item(System.String
    key)
  •  
  • / _at_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)
  • / _at_delegate /
  • delegate void PropertyChangedEventHandler()
  • / _at_event /
  • void add_PropertyChanged(PropertyChangedEventHandl
    er eventHandler)
  •  
  • / _at_event /
  • void remove_PropertyChanged(PropertyChangedEventHa
    ndler 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 _at_
  • class _at_class // class defined in J
  • int i obj._at_synchronized // accessing field
    named synchronized
  • Signing assemblies
  • / _at_assembly AssemblyKeyFile(key.snk) /
  • Declarative security
  • / _at_attribute FileIOPermission(SecurityAction.Dem
    and) /
  • ReadFile()
  • // demands for the permission before allowing
  • // the call

23
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
  • _at_com.class, _at_com.interface, _at_com.method, and so
    forth
  • Applications hosting Microsoft ActiveX controls
  • Exposing components to COM
  • Must have _at_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
  • / _at_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.InteropSe
    rvices 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
  • CodebehindVJSControl.ascx.jsl"
    Inherits"WebApplication1.VJSControl"
  • Codebehind file
  • // VJSControl.ascx.jsl
  • public abstract class VJSControl extends
    System.Web.UI.UserControl
  • private System.String customername ""
  • /_at_property/
  • public System.String get_customerName()
  • return customername
  • /_at_property/
  • public void set_customerName(System.String s)
  • customername s

42
Web Control Authoring (2)
  • Using a Web Control in a Web Forms page
  • jsl" AutoEventWireup"false" Inherits"VJSWebApp.W
    ebForm1"
  • Src"VJSControl.ascx"
  • ...
  • customerName"Thomas" runat"server"

43
Data Binding in Web Applications
  • jsl" AutoEventWireup"false" Inherits"WebApplicat
    ion1.WebForm1"
  • ...
  • DataSource'"get_Tables().get_Item(Customers).
  • get_DefaultView()") '

44
Web Service Proxy Generation
  • e1"
  • Package VJSWS1
  • ...
  • public class Service1 extends System.Web.Services.
    WebService
  • / _at_attribute WebMethod() /
  • public int AddOne(int x)
  • return x1

45
Proxy Generation
  • Command line for proxy generation
  • wsdl.exe /l"Microsoft.VJSharp.VJSharpCodeProvider
    , VJSharpCodeProvider, Version7.0.3300.0,
    Cultureneutral, PublicKeyTokenb03f5f7f11d50a3a"
    http//localhost/VJSWS1/Service1.asmx
  • Generated File
  • // Service1.jsl
  • public class Service1 extends System.Web.Services.
    Protocols.SoapHttpClientProtocol
  • ...
  • / _at_attribute System.Web.Services.Protocols.Soap
    DocumentMethodAttribute(...)/
  • public int AddOne(int x)
  • System.Object results
    this.Invoke(("AddOne").ToString (), new
    System.Object (System.Int32)x)
  • return ((int)(System.Int32)(results0))
  • ...

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
  • _at_dll.import, _at_dll.struct, _at_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
    /referencemanagedWrappers
  • 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 /referenceManagedWrappers
  • 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
    _at_com.register attribute
  • Conversion of class files that use Java/COM

51
Upgrading WFC Applications
  • Vjswfc.dll must be added as an explicit reference
    during command-line compilation
  • vjc /rvjswfc.dll Form1.java
  • tag format for WFC HTML controls
    modified
  • 5F7F8BDCF"
  • height20 width30 ... VIEWASTEXT

  • User HTML control class has to be compiled into a
    managed assembly
  • No designer support in Visual J IDE for WFC
    projects

52
Other Upgrade Issues
  • If you use RMI
  • You may use Web Services
  • If you use JNI
  • Use P/Invoke or J/Direct
  • If you use com.ms. that is unsupported (such as
    mtx, xml)
  • Use the corresponding .NET Frameworks (equivalent
    or better)

53
Availability
  • Beta 1 shipped on October 10, 2001
  • Beta 2 shipped on March 19, 2002
  • Add-on to Visual Studio .NET RTM/SP1
  • Available for download from MSDN
  • http//msdn.microsoft.com/visualj/jsharp/beta.asp
  • Visual J .NET Redist only version of Beta 2 also
    available for download
  • Localized versions
  • Final product availability
  • Mid-2002
  • Coupon in Visual Studio .NET boxes

54
Additional Resources
  • Community sites
  • http//www.gotdotnet.com/team/java
  • Visual J .NET newsgroup
  • microsoft.public.dotnet.vjsharp

55
  • Thank you for joining us for todays Microsoft
    Support
  • WebCast.
  • For information about all upcoming Support
    WebCasts
  • and access to the archived content (streaming
    media
  • files, PowerPoint slides, and transcripts),
    please visit
  • http//support.microsoft.com/webcasts/
  • We sincerely appreciate your feedback. Please
    send any
  • comments or suggestions regarding the Support
  • WebCasts to supweb_at_microsoft.com.
Write a Comment
User Comments (0)
About PowerShow.com