How do I move from Java to C#?

I know Java well. Which caveats and resources will help me cross to the other side (C#) as painlessly as possible.

Asked by: Agata449 | Posted: 23-01-2022

Answer 1

Biggest tip: go with the .NET naming conventions from the word go. That way you'll constantly be reminded about which language you're in. (Sounds silly, but it really is helpful.) Embrace the idioms of the language as far as possible.

There are various books specifically for folks in your situation - search for "C# for Java" in Amazon and you'll get plenty of hits. It's worth reading carefully to make sure you don't assume that things will work the same in C# as in Java. (For instance, in C# instance variable initializers are executed before the base class constructor body; in Java they happen after. Subtle things like this can take a while to learn, and are easy to miss if you're skimming.)

If you're going to be using C# 3, I'd get a book which definitely covers that - everything in C# 3 will be new to you. Gratuitous plug: my own book (C# in Depth) covers C# 2 and 3, but assumes you already know C# 1. (In other words, it won't be enough on its own, but you may want it as a "second" book.)

Answered by: Daisy987 | Posted: 24-02-2022

Answer 2

See this great article on C# from a Java Developer's Perspective. It has several insights on the things that can be done in both sides to avoid minimum overhead. Having example in both the language you know and the language you want to learn eases the learning curve quite a bit.

Answered by: Arnold952 | Posted: 24-02-2022

Answer 3

  1. Install Visual Studio 2008 and Resharper with IntelliJ IDEA key bindings. This gives you things like prompting you to include namespaces if you start using them.
  2. Start a new project and start writing Java code, when you run into something that doesn't work properly or it's unable to find the class you're trying to use Google "PrintLn in c#".
  3. Write tests or code snippets for sanity checks, like you may want to check if == works for strings (it does)
  4. realize that c# alias Data Types (int is an alias for System.Int32, string for System.String)
  5. look at other peoples code I recommend JP Boodhoos Google code
  6. Take a job in C#, there's lots of jobs requiring both Java and C# especially in support.
  7. Know your libraries, most Java libraries have been ported and most of the time the name is either like (Hibernate => NHibernate) or (Xstream => Xstream.Net). Not every library has an obvious name so just start looking into random ones you hear about here. ie (Rhino.Mocks,HTMLAgilityPack,MBUnit,Rhino.Commons,Castle Project)
  8. Go to usergroup meetings look for a DNUG (Dot Net User Group) they'll be helpful and you can get some good advice.

Answered by: Lydia555 | Posted: 24-02-2022

Answer 4

There's a cheat-sheet from Microsoft for Java developers using C# :)

Answered by: Emma497 | Posted: 24-02-2022

Answer 5

I know that a good answer has already been accepted. However, I'd like to make an addition...

I find that learning a new language typically involves learning subtle syntactic differences....especially when dealing with the difference between languages in the C/C++/Java/C# family.

In addition to a nice thick reference book I recommend getting a pocket reference like C# 3 Pocket Reference from O'Reilly. It won't help you with the design patterns etc...but will provide a very quick reference about the specific differences of the language you are using.

Here's a quick blurb about this book from that site:

C# 3.0 Pocket Reference includes plenty of illustrations and code examples to explain:

  • Features new to C# 3.0, such as lambda expressions, anonymous types, automatic properties, and more
  • All aspects of C# syntax, predefined types, expressions, and operators
  • Creating classes, structs, delegates and events, enums, generics and constraints, exception handling, and iterators
  • The subtleties of boxing, operating overloading, delegate covariance, extension method resolution, interface reimplementation, nullable types, and operating lifting
  • LINQ, starting with the principles of sequences, deferred execution and standard query operators, and finishing with a complete reference to query syntax-including multiple generators, joining, grouping, and query continuations
  • Consuming, writing, and reflecting on custom attributes

I used this book (well the original) to help me go from being a Java to a C# developer. While I was learning, I kept it by my desk at all times and it really helped.

Answered by: Catherine373 | Posted: 24-02-2022

