How should I convert Java code to C# code? - c#

I'm porting a Java library to C#. I'm using Visual Studio 2008, so I don't have the discontinued Microsoft Java Language Conversion Assistant program (JLCA).
My approach is to create a new solution with a similar project structure to the Java library, and to then copy the java code into a c# file and convert it to valid c# line-by-line. Considering that I find Java easy to read, the subtle differences in the two languages have surprised me.
Some things are easy to port (namespaces, inheritance etc.) but some things have been unexpectedly different, such as visibility of private members in nested classes, overriding virtual methods and the behaviour of built-in types. I don't fully understand these things and I'm sure there are lots of other differences I haven't seen yet.
I've got a long way to go on this project. What rules-of-thumb I can apply during this conversion to manage the language differences correctly?

Your doing it in the only sane way you can...the biggest help will be this document from Dare Obasanjo that lists the differences between the two languages:
http://www.25hoursaday.com/CsharpVsJava.html
BTW, change all getter and setter methods into properties...No need to have the C# library function just the same as the java library unless you are going for perfect interface compatibility.

Couple other options worth noting:
J# is Microsoft's Java language
implementation on .NET. You can
access Java libraries (up to version
1.4*, anyways).
*actually Java 1.1.4 for java.io/lang,
and 1.2 for java.util + keep in mind that J# end of
life is ~ 2015-2017 for J# 2.0 redist
Mono's IKVM also runs Java on
the CLR, with access to other .NET
programs.
Microsoft Visual Studio 2005 comes
with a "Java language conversion
assistant" that converts Java
programs to C# programs
automatically for you.

