- Back to Home »
- C# Language
Posted by : Unknown
Saturday, June 29, 2013
Till now it is the well known
fact that from last 5 years the only
language which ruled the complete world is java, a programming language that is
launched by the Sun micro systems. Java
has all the features to provide varied services to its customers. Especially with the web services it become
most popular.
But with the release of new language called C# from Micro Soft, has shacked the
roots of its Royalty. Now I think, everyone will agree the fact that release of
C# effected the market of Java.
So today I would like to discuss about the
running cold war between C# and Java.
Areas which I am going to cover are :
Ø Brief introduction to c#.
Ø .Net platform that is supported by c#.
Ø Similarities and dis-similarities between c# and Java.
Ø Impact of C# on Java.
Ø C# improvements over Java.
Ø Finally with an example, I conclude topic by presenting my view.
INTRODUCTION TO C#:
Microsoft describes c# as a
simple, modern, object-oriented and type safe programming language derived from
c and c++. As some experts says c# as
the “technology of the year”.
C# is a suitable automatic garbage
collection, automatic variable initialization and type-safing the variables. C#
will give the basic freedom of coding at the same time bestows you with all the
advantages of Java. So we can develop
applications with the power of c, ease of VB and the simplicity of Java.
Using simple c# language constructs, the
components can be converted into web servers. MS will be offering c# with
Visual Studio 7 and though c# does not have class library of its own, it has
access to libraries used by VB and VC++.
C# can be called as the superset of all the previous languages, because
it incorporates more features than the older languages.
MICROSOFT .NET :
If I talk about c# without telling .Net
platform it is just going to be an incomplete speech. So, I briefly discuss
about .Net too.
The term MS.NET is similar to ‘Windows DNA’
in that it refers to many things : a business strategy, development model,
market pitch, development platform, and language runtime.
Programs written in c# are compiled into an
intermediate language called
MSIL, the equivalent of Java byte
code. Any language that can be compiled
to MSIL can take advantages of the CLR features such as garbage collection,
reflection, meta-data, versioning, events and security etc.
It is interesting that micro soft is
pushing cross-language development while Sun/Java pushes cross-platform
development.
C# SIMILARITIES TO JAVA:
ü Resemblance of java with c# goes beyond syntax, keywords and
delimiters.
ü It includes many features in common are as follows:
ü Automatic garbage collection.
ü Reflection for type information discovery.
ü Source code is compiled to an intermediate byte code.
ü JIT compilation compiles byte code into native code.
ü Every thing must be in a class – no global functions or data.
ü No multiple inheritance, although you can implement multiple
interfaces.
ü All classes derive from object.
ü Security for restricting access to resources.
ü Exceptions for error handling.
ü Code comments as documentation.
ü Array are bounds checked.
ü GUI, networking and threading support.
ü No un-initialized variables.
ü No pointers.
ü No header files.
Most of keywords in java have their c#
counterpart. Some key words are
identical. For example : new, bool, this ,break, static class ,throw and null.
(as they are derived from c++).
C# specifies access modifiers inline as
part of the member definition just like java.
DIFFERENCES BETWEEN C# AND JAVA :
Some keywords that are in java has
different name in c# like
Super - base, import – using, package – namespace ,synchronized
– lock, final – sealed respectively.
The following table shows differences in
java and c#.
Name Java C#
- Inheritance class Foo extends Bar class Foo:Bar,FooBar{}
implements FooBar{}
- Referring to the Super.hashcode(); base.GetHashCode();
Base class
- Importing types import java.util.*; using sytem.Net;
- Namespaces package mystuff; namespace mystuff;
class Myclass{} class Myclass{}
- Prevent inheritance final class foo{} sealed class foo{}
- Constants final static int max=5; const int max=5;
- Code comments /* comment */ /// comment
- Synchronization synchornized(this){} lock(this){}
- Deprecated classes @deprecated don’t use! [obsolete(“don’t use”);]
or
methods
No throws class in c#, all exceptions
are unchecked.
Package access is default for Java while
private is the default for c#.
Another good example of cosmetic
differences is the system. Object class
in c#, which has the exact same methods as the java.lang.object class in java.
IMPACT OF C# ON
JAVA:
You believe the fact that c# influenced the
java’s market. Nearly 40% has been reduced after release of c#.
C# IMPROVEMENTS OVER JAVA:
C# has a simplified syntax for things such
as iterations, events and treating primitive types like objects which reduces
the amount of code you need to write.
Version problems can be solved.
Assertion are useful for sanity checking
and enforcing the precondition, post conditions and invariants of design by
contract. Value types in c# (int, long,
char) can be treated just like reference types without requiring special
wrapper classes in java.
Provide implementations for runtime type
identification , serialization etc.
Reflection provides the ability to obtain
type information dynamically and makes it possible for the runtime system to
automatically inform.
EXAMPLES :
Example
: Hello World in Java
class helloworld
{ public static void
main(String[] args)
{ System.out.println(“Hello
World”);
}
}
Hello World in C#
class helloworld
{ public static void Main(string []s)
{ System.Console.WriteLine(“Hello
World”);
}
}
CONCLUSION:
C# or Java?
One big advantage with MS’s products is, when they come up a new
product, they bundle it with nice development and debugging tools. Which lacks in Sun Micro Systems products where
developing and debugging is difficult.
Now c# along with .Net has one advantage – the power of c,
which is probably missing in java. C# will give you that freedom at the same
time bestows you with all the advantages of java. All programming languages are compiled to an
intermediate languages in the MS.NET architecture it is possible to inherit a
c++ class in small talk class and instantiate that in c# class which is never
possible in java.
One big issue is java has been already with
us for the past 5 years and has a long
base of programmers but Ms now has a tough time in training .Net or c#
developers.
One problem with MS software is the
security many bugs and memory
allocations errors are common in MS’s software and active X components is a
serious security violation, which are clouded over the internet. Javas sandbox
is still a winner and strongly controls behavior of the codes. But still people
feel that java programmers are slow. Let us wait and see whether the c# make
such a faster impact like what java has made.