Helpful Information
 
 
Category: .Net Development
But which is better, Java or C#..

Hi all,

I have been reading through this forum and 'C# is Java' came up a lot in one particular thread, so which is better :S. I'm quite up for learning and so.. Java or C# is my question. There both looking pretty interesting.

Have fun everyone,
mark.

I would say, at this point, it depends on your platform. If you're okay with MS and their products (many people have religious-like zeal against anything the corporation is so much as loosely affiliated with) and plan to run on a windows platform, then I'd say you'd be hard pressed to go wrong with C#. It has VB's renouned forms for increadibly easy interface creation, and really looks a lot like java at the code-level. It is a fully-functional and featured language, and once you get the hang of the Visual Studio IDE, you can have very rapid development quite easily.

On the flip side, java is ported everywhere, will run on any system. Characters are always two bytes to insure that it supports any language's character set. It's been around longer and is more mature. As for the internet, JavaScript is an easy pick-up and a must for almost all client-side activity. Applets and Servlets are at your disposal, as well. They support XML web services, too, but it's more costly licensing for a company (I think, really not very sure).

If you get to know one language, you will have absolutely no problem picking up the other. I'd say it really boils down to platform. If you need stuff to run in something other than windows, stick with java. The open C# compiler (mono?) has been mentioned, but if you're developing a significant portion in *nix, forget C# for now. Language maturity can be worked with, but couple that with compiler maturity issues, too, and it's likely to get hairy.

I should also mention that I've only loosely worked with both languages and am as far from an authority as could be. I've done background research on the two in the last six months, but haven't spent more than a few weeks programming in either. I'm a man of C/C++/Perl (especially that last one). :)

Ah, I think i'll stick to Java then. A, because of as you mentioned its ported to ever platform and B, simply because it seems to be alot more desirable on the job front :).

Thanks a lot for your help, easy to understand and got the point accross.

Ta,
Mark.

Well saying that Java advantage is that it runs in all platforms is mostly true but everyone knows that ensuring your Java applications/applets/etc work on each platform is an absolute nightmare.
To me C# is better than Java. Sun was the pioneer of Java and microsoft looked at its records and said, let's keep this, enhance that, and get rid of this and so on, making C# a modern new language. And things you take 2h to do in java takes 15 minutes with C#....
Where's overloading, pointers, preprocessor directives, delegates and deterministic object cleanup in Java?
I'm starting to think that the only real advantage of Java is portability(although it can be a nightmare).. because with C# you can do everything Java does and do it easier and in less time(and maybe better). And I won't even mention JSP6Servlets Vs. ASP.NET because every independent study have said everything about it...

One of the first things I saw in C# that got me interested in it: read/write properties:



Java:

public int getSize() {
return size;
}

public void setSize (int value) {
size = value;
}

C#:

public int Size {
get {return size;
}
set {size = value;
}
}



"relationship between a get and set method is inherent in C# while has to be maintained in Java." It just makes your life easier :)

you can find more examples like that here:
http://genamics.com/developer/csharp_comparative.htm

if you just want the conclusion:

"I hope this has given you a feel for where C# stands in relation to Java and C++. Overall, I believe C# provides greater expressiveness and is more suited to writing performance-critical code than Java, while sharing Java's elegance and simplicity, which makes both much more appealing than C++."

About the job market if you have been paying attention lately you'll notice the fast increase of jobs asking for C#/.NET skills, thus giving you a hint where the future is heading

You make a good point, especially with the development time, although Python still beats both hands down on that front.

Your code snippets were very interesting, I did note that C# seem's to use less code than Java which is always a good thing! Another thing I seem to have picked up is that compiling C# is easier than using the command line to compile Java?

Maybe when Mono is more mature it will make sence to use C# for multi platform development..

I've looked at ASP.Net and JSP before and the one advantage I've seen is that JSP has over ASP is that ASP.NET can only be run on windows servers where JSP runs on multiple server on multiple OS. If only Microsoft would make a cross plaform version of ASP then i'd consider using it, simply because it looks very interesting!

As for jobs I havn't seen any advertised but i'll look into that more closely before I make the final choice over which one to learn next!

Thanks alot for the advise!
Mark.

I’ve done a fair bit of programming in both Java and C# and I’d have to say that the only reason I’d ever consider using Java is for cross platform compatibility. C# is faster to develop in (especially GUI design), has a better IDE then any of the various Java IDEs out there, can perform lower level operations (fixed statements and unsafe code), is a hell of a lot faster and comes with one of the most comprehensive runtimes I’ve ever seen. Quite literally anything you could ever want to do is built into the .NET framework. All this with the beauty of OOD that is Java and you can’t go wrong.

I think C# definitely has a bright future and if you already know Java you should have no problem picking up C# in no time so if cross platform compatibility isn’t an issue I’d say give C# a try.

fetcher: I never understood the PROPERTY thing. You wrote:


C#:

public int Size {
get {return size;
}
set {size = value;
}
}


but where does the variable value come from?

In java, it's clear because it's passed on as a parameter (int value).

I am still confused about the property property of Microsoft languages, and frankly, I really don't like it. But maybe I will like it once I understand it :p

'value' is a keyword in C#, when you set a property in C# 'value' contains the value that was sent to the set procedure, it can be anything (value or referance).

Usually you declare a variable and a property to control read write acces such as:


private int iSize;
public int Size
{
get
{
return iSize;
}
}

This will allow you to only read the iSize variable outside the class.

It's also very useful for when you want something to happen when a variable is assigned to. ie:


private int iID;
public int ID
{
get
{
return iID;
}
set
{
iID = value;
lblCurrentID.Text = iID.ToString();
}
}

