by Jason A. Fletcher, application engineer, Intel Software and Solutions Group, Intel Corp.
This paper discusses the basics in transitioning Java code to C# code by hand. If you're afraid of looking at code, turn back now or abandon all hope. I present four simple examples to help you learn some of the basics of C#. I will not cover attributes or more advanced topics such as interoperability with ASP .NET, ADO .NET, and so forth. I also presume that you are familiar with the Visual Studio .NET environment from Microsoft. If you're not, refer to Appendix A for the concepts of VS that you'll need for these examples.
Before we get into the code samples, let's look briefly at some of the differences between Java and C#.
Surface language differences
Conventions
Java classes use Pascal notation. All other words (keywords, methods, variables, and so forth) use camel notation. Pascal notation uses initial caps for all words, such as ThisIsMyJavaClass. Camel notation is almost the same as Pascal, except the first word uses all lowercase letters, such as thisIsMyJavaMethod . C# is the nearly the inverse. Keywords and variables use camel notation, while all others (classes, exceptions, methods, and so forth) use Pascal notation.
Bracket placement when declaring arrays
In C#, place the brackets after the variable, like this: int[] array. Java can use the C# declaration or it can use int array[].
Properties
Properties in C# make class variable access more transparent to the user, as well as making the access look less like a method call. Depending on whether you want to get or set the value, the C# call will look like variable = Class.Property or Class.Property = value. Java implements the calls this way: variable = Class.getVariable() or Class.setVariable(value). Note that C# properties do not use parentheses.
Migration 1: bubblesort—arrays and indexers
Our first example is the bubblesort sorting algorithm. Before we proceed, create an empty project in VS and add a C# code file. Now, instead of explaining the simple algorithm, let's dive in:
![]()
If you're interested in this topic, these articles may be helpful:
![]() | Java 1.4.1 for Mac OS X from Apple Computer Inc. Java 2 Platform, Standard Editions 1.4.1... |
![]() | Oracle JDeveloper 10g Handbook: Build Java 2 Platform, Enterprise Edition (J2EE) Applications by Dr. Avram Roy-Faderman, Peter Koletzke, and Dr. Paul Dorsey. McGraw... |
![]() | Embedding .NET controls in Java by Heath Stewart, Microsoft MVP, directory of technology, Proplanne... |
![]() | Intel Itanium microarchitecture support for .NET and Java by Matt Gillespie, technical author and editor. Intel Corp. The Int... |
![]() | Enterprise Java performance: best practices by Kingsum Chow, Ricardo Morin, Kumar Shiv, Software and Solutions Gro... |
![]()
Related Jobs:

