This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
is there an effective tool to convert c# to java?
I'm not very experienced with Java and have a lot of C# that I would like to translate into Java syntax so it would become compilable.
Reason: Android and Google Cloud
I know the API/Platforms have different structures, but lets say we dont need a 100% compability, but just to get "core functionalitet" translated. The GUI itself is one story of its own, as I've learned. But instead of rewriting every SWITCH-CASE, rebuild every Class etc. it would be nice to "map" the objects to Java equals and then do a recompile on the Android/Google platform.
I am sure there would be something that cant be translated as its a "C# only thing" - but just like every language is possible to generate .NET/MONO I thought there might be a Java -> .Net available too and therefore also a decompiler kinda thing?
So are there any easy ways to overcome this translation by Frameworks, SDK or other similar methods that will take 80-95% of the task automatically?
Have a look here: JSC.
But beside, there are some c# concepts which don't easyli translate into java.
.NET and Mono are compatible because both are VMs that run C# code. Grasshopper claims to allow you to run .NET classes on the JVM, but I haven't used it. It won't work at all for Android because Android isn't the JVM, but rather Dalvik.
The differences between C# and Java are more than "structural" as you put it, and translating from one language to another is more complicated than I think you understand.
I know Microsoft has a tool that's supposed to help convert Java to C#, but considering that a great many java applications reference libraries outside of the main system (apache being the most prominent example) this type of tool would be a monumental task.
C# also has data types that aren't supported at all in Java, such as unsigned types and stack-allocated objects. Writing translations from CLR to Java bytecode would be difficult indeed. And if you're using lambda functions in your code, kiss this idea goodbye.
Then there's the fact that not all language features in Java are available to the Davlik JVM.
I'm not a microsoft fanboy, but here's a comparison of the two languages that will give you an idea why I doubt this tool exists.
http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java
Related
This question already has answers here:
How can I obfuscate my c# code, so it can't be deobfuscated so easily? [closed]
(4 answers)
Closed 5 years ago.
I have made an PC app in visual studio 2017 .net c# and compiled it to an exe. And then I thought my code was safe and nobody could see it because it was compiled, but when I open the exe in a program like .net reflector I can see the source code.
Is there any way I can prevent that? Or protect me against Decompiling??
There's really no point in attempting this.
While you'll be inundated with "obfuscation", this is a poor waste of time.
Deobfuscators are getting better all the time.
If someone wants your code bad enough they'll get it no matter what you do.
Frankly, if you are asking this question then the code you wrote isn't worth the time it would take to protect it.
You cannot prevent decompiling, if you compile into MSIL (intermediate language). In such case you need to use obfuscation
For a deeper discussion on the subject check out this post .NET obfuscation tools/strategy
You can find a similar discussion here How can I obfuscate my c# code, so it can't be deobfuscated so easily?
You can also opt to generate a native image using Ngen.exe for a specific platform - that will bypass the IL and generate compiled processor specific machine code, and that one is pretty much safe from standpoint of reverse - engineering.
Using an IL is a quite common design choice - and it has it's drawbacks and benefits - the main ones being easier support of multiple languages on one platform, and multiple target platforms, i.e cross platform
To get a glimpse of some of the benefits of using IL - check this out - stackoverflow.com/questions/1926386/…
Java also uses an intermediate language - java bytecode - javaworld.com/article/2077233/core-java/bytecode-basics.html
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am coming towards the end of a project that I created in C#. Unfortunately, the target hardware only comes with compilers for C/C++. My dad is an embedded programmer so he will be making the necessary code to integrate with the hardware, but in the meantime I need to find a way to translate the language. Free translators are a very high preference as I am extremely tight on funds at the moment.
While I am not fluent in C++, with a dirty translation I should be able to figure out most of what is required to make it run.
Edit:
The target platform is mbed Microcontroller
Don't. This will not work.
C# has a garbage collector. C and C++ don't. You will have to rethink how you allocate objects and release them in C++.
Chances are, since you already have completed the project, rewriting it in C/C++ will be quite easy. You already understand the problem and have expressed it once before.
There is no 1 to 1 mapping from c# to c++. The programming model and platforms are very different at the lower levels. Take memory management for example.
Your best chance is either to rewrite your application or try to get .NET Compact Framework or .NET Micro Framework to run in the hardware.
Edit:
Note that at least the .NET Micro Framework has a porting kit if your hardware is not supported.
Since design is half the battle in application development, your C# prototype should serve you well, but you are unlikely to find a suitable automatic translation tool. If you have not made heavy use of the .NET class library, especially those parts that relate to the underlying OS API, C# should be easily manually translated to C++. The code body syntax and semantics are very similar; it is the enclosing structural elements such as class definitions that are more different.
The required effort depends on the size of the application code, but much of that is mechanistic. The biggest difference being that you need to be more careful with memory management in C++ since there is no automatic garbage collection.
Learn C or C++. There are no alternatives.
Both languages are radically different from C# and .NET, and automatic conversion is not possible. (and if it were, it certainly wouldn't allow you to "figure out most of what is required to make it run". It would be completely unrecognizable code, that'd be impossible to read or extend.)
In order to write a working C or C++ program, a C or C++ programmer needs to write the code. The good news is that it doesn't have to be that difficult. You don't have to learn every corner of the C++ language. But you do need to learn the basics.
If you're looking for the quick and dirty way to get off the ground, learning C might be a better option, because the language is so much smaller and simpler. But C++ is doable too. Just don't think you can get away with reading a 15-minute online tutorial.
There are no translators.
The .NET Micro Framework has been ported to a Phycore LPC3180 (NXP) platform that is not to dissimilar to your board so it can be done but you still need to port the .NET framwork to your platform.
It is unlikely that you will be able to use Mono AOT unless you are going to port Meamo to to your mbed board.
Any porting would require you to be able to program C code.
The best and fastest way forward would be for You to learn C++.
The differences between C++ and C# are not to big once you get going with C++ and understand the differences. You also going to have to use the mbed library for your hardware control and communications instead of what is provided by C#.
The C# code was a good prototype to debug your program design but it is not going to help you on the target. Now that you understand the problem it should not be to hard.
I'm not sure how you got this far without realising that the target platform couldn't run .NET, but it might be worth seeing if Mono's Ahead-of-Time compiler is able to output to your target platform.
At least then you wouldn't be throwing out (months of?) code.
Since you wrote the application in a garbarge-collected language, the fastest way to port this to an mbed platform should be to port the application to a garbage-collected language which runs on mbed.
I haven't tried it, but eLua is supposed to have a preliminary port which runs on the mbed platform, and Lua is fairly simple to learn.
http://mbed.org/users/jsnyder/notebook/elua-preliminary-port/
If you can get your dad to bring up eLua on the mbed platform, I suspect you could do the conversion fairly easily compared to trying to convert your application to C++.
Port the code manually, and as you do, you will learn C++. :D
I just had a quick phone interview. The interviewer asked me a few questions like:
How does C# work?
What is the CLR and what does it do?
What is C# code converted to?
Other than the CLR question (for which I gave a very vague answer), I didn't know the answers. There were a few others related to .NET that I don't remember, but I didn't know the answers to those either.
I'll admit that my knowledge is more high-level, but I feel like I have a basic grasp of how .NET works. Either way, I got a second interview, but he said I "need to brush up on how .NET works" before my next interview.
So...I'm not exactly sure how to do that...any advice?
I guess I should also mention that I've been out of college for 2 years, and I've been working professionally since then building ASP.NET web applications. Before that, I had no .NET experience.
This article on Wikipedia can give you a good idea about these 3 questions: .NET Framework
I recommend CLR via C#, which is a great book that shows exactly how C# code works "under the hood."
Taking the questions one at a time...
How does C# work?
I would ask the interviewer what exactly he means by this—does he want features of C# such as properties, events, or delegates? Does he want to know how people develop for C#? Does he want a comparison to C/C++? This is a vague question with many possible answers.
What is the CLR and what does it do?
The Common Language Runtime is the virtual machine responsible for execution of .NET byte code (in CIL). It is the .NET equivalent of Java's JVM.
What is C# code converted to?
C# is compiled into the Common Intermediate Language, formerly known as MSIL. It is a type of byte code. To be able to see it and translate it back into .NET languages, you can use a tool like the .NET Reflector to view the CIL code as well as how it would look in C#, VB.NET, etc.
my favourite metaphor/simile is its like having a car, you don't need to know how the engine actually works (water pump, cylinders, spark plugs)... in order to drive a car, but if you did know the extra details it would help your drive even better and be able to actually understand/diagnose some problems you may encounter with the car...
You don't need to know much about the CLR to code an asp.net web site, but if you were to get into the guts of the CLR you might alter the way you code some things to make it even faster to run.
MSDN has reference material on these subjects, e.g.
http://msdn.microsoft.com/en-us/library/c5tkafs1(VS.71).aspx
those should be easy questions if you have realy been working with .net for 2 years,
http://www.microsoft.com/learning/en/us/certification/mcts.aspx
Edit: throwing in my comments bellow, certainly not well known guidelines of any kind... just for discussion
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What are major differences between C# and Java?
I believe it was Eric Sink that said "C# is Java done right". I am pretty familiar with Java, and thought I could try to learn some C#.
As I understand it, these two OO-languages are very similar, so what are the actual differences (if any)?
Having used both extensively for various projects both commercial and hobby, I prefer the expansive open source community around Java, but the tools and (these days) quicker language advancement around C#.
Pro C#
Java got a 5 year head start on C#, during which it tried a bunch of groundbreaking stuff and gave C# some mistakes to learn from and some best practices to adopt. You can viscerally feel the difference that this makes in the class library design, in the way generics are implemented, and just in general polish.
When you add to this the fact that C# introduces a new crop of powerful, carefully chosen, and well-integrated language features every couple of years (LINQ, closures, type inference, the dynamic variable type, generic support for co- and contra-variance, etc.), it really tends to be a joy to use.
I'm actually surprised to find myself saying this, but you can count on Microsoft to bring in some of the best features from languages as diverse as Haskell, JavaScript, and Python directly into C#. All signs point to this trend continuing.
Pro Java
Java, on the other hand, had a 5 year head start (plus even more if you consider how long it has taken Microsoft to begin to come around to doing things more openly) on building a community around it. This gives rise to the fact that NUnit is a port of JUnit, NHibernate is a port of Hibernate, and in general N* is a port of J*.
You usually end up getting very similar sets of incredible tools from each language's respective community, but a lot of stuff existed (and thus matured) in Java before it existed for .Net.
Summary
Both are worth knowing, and there are tons of things to learn from both. They both have solid communities with slightly different takes on the world. I recommend knowing both and watching them closely going in to the future.
Have a look at
Comparison of Java and C Sharp
Java vs C#/.NET
I can't believe this hasn't been mentioned yet...
Java runs on many different devices (Win, *nix, Mac, cellphones, pas, etc. including x86, arm, and some embedded devices whose opcode is bytecode)
C# runs on 1 (well 4 if you count 2k,xp,win7 beta and win7 as 'different') os on 1 architecture.
Someone will mention mono at this point. Mono is a mistake; a lagging-far-behind implementation of .net that MS hasn't sued anyone over, but claims they can. It is not complete, (will never be) and generally lags real .net by at least a major version.
Java runs on relatively more platforms than C# (or .NET)
This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
What are the benefits of using C# vs F# or F# vs c#?
My team is currently using C# .NET to develop enterprise applications for our company. We have a history of Winforms dev, but are now moving over toward SilverLight.
My boss recently saw a video on F# and thought it looked pretty exciting, and he has asked me to check it out. My question is this - what advantages would a functional language (like F#) give over an OO language (like C#) in the realm of enterprise application development?
I really want to see if there are any compelling reasons to even begin contemplating a shift. Some F# and C# comparison code might be nice to see as well.
You can express a lot of concepts much more concisely in a functional language like F#.
Functions are first class objects, and can be applied directly to collections to perform transformations/filtering much more efficiently.
Immutability is encouraged in functional languages, and this makes (for instance) multi-threaded code much more reliable (you know data structures aren't changing under you).
By being able to write multi-threaded code more reliably and more easily it's much easier to take advantage of multiple processors/cores (increasingly important now Moore's law doesn;t apply so much).
Note that you can use your existing C# objects within F#. As such, you may want to write certain parts of your code in F# and other parts in C#. You should be able to mix and match according to your requirements and the suitability of each approach.
I just ordered the Manning 'Real World Functional Programming' which does a fantastic job of explaining all of the nooks and crannies of F#, functional programming, and especially how it compares to C#, and OOP
What I'm coming down to is that functional programming in general increases the 'rigor' of your programs, assuming you conform to the principles of side-effect free functions, and immutability.
Additionally, there seem to be benefits to thinking about code in a declaritive sense, rather than an imperative sense. In OOP I tend to think of the steps it takes to accomplish something, but in FP it seems like you're more concerned with how you want to apply functions to data to obtain results.
firstly you ask "functional language (like F#) give over an OO language (like C#) i" f# is both functional and OO. any thing you would write in c# can be directly translated to f#. F# is a multi paradigm language but the advantage comes from the functional part in my opinion. f# and other functional langauge are a clear winner when it comes to writing multi threaded applications due to the higher possibilities for the compiler to reason about what can safely be run in parallel.
When it comes to web development f# has a very cool tool kit that allows you to write all code (as in server side and client side) in the same language aka f#. the client side will be translated into JavaScript by the web toolkit.