Java vs. .NET - Austin Java Users Group

Download Report

Transcript Java vs. .NET - Austin Java Users Group

Java vs. .NET
Java vs. C#
Swing vs. WinForms
6/10/2004
The Object Services Company,
Inc.
1
C# Language Differences
Class Declaration
.NET Types
Event Handling
Exception Handling
Operation Parameters
Operation Visibility
6/10/2004
Component Assemblies
Package Structure
Class Properties and
Structures
Class Indexers
Source Code Attributes
The Object Services Company,
Inc.
2
Class Declaration
• class SomeClass : ExtendedClass,
Interface1, Interface2
– SomeClass extends ExtendedClass
– SomeClass implements Interface1 and
Inteface2
• More than one object can be declared
inside the .cs file
6/10/2004
The Object Services Company,
Inc.
3
Package Structure
• To import use ‘using’ keyword
6/10/2004
The Object Services Company,
Inc.
4
.NET Types
• Value Types can be used as
Objects
– Aliased to System types so
that any .NET language can
use them from any other .NET
language
– (See column to the right) 
• Java boolean
– bool (System.Boolean)
• Java bytes
– byte (System.Sbyte)
• Java char
– char (System.Char)
• Java int
• Structures
– Can have constructors
– int (System.Int32)
• Java long
– long (System.Int64)
• Java float
– float (System.Single)
• Java double
– double (System.Double)
6/10/2004
The Object Services Company,
Inc.
5
Exception Handling
• Catch Block can trap
no Exception or
specific Exceptions
6/10/2004
The Object Services Company,
Inc.
6
Event Handling
• .NET Delegates
– Much different than Java
6/10/2004
The Object Services Company,
Inc.
7
Class Properties
• Declare a variable
• Only a getter implies
a read-only property
• Can use lazy
initialization
• Can be defined in an
Interface
6/10/2004
The Object Services Company,
Inc.
8
Class Indexers
• Instances of a class
can be referenced
with Array notation on
the class
6/10/2004
The Object Services Company,
Inc.
9
Operation Parameters
• Undetermined Number of Parameters
– public void methodCaller( params int[] a );
• methodCaller( 1 );
• methodCaller( 1, 2, 3, 4, 5 );
• Pass by Reference
– public void increment( ref int a )
• Can possibly change the value of ‘a’
• Pass by Reference and Change Value
– public void DoNothing( out int a )
• Ensures ‘a’ is changed
6/10/2004
The Object Services Company,
Inc.
10
Operation Visibility
• Overriding Inherited Operations
– Requires superclass method to be marked ‘virtual’
– Overriding method must be marked ‘override’
• public, protected, and private are the same as in Java
• internal
– Member is accessible from the entire assembly.
– More than one object can be declared inside the .cs file.
– Each object has a handle to the internal member
• protected internal
– A union of protected and internal.
– Can be accessed from the entire assembly, or within objects
which derive from this class
6/10/2004
The Object Services Company,
Inc.
11
Component Assemblies
• Common Language Runtime (CLR)
– Similar to Java VM
– But multi-lingual, i.e. VB, C++, C#
• Shareable Dynamic Link Libraries
• Shareable Code Modules
– Linked at compile-time
• Transparency to all .NET languages
– Should be aware of data types, naming and
formatting standards
6/10/2004
The Object Services Company,
Inc.
12
Source Code Attributes
• Used for compiler and runtime processing
• Attributes are derived from
System.Attribute
• New and confusing for us Java
Developers
6/10/2004
The Object Services Company,
Inc.
13
Swing and WinForms
• .NET has the same GUI components as Swing
• No Layout Managers
• .NET has Data Binding!
– DataProvider manages DataSources
– DataSet is a disconnected, in-memory data cache
• Lots of 3rd Party Controls converted from COM
Components to .NET
– Especially Tables and 2D Graphs
• Extensible Application Markup Language
(XAML)
6/10/2004
The Object Services Company,
Inc.
14
IDE’s
• Visual Studio
– Requires .NET Framework install first
– Horrendously lengthy installation
• SharpDevelop
– Open Source
• Improve C# Plugin
– Eclipse
• CodeWright
– By Borland
6/10/2004
The Object Services Company,
Inc.
15
References
• C# for Java
Developers
– Allen Jones, Adam
Freeman
– Microsoft Press
• C# Language Pocket
Reference
– Peter Dayton, Ben
Albahari, Ted Neward
– O’Reilly Books
6/10/2004
•
•
•
•
•
XAML
C# Namespaces Doc
.NET CodeDom
GotDotNet
How Do
I?...Common Tasks
• .NET 24/7
• Windows Forms
QuickStart Tutorial
The Object Services Company,
Inc.
16
Conclusions
• More web info for Java than .NET …for
now…
• Longhorn and XAML
– XAML can be translated at run-time for
WinForms or WebForms
• If Windows is the only client platform for
deployment…why not use .NET?
– Front-end .NET and Back-end Java J2EE?
6/10/2004
The Object Services Company,
Inc.
17