One more quick-and-dirty idea: you could use IKVM to convert the Java jar to a .NET assembly, then use Reflector--combined with the FileDisassembler Add-in--to disassemble it into a Visual C# project.
(By the way, I haven't actually used IKVM--anyone care to vouch that this process would work?)

If you have a small amount of code then a line by line conversion is probably the most efficient.
If you have a large amount of code I would consider:
Looking for a product that does the conversation for you.
Writing a script (Ruby or Perl might be a good candidate) to do the conversion for you - at least the monotonous stuff! It could be a simple search/replace for keyword differences and renaming of files. Gives you more time/fingers to concentrate on the harder stuff.

I'm not sure if it is really the best way to convert the code line by line especially if the obstacles become overwhelming. Of course the Java code gives you a guideline and the basic structure but I think at the end the most important thing is that the library does provide the same functionality like it does in Java.

Related

To make development portable to Java, does it make sense to do the whole development on J# vs C#?

To make development portable to Java, does it make sense to do the whole development on J# vs C#? What happens to missing bits in Java that exist in C# like lambda expression and so on?
What is the best way to achieve portability?
I definitely wouldn't use J# - it's not supported any more, and it only supported Java 1.1.4 anyway, IIRC.
I would personally recommend keeping the overall architecture consistent between the two languages, but then write the code separately, manually, taking into account the different idioms in the different languages.
If your codebase uses data-driven tests, it would be good to share that data between the two languages, as a way of helping to ensure data portability.
I suggest you don't use J# anymore as it has been discontinued. The last version has been shipped with Visual Studio 2005.
In addition to J#-specific language extensions and .NET CLR support, its runtime library implements Java 2 Collections Framework (without the java.util.concurrent extensions, though) and even some JFC/Swing, via the Supplemental UI Library.
So you'll be limited to the Java 1.4 API.
Given that J# has been discontinued long ago, I wouldn't suggest you invest your time into it.
If you really need portability between JVM and CLR, I'd take a look at IKVM (implements Java 1.7 API on top of CLR), Scala for .NET (discontinued circa Scala 2.10) or languages like Ruby (JRuby/IronRuby) or Python (Jython/IronPython).
Alternatively, you can generate your C# for .NET -- there're Java to C# converters available.

Implementing C# for the JVM

Is anyone attempting to implement C# for the JVM? As a Java developer, I've been eyeing C# with envy, but am unwilling to give up the portability and maturity of the JVM, not to mention the diverse range of tools for it.
I know there are some important differences between the JVM and CLR but is there anything that is a showstopper?
There are very significant differences between the CLR and the JVM.
A few examples:
Java doesn't have user-defined value types
Java generics is completely different to .NET generics
Many aspects of C# depend on elements of the framework - delegates etc. You'd need to port the library as well, even for language aspects.
Java doesn't support things like properties and events at a JVM level. You could fake some of this, but it wouldn't be the same.
I don't believe Java has any equivalent to pass-by-reference parameters, even at the JVM level
Subtleties to do with the different memory models would quite possibly bite, although I'm not sure how much is in the C# spec.
Unsafe code in general probably isn't possible in Java
Interoperability with native code is very different between JNI and P/Invoke. This probably isn't much of a problem for you.
You'd have to fake operator overloading and user-defined conversions
You could probably port a lot of C# - but you'd be left with a pretty unsatisfactory experience, IMO.
Going the other way, are you aware of IKVM? It allows you to run Java code in .NET.
Visit http://code.google.com/p/stab-language
The code below if a Stab language code for JVM
using java.lang;
using stab.query;
public class Test {
public static void main(String[] args) {
// Sorts the arguments starting with "-" by length and then using the default
// string comparison
var query = from s in Query.asIterable(args)
where s.startsWith("-")
orderby s.length(), s
select s;
foreach (var s in query) {
System.out.println(s);
}
}
}
Bytecode transpilers
Grasshopper can take a CLR bytecode and transpile it for JVM. Intended primarily for web apps, it does not provide e.g. JVM implementation of Windows Forms classes. Seems somewhat dated, though. The web talks about ASP.NET 2.0, Visual Studio 2008 and so on. First mentioned by #alex
XMLVM can take CLR or JVM bytecode as input and produce either as output. Additionally it can output Javascript or Objective-C. No releases yet, only Subversion. "Experimental development version that is not to be used in a production environment."
IKVM goes in the other direction than OP wants. It provides a JVM implementation running on CLR, a JVM to CLR bytecode transpiler and a CLR library method stub generator for Java. http://www.ikvm.net/uses.html Mentioned by #Jon Skeet
RPC
Why not have CLR and JVM running alongside and make the communication as much frictionless as possible? This is not what the OP wants, but some other answers are already quite off topic in different ways, so let's cover it.
RabbitMQ, has a free option, it is a RPC server written in Erlang with API libraries for C#, Java and more.
jnBridge, the licence may be too expensive for some prospective users.
gRPC, and similar modern RPC libraries offer wide language support, code generation for client libraries in these languages, language independent wire format for data, advanced features like cascading call-cancellation and so on.
Programming languages
Write once, run everywhere ;)
Haxe, compiles to C#/CLR, Java/JVM, Javascript, Flash, Python, … Provides interop mechanisms for each of the target languages. Can be thought about as an ActionScript3 successor to some degree. Seems pretty solid stuff, with at least one company actually depending on it. Much more trustworthy than Stab, mentioned next.
Stab brings some C# features and Java interoperability. Not very useful, you get some C# features, but what you interact with is Java code which does not use them. https://softwareengineering.stackexchange.com/a/132080/45826 The language is relatively obscure, possibly abandoned, with little promise to become better. First mentioned here by #Vns.
Gust of fresh air for the JVM platform ;)
Scala, Kotlin, others, are fairly nice languages running on top of JVM which bring features that a C# programmer may miss in Java. Especially Kotlin feels like a reasonable alternative to C# in the JVM world. Scala may be a bit too large language for a programmer to get comfortable with in a short time.
Mono
That is certainly an option too. Why transpile to JVM if Mono can run it as it is. First mentioned by #ferhrosa
NEW YORK — Nov. 12, 2014 — On Wednesday, Microsoft Corp. reinforced its commitment to cross-platform developer experiences by open sourcing the full server-side .NET stack and expanding .NET to run on the Linux and Mac OS platforms.
According to this press release from which the quote comes, Visual Studio 2015 will add Linux/Mono as a supported platform.
This is a blog written by the Mono project people about it, from the other side: .NET Source Code Integration (November 2014).
.NET Core
A Windows/Linux multiplatform version of (some of) .Net governed by Microsoft. 'nuff said https://github.com/dotnet/core.
Conclusion
It would be now necessary to give these tools/frameworks a try and see how much friction there is. The OP wants to write in C# for the JVM, which may actually work quite well using Grasshopper.
Doing this with the goal to mix C# and Java world libraries in a single codebase may not work so well.
Sources
http://blog.pluralsight.com/new-course-making-java-and-c-work-together-jvm-and-net-clr-interop
It might be simpler to write a converter from IL to bytecode. That way you'd automatically get support for any .NET language on the JVM.
However, this is such an obvious idea that if this hasn't already been done, it's probably extremely hard, or hard to do well/usefully.
Look at Grasshopper. It is a Visual Studio-based SDK and patented .NET to Java converter that enables you to run .NET Web and server applications on Linux® and other Java-enabled platforms.
An option for cross-platform development in C# could be mono: http://www.mono-project.com/
You can use a source-to-source compiler to translate C# into a language than runs on the JVM. For example, there are several C# to Java converters that would allow C# applications to run on the JVM after being translated into Java.
This answer may be late for you, but this one is just new. You may want to checkout Kotlin programming language. It offers the syntactic sugars which C# has and its the closest to C# syntax too, other than any Non-Java JVM language. Its from JetBrains.
I can see two reasons why this isn't getting much enthusiasm.
The first thing to realise is that, when it comes to the actual features of the language, C# and Java are very close. Not only are C# amd Java close, they are also moving in similar directions. There are some features that the JVM won't currently support out of the box, but that's not the real problem. You can always fake what is missing. I think people prefer waiting for Java to get some more sugar, than to create an Almost-Java from scratch. By the time the port is ready, Java may have decided to catch up.
Secondly, the reason why developers prefer C# isn't so much the language itself, but the tools around it, their two-way relationship with C# and how Microsoft supports the whole thing. For example, the C#-XAML combo is friendlier than JavaFX, because C# and XAML were hacked for eachother (e.g. partial classes in C#, bindings in XAML and more). Using C# on JavaFX doesn't improve much. To get the C# experience on the JVM, you need to also port the tools, and that's a much bigger project. Not even Mono will bother.
So, my advice to a Java developer, who wants to use a fancier language ontop of familiar tools, is to check out the existing JVM languages.
Mono is an option too, but I have always been skeptical of it. Even though it is C#-.NET and cross-platform, things built with Microsoft's tools won't generally work on Mono. It is essentially its own thing. We'll see what happens now that Microsoft said they'll be collaborating.

