java vs c#


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: java vs c#

  1. #1
    Join Date
    Mar 2008
    Posts
    53

    java vs c#

    Hello,
    I've heard that in Java even the methods (of a class) can be generics? Are this correct? Could you give me a simple examples ? ( I come from c++ and this for me sounds strange)...
    Furthermore: Does C# permit the same thing? (generic methods) ?

    thanks in advance...

  2. #2
    Join Date
    Jul 2004
    Posts
    81
    Sure, and the syntax is nearly identical between Java and C# for this:

    Java:
    public static <T> short Compare(T Arg1, T Arg2)

    C#:
    public static short Compare<T>(T Arg1, T Arg2)


    You can call it either by explicitly specifying the type or not:
    Java:
    o.Compare(1, 2);
    o.<int>Compare(1, 2);

    C#:
    o.Compare(1, 2);
    o.Compare<int>(1, 2);
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  3. #3
    Join Date
    Mar 2008
    Posts
    53
    thanks for reply...and Can these method be virtual too? (I suppose of course for java, being in Java all methods virtual by default)...

  4. #4
    Join Date
    Jul 2004
    Posts
    81
    Yes:

    C#:
    public virtual short Compare<T>(T Arg1, T Arg2)

    And as you said, all methods in Java are virtual without the need for a keyword.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  5. #5
    Join Date
    Mar 2008
    Posts
    53
    furthermore: does C# (and java) permit overloading of methods?

  6. #6
    Join Date
    Jul 2004
    Posts
    81
    Yes. Overloading requires no special syntax in either language - just create a new method with the same name but different signature.

    If what you meant was overriding base class methods, then you can use:

    C#:
    protected override void TestMethod()
    {
    }

    Java:
    @Override
    protected void TestMethod()
    {
    }

    C# additionally allows shadowing base class methods:
    protected new void TestMethod()
    {
    }
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  7. #7
    Join Date
    Mar 2006
    Posts
    100
    ONE BID DIFFERANCE WITH OVERLOADING IN JAVA VS C#.........

    You cannot I repeat CANNOT overload operators (this got me in a bind in my first java project). However, is some frameworks and DSLs, like groovy, this functionality is added.
    "America... just a nation of two hundred million used car salesmen with all the money we need to buy guns and no qualms about killing anybody else in the world who tries to make us uncomfortable. " - Hunter S. Thompson

    MCAD
    IBM Business Partner

  8. #8
    Join Date
    Mar 2008
    Posts
    53
    could anyone explain me the sense of the
    "Comparing C# and Java Generics", Anders Hejlsberg reply at paragraph 3 ("Issue number two, and.......) ?
    http://www.artima.com/intv/generics2.html
    I don't understand the sense of what he says about reflection in java (is it possibile or not?)

    thanks,

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 05:58 AM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  4. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center