The above lets you get or set the current ID, but when you set the ID the label lblCurrentID is updated to display the current ID.

in C# a property may have a get and/or set accessor associated with it. C# automatically provides the variable value which holds the new value to which the property can be set



class Car {

int size;

public Car(int size) {
this.size = size;
}

public int Size {
get { return size; }
set { size = value; }
}
}


to use it...



Car c = new Car(10);

Console.WriteLine("Car size is: " + c.Size); // displays 10

c.Size = 12;

Console.WriteLine("Car size is: " + c.Size); // displays 12



vb.net:
I hope that now the property property of Microsoft languages isn't confusing anymore. It is simpler once you get it :p

Thanks guys. It cleared up a few things for me.

The thing that gets me the most is this:


get
{
return iID;
}


get return iID? Why not just GET ID or RETURN ID? Two consecutive verbs = bad programming syntax! :cool:

vb.net:



get return iID? Why not just GET ID or RETURN ID? Two consecutive verbs = bad programming syntax!


dude..... you must be kidding right? Or you are another one of those people that get blind with their anti-microsoft way of living? :D

inside the get you can have many more stuff than just a return.....so ummm where's the problem? :rolleyes:

people say Java is an "evolution" of C+ and C# is an "evolution" of Java => C# kicks Java a$$!! in an elegant, beautiful, simple, eficient way :p

As a language, I think C# is better than Java, but there's more to programming in something than just the language itself. Platform is a big thing. No, I'm not spouting off about java's super portability, though that is part of it. It's the whole package, the compiler, the runtime, support, following...and there's a lot more subjective points in there. No one language is completely better than another. Cobol is worlds better than Java/C# for what it did.

Or you are another one of those people that get blind with their anti-microsoft way of living?

In fact, you couldn't be more wrong. I am a huge supporter of Microsoft, probably the biggest you will find in these forums.


inside the get you can have many more stuff than just a return

Like what? show some examples, because the books made it look like RETURN was the only thing to do.

Ok i never got this about Java, The idea seemed to be that Java apps run the same on all platforms but.. Java can only run where an VM will run, and then you get problems with VM types, versions, memory etc. surly it isn't any more platform indepent than, well i would say perl but i know sometimes you have to chnage code so it will run on other platform. so that aside, if C# is better than Java language wise, and has a growing following, why use Java?

Mark.

I agree 100% with netytan :D

vb.net:
I'm sorry I thought you were all anti-microsoft.

Anyway about the get accessor, I couldn't find any example so I posted the question in another forum and someone posted this:



Definitely can. For example:




protected override RenderPathID RenderPath

{

get

{

if (IsDesignMode)

{

return RenderPathID.DesignerPath;

}



if(RenderType==RenderType.Default)

{

if (_BrowserLevelChecker.IsUpLevelBrowser(Context))

{

return RenderPathID.UpLevelPath;

}

return RenderPathID.DownLevelPath;

}





if(RenderType==RenderType.Uplevel)

{

return RenderPathID.UpLevelPath;

}

else

{

return RenderPathID.DownLevelPath;

}

}



}



So there you go vb.net ;)

The IDE for C# is light years ahead of Sun's Sun One Studio and Borlands JBuilder. Like it or not, Microsoft can churn out some pretty good stuff. Do you guys remember how we (windows users) had to use MS DOS and notepad to create our Java apps? I do. The development tools for Java are catching up, but they're still 5 years behind. Easily.

Originally posted by netytan
Ah, I think i'll stick to Java then. A, because of as you mentioned its ported to ever platform and B, simply because it seems to be alot more desirable on the job front :).

Thanks a lot for your help, easy to understand and got the point accross.

Ta,
Mark.

Speaking strictly from experience, I've been doing Java for 3 years and recently started doing .NET [have previous exp with ASP]

The problem with Java is the huge dependencies on third party code [usually opensource]. These opensource projects are frequently in beta or some chaotic state that causes constant changes in your own code to keep up. I actually started doing jsp / servlets for this reason [asp was too limiting]. I used J2EE, Jboss, Tomcat, log4j, struts, jetspeed, etc etc etc. It just came to a point where 40 percent of my time was spent keeping up with someone else's bugs.

The cross platform mantra of Java is really not that relevant. Simply put, you will get more done in shorter time in .NET, boiling down to cost savings for your client/company. Anyone who selects a platform just because its "cross platform" is indeed lying to themselves because when you say cross platform, most likely you have already made the decision to deploy on unix and only unix, so whats the point in being "cross platform".

Dont get me wrong, I like java. But I like .NET better :)

Regards,
Mark

Hi Tazzbot,

I gotta agree with you, after looking more into it i desided that C# is the next language i'm gonna learn (over Java). Can't agree with your platform independance stament though, platform independace to me is exactly that, meaning it should work on multiple platforms (windows, unix etc.)

develpment time is very important and C# has that over Java too, Also even though it's been around alot less time is seems to be more mature (if you know what i mean, sounds strange.) but neither can match Python for devlopment time, ease of use and scalability.

Anyway thats for your input,

Have fun,
Mark.

One of the first things I saw in C# that got me interested in it: read/write properties:



Java:

public int getSize() {
return size;
}

public void setSize (int value) {
size = value;
}

C#:

public int Size {
get {return size;
}
set {size = value;
}
}




If you like C# attributes try this:

public int Size{get;set;}

In my opinion C# is much better than Java when designing complex applications.

Java features are poor if compared with C#.

However Java is nice and actually a must for mobile developement.

I've seen the thread is old, however I wanted to post some additional fresh info about C# attributes.

You have a point their! I like all you have said here! That was really good!Your code snippets were very interesting!Thank you for sharing it! I've learned a lot!










privacy (GDPR)