Why doesn't Sun do a C# to Java byte code compiler?

We Want to Run Our C# Code on the JVM
My company has a large C# code base. Well over half of this code is our core engine for creating, reading, modifying, calculating and writing Excel workbooks. We frequently get questions from customers and potential customers asking whether we are going to build a Java version of our engine - many of them are not at all interested in the UI. We even have a few customers who have taken the trouble to use our .NET library from their Java applications.
So, we would like to build a Java version of our core engine, ideally without maintaining a separate Java source code base.
Eric Sink described this problem very well. I am in a similar position except for the fact that our software license includes royalty free deployment, making Eric's choice of Mainsoft a nonstarter for us.
I have been Googling the likes of "c# to jvm" every few months for several years now with no joy. Having spent ~7 years developing similar software for Java, I am confident that the .NET APIs we use in our core engine could easily be encapsulated and we could accomplish everything we need using the Java libraries. So, if we only had a C# -> JVM compiler we could build our core engine for Java and we would no longer have to turn away Java developers who would like to use it.
I am not asking for the technical reasons why Sun does not do a C# compiler. I recognize that Java has no properties or an unsigned 64 bit long, etc... For the sake of argument, just assume that all of these technical issues could be dealt with by extending the JVM and / or other means.
And I am not asking for yet another debate on why one language / stack might be better than the other. The reality in our business is that there are plenty of potential customers using each.
Why Should Sun do a C# Compiler? (IMO of course)
Making it easier to run C# code on the Java platform means more developers and more software for the platform. Is there anything more important to the success of a platform? Jonathan Schwartz is a software guy. I will leave it to others smarter than me to decide whether or not he took on an impossible job as President and CEO of Sun, but having met with Jonathan shortly after he joined Sun my impression is that he understands software and the need for a large base of developers.
So Why Doesn't Sun do a C# Compiler?
NIH syndrome?
The ghost of Scott McNealy?
Too many Java developers dislike or distrust anything related to Microsoft?
They agreed not to as part of taking the big bucks?
???
There must be a good reason. I just cannot for the life of me figure out what it is...
Firstly Sun has zero incentive to implement a C# compiler on the JVM because they have something very similar called the Java programming language.
Its also not really as simple as just implementing a compiler as the Java standard class libraries are not the same as the .net Base Class Libraries. You would end up having to change all the .NET API calls to Java API calls.
Micrsoft had a product called J# which was meant to be for Java to .NET conversion but in the end no one used it as the API was limited to pre Java 2 API so it was mostly useless. It would be the same if Sun implemented parts of the .NET BCL, as only the core portions of it are standardised and royalty free. Parts like ASP.NET and WPF, WCF etc are not part of the ECMA standards and so Sun would need Microsofts permission to implement those API's.
If enough customers want a java version to make business sense to port your application to java then do it, you just wont ever get any help from Sun via a C# to JVM compiler.
Joe Erickson wrote:
Making it easier to run C# code on the
Java platform means more developers
and more software for the platform.
This is an untrue statement. Running C# code on the JVM does not create Java programmers, it creates C# programmers who can execute on a JVM. It only expands the reach of C#, assuming the JVM also translates any microsoft specific calls (i.e. win32) into something that is platform neutral. So if Sun translates IL to Java Bytecode, the only group it helps is: Microsoft. And, given Sun's history with Microsoft during the original C#-Java schism/Visual J++ lawsuits...
Plus, you have to face the technical infeasibility, whether you want to or not. There are fundamental differences in the way the bytecodes are executed that are far more important issues than whether or not there's an unsigned long datatype.
If you must have C# on a non-Microsoft platform, use Mono
Why doesn't Microsoft do a C# to Java byte code compiler? Why don't you do it? There are open specs on each side...
"So, we would like to build a Java version of our core engine, ideally without maintaining a separate Java source code base."
Basically, you want to compile your C# code unmodified, and have it run in a Java-only environment.
IKVM is not what you want. IKVM is three main things.
a. ikvm - CLI implementation of a Java virtual machine (note that this uses Classpath (now OpenJDK) for the Java class library).
b. ikvmc - Compiles java bytecode to CLI bytecode.
c. ikvmstub - Generates java stub classes that call CLI code.
Note that all of these tools depend on CLI at runtime. What you want is exactly the opposite of IKVM, which is of course MVKI (Most Venerable Kompiler Intermediary) :):
a. mvki - Java implementation of a CLI virtual machine (presumably this would use Mono or DotGNU for the class library).
b. mvkic - Compiles CLI bytecode to Java bytecode.
c. mvkistub - Generates CLI stub classes that call Java
Note that none of these would require an existing implementation of the .NET Framework at runtime, so they should be satisfactory to your Java-only customers.
Unfortunately, as far as I know MVKI does not exist, so you're best off doing a manual port (which would inevitably be cleaner, albeit more work).
Edit: Based on the description of Mainsoft, it appears to be similar to MVKI, though I'm not sure what they do for the class library, and unlike IKVM it's not FOSS.
http://jsc.sourceforge.net/ is a c# cross compiler that can convert .NET code to Java (amongst other things).
Expose your .NET API as ASMX web services and you should be good to go.
EDIT: For more heavy-usage scenarios, it would be worth looking into Windows Communication Foundation (WCF). This has built-in, configurable support for security, streaming, different transport scenarios (HTTP, TCP/IP, local named pipes). You are not restricted to SOAP message encoding, but that would probably be the easiest way to interop with Java.
I'm not too sure about your exact scenario, but if you're dealing with large files and the .NET code and Java code are both running locally, you can just save the file to the user's hard drive using .NET and then fetch it from your Java app.
There must be a good reason. I just cannot for the life of me figure out what it is...
It is easy to believe that companies are non-profit organisations which have your interests at heart. It is easy to forget that the only purpose for a listed company is to make money for it share holders. This is a legal obligation and directors/executives have been sacked/sued if share holders don't believe they have failed to do this.
Sun makes Java free because it helps sell their hardware which how it makes money from Java. IBM makes Java free because it helps them make more money on their consulting.
If Sun were to spend money on a C# converter how would it make that money back and make a profit. Imagine you have to convince Sun's share holders. If you can, Sun will make a C# converter.
I wonder whether the Mono project could have made less work for themselves by targeting the JVM instead of developing and maintaining their own virtual machine from scratch. Development effort could have focused on a C# cross-compiler and porting clean-room implementations of the .NET libraries to the JVM. Sort of like an open-source version of what Mainsoft has done. You could then enable inter-language calls between Java and C# code in the same JVM, and deploy Applets and Java Web Start applications written in C#.
I know this might not be what your looking for, but here are some possible alternatives that (if not to you) could be useful to others.
C: You could port as much as possible to C. Now you can make a wrapper in C# and Java (and any other language that can communicate with C) that makes it feel native to their language while programming. The problem now is that you (or them, depending your license) has to build the C part for each platform.
Fantom*: A programming language that according to their home page,
is:
Portable: Write code portable to the Java VM, .NET CLR, and JavaScript in the browser.
Familiar: Syntax Java and C# programmers will feel at home with Fantom's evolutionary syntax.
Object Oriented: Everything subclasses from Obj. Value types when you need the performance.
Functional: Functions and closures are baked in.
Static and Dynamically Typed: Don't like the extremes - take the middle of the road.
Haxe*: (pronounced hex) is cross platform language that compiles to other languages. Soon C# and Java will be supported. It currently supports:
Javascript: You can compile a Haxe program to a single .js file. You can access the typed browser DOM APIs with autocompletion
support, and all the dependencies will be resolved at compilation
time.
Flash: You can compile a Haxe program to a .swf file. Haxe is compatible with Flash Players 6 to 10, with either "old" Flash 8 API
or newest AS3/Flash9+ API. Haxe offers very good performance and
language features to develop Flash content.
NekoVM: You can compile a Haxe program to NekoVM bytecode. This can be used for server-side programming such as dynamic webpages
(using mod_neko for Apache) and also for command-line or desktop
applications, since NekoVM can be embedded and extended with some
other DLL.
PHP: You can compile a Haxe program to .php files. This will enable you to use a high level strictly-typed language such as haXe
while keeping full compatibility with your existing server platform
and libraries.
C++: You can now generate C++ code from your Haxe source code, with the required Makefiles. This is very useful for creating native
applications, for instance in iPhone development.
Haxe Community. (2011, March 11). Haxe Introduction. Retrieved January 29, 2011, from http://old.haxe.org/doc/intro
You can learn more about why Haxe is useful here.
*I have never used this language and I don't know how well this would work.
I made a comment that should really have been an answer:
It is just not technically possible at this point to implement the C# spec on the JVM. C# supports pointers, unsigned types, user defined value types, true generics, passing by reference, and loads of other things. For a very C#-like JVM language, check out Stab.
Mainsoft fakes it. I am sure it takes enormous effort on their part.
Have fun.
Must break checked exceptions.
Must find a way to implement delegates (which are like single-method interfaces added no earlier than load time).
You can run your .NET code and Java code in the same interpreter! See the IKVM .NET-based JVM, and the Boo and Java wiki page for an example use case (using the .NET-based Boo language to write applications using Java libraries).
Joe, I suggest you investigate IKVM. You might find something there that scratches your itch
If i was doing something like cross platform cross language support, I would create a 'common api' since the languages are similar in syntax you could make a translator easy enough. Then instead of calling java or .net apis directly from the core, you would call your 'common api' which would re implement the java and .net apis you would need. In this way you could create a cross language sandbox if you will. Since the main differences in java and c# are object definitions, I would get those by reflecting the C# dlls, and then reconstruct the constructs, then it would be easy to have an interpreter run through and implement the function bodies and convert properties to getters setters already knowing the structure of the files. This of course is assuming .net 2.0, some of the features in 3.0 and 3.5 become very difficult to 'interpret'
It would be complex, but probably not as complex as reconstructing a core in java by hand, and having to have 2 teams working on them seperatly. If this idea sparks some inspiration i might create one. I would really rather see a simpler stable mono installation for mac.
Basically I think a code level interpreter based on a set of common api classes is something very possible to write with a team in a week or two.
Simple. Because Sun would rather not be sued by Microsoft. And while we as programmers might see no viable reason for a suit, keep in mind that Microsoft is quite a bigger company than Sun and has the power to boss them around.
Sun fortunately is in the position of being quite more open than Microsoft however. If such a demand exists, either open source or a third-party could make this compiler for Java and Sun wouldn't have to take the heat.
JACIL is an apparently dead project that attempts to do the reverse of IKVM. Perhaps some motivated folks could use it as a starting point for a viable .Net to JVM compiler.
I guess the better question is why don't you write a C# to Java byte code compiler, if you want one to exist. Waiting for corporate overlords to do something is a bad idea.
A suggestion for creating such an implementation: take Mono's or .GNU's C# front end. Don't bother writing your own.
I think you will find that the Mainsoft, Enterprise Edition tool allows you to run most/maybe all your .NET code under the Java JVM... Seems to be focused more on ASP.NET but will allow C#. It has been available for some time, pity they don't publicize it better!
Warning blurb follows....
Mainsoft® is Java-.NET
interoperability software that enables
IT organizations to move to
Java-enabled platforms such as Linux
while preserving existing investments
in .NET code and skills. The software
integrates seamlessly into the Visual
Studio® development environment,
enabling C# and Visual Basic
developers to rapidly develop and
maintain server and Web applications
that run on Windows, Java EE platforms
or both, thereby reducing application
development and maintenance costs,
time-to-production and total cost of
ownership.