Answer 6

I made the transition pretty easily by using C# at work, but one of the most important things to do is familiarize yourself with the .NET API and some of the powerful techniques available in C#.

After I learned the .net library I relied on it a lot more than I used to, so learning about the things it can do for you is very helpful. After that, if you work with db code at all, learn LINQ, and also techniques lambas, anonymous types and delegates are also a useful to pick up.

Answered by: Miranda201 | Posted: 24-02-2022

Answer 7

The language syntax is vary similar, so I should only read a small reference of the C# syntax. Like a simple book (for experienced programmers) or maybe wikipedia ( will tell enough.

The biggest difference is the library: Asp.Net websites are totally different from java servlets.

Don't read much, just start programming!

Answered by: Chelsea969 | Posted: 24-02-2022

Answer 8

Here's a link that has syntax comparison between Java and C# (even though it's almost identical, there are a few differences).

Answered by: Melissa742 | Posted: 24-02-2022

Answer 9

Use Sharpen to convert your Java programs to C# and see the differences.

Answered by: John737 | Posted: 24-02-2022

Similar questions

java - Is it possible to move an Icon?

In Java, is it possible to use paintIcon to put an icon into a canvas, and then move that icon around using keyboard events like you would a game character?

How to move a file using Java

Make the move to c++ from java?

Ive been learning java for maybe 5 months, and for that whole time, i mostly tried making games. I made a halfway decent game with java2D, but I want to move on to bigger and better things... 3D. I began to learn LWJGL(which is basicly OpenGL). Before I get too deep into learning java, and going 3d with it, should I move to c++? Are pointers really that essential for large programs? Can I still make anything cross platform...

java - Can't move from one JSP to another

At the beginning I'm at adminPage.jsp : <!DOCTYPE html> <html> <head><title>System Administrator Page</title> <link rel="stylesheet" href="./css/styles.css" type="text/css"/> </head> <body> <h1>Hello ${name.firstName} ${name.lastName} , You've logged in successfully!</h1> <h1> Please choose one of the following opt...

Java - How to move a file into a zip file?

That's it. I have a text file, and I need to move it to a (existing) Zip File in a given directory. File file = new File("C:\\afolder\\test.txt"); File dir = new File(directoryToGo+""); boolean success = file.renameTo(new File(dir, file.getName())); But it does not work. Is there a way to move a file into a existing Zip File? Thank you.

java - TAB to move through the form

I want to move with TAB key through the form. By default TAB jumping through first line first and then through second and so on. I want it to jump through columns how should I do this? I was trying with keyPressed event, but didn't worked. This is code of one jTextField which request focus of second jTextField: if(evt.getKeyCode() == KeyEvent.VK_TAB){ tfPri...

How to move a ball in Java

import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JPanel; public class Game extends JFrame{ int x1=(int)( Math.random()*10),x2=(int)(Math.random()*45),x3=(int)(Math.random()*35); int y1=(int)( Math.random()*10),y2=(int)(Math.random()*45),y3=(int)(Math.random()*35)...

java - move a ball one after another

I am writing a code of game bean machine(Galton box), its mechanism that one ball fall and move randomly until it get to one of the slots (randomly) and then another ball comes doing the same thing and so on, the problem is that all balls fall at the same time which something I do not want, I want each ball to fall when the current one finishes its travel..can anyone helps me ! Thanks.. here is the code: ...

java - Move file when it is available

I am using this code to move files in row in my C# application. public static bool IsFileReady(String sFilename) { try { using (FileStream inputStream = File.Open(sFilename, FileMode.Open, FileAccess.Read, FileShare.None)) { if (inputStream.Length > 0) { return true; } else { return false; ...

how to move to the page i want in pdf file in java

i am working on generating a pdf file of multiple pages but when i am adding my information to the pdf file this information is added only in the last page and the previous pages are empty, this is a part of my code and i need to start from the first page and then move to the second according to a condition, where in every page i want only 20 rows of data. is there any solution?? try { Document ...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)