C# --> Java code generator

I have a small (~2000 lines of code) class that I would like to use from both java & .NET. There are several approaches to do this - among them wrapping the class as a service, using some interop voodoo, or duplicating the code to both C# & java.
Do you know an out-of-the-box tool that accomplishes the latter - takes a simple C# class with no dependencies and converts it to an equivalent java class?
IKVM.NET does pretty good job in taking a jar file and compiling it to a managed .NET assembly.
If it is small (or in fact, even if it is large), I'm not sure of the wisdom of mechanical translation tools; I've simply never had much joy with them. However, one option would be to write the .NET code in J#.
But I stress - if it was me, I'd manually port it between the two manually and maintain them separately. Most of the time the differences aren't huge - signed bytes, the boxing differences, etc. Of course, anything with delegates will need changing - and captured variables work differently, etc etc.
There used to be a COM bridge and you can register C# assemblies for use in COM with regasm.exe or visual studio.
It's not really what you asked for, but I would just create a simple C# to Java translator.
The differences are not that huge and you seem to be the author of the source so you can avoid nasty constructs that are quite difficult to translate. That way your translator would be quite simple. I would go from C# to Java because C# is more expressive, and you can emulate almost all the C# functions in Java.
Actually cs2java seems to do just that.
This is list of tools I know. Sharpen or j2cstranslator looks like good options.

Should C# and Java incorporate each others syntax?

I've been jumping from C# to Java an awful lot and the "differences" between the two are a bit of an annoyance.
Would it be possible to write a set of extentions/plugins that would merge the two languages syntaxes.
I'm talking about adding either IDE support or using language constructs that would for example:
treat these two lines equivalently:
System.out.println("Blah");
Console.out.writeline("Blah");
Automatically notice that when you type in string you mean String
Recognise common API calls and translate them in the background.
The end goal being to be able to write a java/C# program and to pick at compile time which VM/Runtime you are targeting.
If you could do this would it be a good idea?
If not why not?
The two languages are so similar it's painful in some aspects but in other aspects they are really different.
I've seen Code that will translate a C# project into Java and I'm assuming there is probably the reverse, what I am proposing is a middle ground, so we can all just "get along".
No, absolutely not. Certainly not in the languages themselves (as implied by the title) and preferably (IMO) not in the IDEs (as requested in the body).
They are different languages. The idioms and conventions are subtly different. I don't want to be thinking in Java when I'm writing C# or vice versa. I believe developers should be actively encouraged to separate their thinking. It's not too hard to switch between the two, but that switch should be present, IMO.
While I totally agree with Jon Skeet, if you must have this why not create your own library of Java API so you can create System.out namespace which has a method call printLn which calls Console.Writeline()?
That gets you close to what you want.
Just because Java and C# share some similar syntax you need to see past this and think in terms of Java Platform and .NET Platform. The two are distinctly different, so my answer is definitely not.
There actually already is a Java language for the .NET framework, developed by microsoft: J#
This way you get the java-syntax but you are still developing with the .NET framework.
But i am not recommending anyone to use it.
I knew Java before i knew C# so i tried out J# because i thought it would be an easier transition. At first I liked it but after I tried C# I'm never going back. First of all, nobody uses J# so it's kinda hard to find examples and tutorials. Second, C# has (IMO) much more convenient syntax, specially for events, properties, lambda, anonymus methods and alot of other things, it's also being updated every now and then with even more syntax sugar which i don't think J# is.
Maybe if you often write Java and sometimes have to write a .net app it might be a good option.
I think no. I also switch from java to c#. But if the syntax is identical was is to stop someone from trying to compile c# in a Java compiler, or vice-versa.
Visual Studio actually ships with a Java to C# converter, which tries to do some of the things you mention. Unfortunately it fails miserably (1) for anything beyond the simple hello world application.
Despite being very similar on the surface, there are many significant differences between Java and C#, so you would achieve very little by doing what you suggest imo.
(1) To be fair, it actually does a fairly good job if you consider the limitations given for such a task, but in practice the resulting code is of limited use and you have to do a lot of clean up after the conversion.
Firstly what you are describing is not a difference in language syntax but a differences in class libraries. Both languages are relatively simple in terms of keywords and features but understanding or knowing the libraries and how they operate requires considerable learning.
The mistakes you are describing are things that the developer should not be making to begin with - the IDE should not be guessing. There are going to be many cases where you can't easily / trivially translate between java or dotnet. In the end a skilled developer learns and knows when and which class libraries to use.
Actually in the beginning there was no dotnet - microsoft was behind java. They however proceeded to change java in ways not compatible with the java plstform standard. To paraphrase sun sued microsoft and won I'm court. Following that ms proceeded to create dotnet and particularly c# which became microsofts VM platform. Of course along the way a whole stack of things got changed. Microsoft introduced many things which broke Javas run anywhere etc. They have done the same thing with dotnet which have cause problems for the mono team to be able to faithfully reimplemwnt everything for other non windows platforms.
• String vs string.
• lowercase method names (java) v uppercase method names(dotnet).
• Giving java keywords new names - "package".
In the end dotnet was microsoft response so they can control the platform and do their own thing instead of following a standar

Categories