Java vs C/C++

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Java vs C/C++

Postby P4r4digm » Thu Oct 29, 2009 3:24 pm UTC

So i learned C and C++ long before I knew anything about Java...and I've never been put on a strictly java-developed project, but from what I can tell dabbling around in the language here and there, the two are identical as far as syntax and many constructs go.

Java doesnt seem to have pointers and is interpreted (but you can compile it?), and seems to rely on a large collection of libraries and jars and shit I know nothing of whereas with C you can pretty much start from scratch and write everything yourself. But I really don't know enough about java to make a ruling on this.

Anyways I'm just interested in the advantages and disadvantages of one over the other...hopefully it'll help me be a bit more knowledgeable with people who say C sux bawls
Image
User avatar
P4r4digm
 
Posts: 13
Joined: Fri Apr 03, 2009 6:52 pm UTC

Re: Java vs C/C++

Postby qbg » Thu Oct 29, 2009 5:55 pm UTC

P4r4digm wrote:Java doesnt seem to have pointers and is interpreted (but you can compile it?), and seems to rely on a large collection of libraries and jars and shit I know nothing of whereas with C you can pretty much start from scratch and write everything yourself. But I really don't know enough about java to make a ruling on this.

Correct, Java doesn't have pointers. Every variables of a non-primitive type are references.

Java is typically compiled to bytecode, which is then JITed in a good implementation of the JVM, so Java isn't slow.
Anyways I'm just interested in the advantages and disadvantages of one over the other...hopefully it'll help me be a bit more knowledgeable with people who say C sux bawls

C is a beautiful language that is essentially portable assembler.
C++ is the result of making a squid by stapling extra legs onto a dog.
Java has a ton of libraries, and can be quite annoying, but at least it has GC.
qbg
 
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Java vs C/C++

Postby LikwidCirkel » Thu Oct 29, 2009 7:26 pm UTC

There are quite a few differences, but to me two are most noteworthy.

1)
Java is always a managed environment, so you're not likely to end up with errors from bad cleanup.
C/C++ is unmanaged, but can be used with managed libraries and extensions and an os-specific run-time. A managed environment creates overhead in either case, but with Java, you don't have the choice.

2)
Method calls use run-time binding by default with Java. I'm no expert, and I'm not sure if or how static-binding can be accomplished. This makes multiple-inheritance completely impossible. C++ by contrast uses static-binding by default. Declaring a function "virtual" makes it use run-time binding. Understanding the difference is very important because if effects which method will be called within a class hierarchy. This needs to be fully understood if you really want to know what you're doing.

For example:
Code: Select all
// java
class a {
  public void foo() { ... }
}

class b extends a {
  public void foo() { ... }
}

class SomeClass {
  public static void main(String args[]) {
    a my_a = new b();
    my_a.foo(); // executes foo() defined in class b
  }
}

// c++
class a {
  void foo();
};

class b : a {
  void foo();
};

int main() {
  a *my_a = new b();
  my_a->foo(); // executes foo() defined in class a
}


Other differences are, of course, that you can't do arbitrary memory accesses with Java - but the idea is to _prevent_ people from doing that. It's usually only a restriction for very low level stuff like operating system, drivers, low-level services and the like. Java also compiles to it's own bytecode and requires a VM to run, but we all should know this.
LikwidCirkel
 
Posts: 169
Joined: Thu Nov 08, 2007 8:56 pm UTC
Location: on this forum (duh)

Re: Java vs C/C++

Postby P4r4digm » Thu Oct 29, 2009 8:05 pm UTC

I've always loved C's philosophy of "we'll let you do it but its your problem if you fuck up" because it gives you full control to experiment on a very low-level basis with computers without needing to know assembly. Part of what makes coding fun to me is finding new ways to bend the language to write memory managers, mess with memory directly, and crazy bitshifting etc...it's the language that makes you say "thats the smartest 3 lines of code Ive ever written"
And then of course C++ introduced templates which brilliant minds such as andrei alexandrescu took and blew our understanding of the restrictions of the language all over the walls.

So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...anyone know a type of problem that java would be able to solve easier/more effectively than C?
Image
User avatar
P4r4digm
 
Posts: 13
Joined: Fri Apr 03, 2009 6:52 pm UTC

Re: Java vs C/C++

Postby You, sir, name? » Thu Oct 29, 2009 8:50 pm UTC

P4r4digm wrote:So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...

Basically: This --^

P4r4digm wrote:anyone know a type of problem that java would be able to solve easier/more effectively than C?


Portability problems. Java is write once, run everywhere. C is write once, compile everywhere if you've managed to write portable code. Otherwise it's write once, spend a week fixing portability issues everywhere else.

Java is also awesome for prototyping (given a decent IDE). If Java code compiles, there isn't a very big probability that it won't run as expected (assuming you've got some degree of experience), and if some problem arises, it's much easier to debug than C code because of reflection and things of that nature. It's much harder for a C compiler to catch issues at compile-time because of it's liberal attitude towards casting, and if a problem arises at runtime, debugging is a lot harder.

It's a lot easier to write bad C code than it is to write bad Java code, but really good C code will usually top really good Java code.
Blag.
Ternary computer emulator. Latest version is 0.5 [Nov 29 2008].

Good morning, that's a nice tnetennba.
User avatar
You, sir, name?
 
Posts: 6126
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: Java vs C/C++

Postby Berengal » Thu Oct 29, 2009 8:58 pm UTC

Also, there's much more bad Java code than there's bad C code. Bad C programs don't last very long in the usual case...
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Java vs C/C++

Postby OOPMan » Fri Oct 30, 2009 7:59 am UTC

Java is not just a language, Java is also a VM.

As a language, Java is shite.

As a platform for other languages, it's great.
Image

Image
User avatar
OOPMan
 
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Re: Java vs C/C++

Postby 0xBADFEED » Fri Oct 30, 2009 2:36 pm UTC

I'm not a big fan of Java as a language.

One thing that is really nice about Java though is that I can sort of turn my brain off and still write half-decent Java. You can write Java on auto-pilot when you're burned-out or tired and it will still be OK. You can't do this with C, and definitely not with C++.
0xBADFEED
 
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Java vs C/C++

Postby Xanthir » Fri Oct 30, 2009 2:56 pm UTC

You, sir, name? wrote:
P4r4digm wrote:So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...

Basically: This --^

This is sawdust and lies. There are a ton of bad languages which are objectively worse than others (unless you're being silly with "suited for certain tasks and platforms").

One problem, though, is that most people *see* that there are bad languages and ignore them. They're usually talking about the languages that everyone else uses. However, since they don't *use* those other languages, they can't really understand what makes them good, and so can't properly evaluate how much better they are. A programmer who masters Java has a set of "looks pretty equal" languages that is a subset of a BASIC programmer's.

If you find that most languages seem to suck, you're either elitist or just happened to find one near the top of the pile, where the deficiencies of the other languages are more visible.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 3988
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Java vs C/C++

Postby gametaku » Fri Oct 30, 2009 4:20 pm UTC

You, sir, name? wrote:
P4r4digm wrote:So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...

Basically: This --^

P4r4digm wrote:anyone know a type of problem that java would be able to solve easier/more effectively than C?


Portability problems. Java is write once, run everywhere. C is write once, compile everywhere if you've managed to write portable code. Otherwise it's write once, spend a week fixing portability issues everywhere else.



No, its write once, run everywhere people have the java platform installed. (admittedly it's fairly universal but it's not run everywhere)
gametaku
 
Posts: 146
Joined: Tue Dec 30, 2008 2:21 am UTC

Re: Java vs C/C++

Postby MoghLiechty2 » Sun Nov 01, 2009 5:14 am UTC

Yeah, what everyone else said. They're different in very specific ways which result in very specific different advantages which allow them to apply to very specific different applications. But that won't stop me from... *ahem*

C Plus Plus!
C Plus Plus!


I avoid Java like the plague. Anything I want to do with managed code I can do easier and better with C#, but this won't be the case with everybody of course.
qbg wrote:C is a beautiful language that is essentially portable assembler.
C++ is the result of making a squid by stapling extra legs onto a dog.

I couldn't disagree more. And it's not because I suck at disagreeing. C is a wannabe squid, except it has no legs.
MoghLiechty2
 
Posts: 629
Joined: Sat Jan 24, 2009 8:55 pm UTC
Location: iSemester % 2 ? Seattle : Indiana

Re: Java vs C/C++

Postby You, sir, name? » Sun Nov 01, 2009 12:55 pm UTC

gametaku wrote:
Spoiler:
You, sir, name? wrote:
P4r4digm wrote:So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...

Basically: This --^

P4r4digm wrote:anyone know a type of problem that java would be able to solve easier/more effectively than C?


Portability problems. Java is write once, run everywhere. C is write once, compile everywhere if you've managed to write portable code. Otherwise it's write once, spend a week fixing portability issues everywhere else.



No, its write once, run everywhere people have the java platform installed. (admittedly it's fairly universal but it's not run everywhere)


The point is that you don't actually have to change the code to run Java programs somewhere else.
Blag.
Ternary computer emulator. Latest version is 0.5 [Nov 29 2008].

Good morning, that's a nice tnetennba.
User avatar
You, sir, name?
 
Posts: 6126
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City

Re: Java vs C/C++

Postby OOPMan » Mon Nov 02, 2009 6:59 am UTC

MoghLiechty2 wrote:Yeah, what everyone else said. They're different in very specific ways which result in very specific different advantages which allow them to apply to very specific different applications. But that won't stop me from... *ahem*

C Plus Plus!
C Plus Plus!


I avoid Java like the plague. Anything I want to do with managed code I can do easier and better with C#, but this won't be the case with everybody of course.
qbg wrote:C is a beautiful language that is essentially portable assembler.
C++ is the result of making a squid by stapling extra legs onto a dog.

I couldn't disagree more. And it's not because I suck at disagreeing. C is a wannabe squid, except it has no legs.


Yeah, but you're an M$ Slave, so obviously you'd recommend C# over Java :-)
Image

Image
User avatar
OOPMan
 
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Re: Java vs C/C++

Postby MoghLiechty2 » Mon Nov 02, 2009 8:12 am UTC

OOPMan wrote:Yeah, but you're an M$ Slave, so obviously you'd recommend C# over Java :-)

Ah but slave would imply that I work without compensation, where in fact they pay me quite well!

So it's more like I'm being bribed. :wink:
MoghLiechty2
 
Posts: 629
Joined: Sat Jan 24, 2009 8:55 pm UTC
Location: iSemester % 2 ? Seattle : Indiana

Re: Java vs C/C++

Postby mcv » Tue Nov 03, 2009 9:58 am UTC

Feels like a blast from the past, this discussion. I didn't think there'd still be people unfamiliar with Java, considering how it's the most popular language of the past decade.

Yes, Java looks a lot like C++. That's because Java was designed to lure C++ programmers. Java is basically C++ done right: you don't have to manage your own memory anymore, you've got proper exceptions, and it's generally much less prone to bugs. And in the late '90s, a lot of C++ programmers were tired of the aggravated brain damage that C++ was, which is how Java got it's jump start. C++ has been basically obsolete for application development ever since (especially now that Java performs at least as good as C++).

C is different. Like qbg said: it's basically portable assembly, and still a very good choice for anything that should really be done in assembly (low level system stuff, VMs, drivers, high performance graphics libraries, etc).

Java has a couple of problems, though: because it's basically a more secure C++ clone, its syntax is just as verbose. Even more so, in fact, because exceptions need to be handled explicitly. Reading a file and writing it line by line to stdout takes a dozen lines of code (if not more), when it should really take only 2 lines of code in any well-designed application programming language.

Also, in Java, it's really hard to completely fuck up your code. It's the perfect language for mediocre programmers, and you know there are a lot of those. This is the other reason for Java's popularity: it's easy to find programmers who can produce working code. Any idiot can write Java, and a lot of idiots do. There's a lot of mediocre Java code out there. There's not a lot of really bad Java code out there, simply because Java doesn't allow you to do any of the really fucked up things that you can do in C and C++.

And then there's the overabundance in libraries and frameworks. Java makes it easy to share code, so everybody does. Which is basically a good thing, but now in order to program in Java, you need to know how to work with the Java Foundation Classes, half a dozen different web frameworks (and then you only know the major ones), several build frameworks (every one more powerful and complex than the last) and lots of cool new technologies that you absolutely have to plug into your application.

But Java is extremely popular. It's really easy to make and maintain extremely large enterprise applications, which is why almost every enterprise project is done in Java. And I fear that makes Java the COBOL of the future.

So should you learn Java now? It's a safe bet if you want to learn a language to get a job. But I think you should have known Java for the better part of a decade already, and now is the time to look for its successor. Java is too big and cumbersome, inherits too many bad ideas from C++, and fixed C++'s problems by becoming even bigger and verbose. Many Java programmers (the ones that like to stay ahead of the curve, and certainly ahead of the masses of mediocre programmers) are looking at more modern, concise, dynamic languages.

Ruby is a big hit, for example (really nice and powerful language, but very slow in execution, and lacks the JVM's security).
Python is pretty good. I don't have any experience with it (yet), but it's faster than Ruby, and it's very popular in game development.
However, the real strength of Java is not in the language, but in the JVM. It's the best application platform a programmer could hope for, especially in this day of multi-core processors, server clusters and virtualisation. And there are some languages that take advantage of that: Groovy, a dynamic language with many Ruby-like features, but it also accepts almost all Java code (except anonymous inner classes, which are a stupid hack anyway because Java can't handle closures), and Scala, which is a static, highly functional language which also steals a lot of good ideas from Ruby, but apparently executes even faster than Java in some circumstances.

After having learned Ruby, I was actually planning to learn Scala, but for a new job I'm currently learning Groovy instead. I'd say Scala is the language of tomorrow, whereas Groovy is the language of today. (And Java is the language of yesterday, and C++ the language a decade ago.)
mcv
 
Posts: 44
Joined: Tue Nov 03, 2009 8:52 am UTC

Re: Java vs C/C++

Postby OOPMan » Tue Nov 03, 2009 2:40 pm UTC

Nice post mcv, except you left out JRuby :-)
Image

Image
User avatar
OOPMan
 
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Re: Java vs C/C++

Postby mcv » Tue Nov 03, 2009 3:33 pm UTC

OOPMan wrote:Nice post mcv, except you left out JRuby :-)

I did. Because I know embarrassingly little about it. I know it's one of the fastest Ruby implementations around, but that's about it. No idea to what extend it interacts with Java or takes advantage of special JVM features, or how compatible it is with existing Ruby libraries. On the one hand, the pretty-language stuff from Ruby combined with all the advantages of the JVM would be absolutely awesome, but somehow it also feels like it wouldn't be quite Ruby anymore.
mcv
 
Posts: 44
Joined: Tue Nov 03, 2009 8:52 am UTC

Re: Java vs C/C++

Postby Berengal » Tue Nov 03, 2009 6:19 pm UTC

Indeed, nice post. I share many of the sentiments, especially the part about needing new languages and the JVM being the best thing about Java.

Some comments:
mcv wrote:Feels like a blast from the past, this discussion. I didn't think there'd still be people unfamiliar with Java, considering how it's the most popular language of the past decade.

You sure about that? C is still pretty popular. langpop shows java as being the currently most-popular language, but C is right behind it, and beats it in several areas. I wouldn't be surprised if Java only was the most popular language for a couple of years.

mcv wrote:(especially now that Java performs at least as good as C++)

That's still a stretch. C++ usually beats Java in various benchmarks, and it (or C) is still the go-to language for high-performance applications like games.

mcv wrote:Also, in Java, it's really hard to completely fuck up your code.

This part I disagree with. It's just as easy to fuck up Java as it is to fuck up C++. You'll get a different class of errors, and the JVM makes debugging that much easier, but you'll still get the same amount of bugs, and they may be just as time-consuming and horrible as the C++ bugs. They're a different class of bugs (no more segfaults (well, the JVM can cause a segfault by not checking for null before dereferencing, but in these cases it intercepts the SIGSEGV and recovers)), but giving bad programmers the ability to make broken code run without actually fixing it makes for at least as subtle bugs. This assumes a bad programmer.

I could agree with it normalizing programmers though: There's less of the really bad ones, but also less of the really good ones. Since programmer productivity is on an exponential scale (or at least a polynomial one) I don't think this is a great tradeoff.

mcv wrote:And I fear that makes Java the COBOL of the future.

I fear I've started to share as well. Java was good at first, but it's really starting to feel tepid now, and Java 7 coming out soon doesn't do much to stir things up again.

mcv wrote:I'd say Scala is the language of tomorrow, whereas Groovy is the language of today.

Groovy does look interesting, and indeed Scala does even more so. I'm investing lots of resources pushing Haskell at work, hoping we'll at least switch to Scala in the near future.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Java vs C/C++

Postby mcv » Tue Nov 03, 2009 9:17 pm UTC

Berengal wrote:
mcv wrote:Feels like a blast from the past, this discussion. I didn't think there'd still be people unfamiliar with Java, considering how it's the most popular language of the past decade.

You sure about that? C is still pretty popular. langpop shows java as being the currently most-popular language, but C is right behind it, and beats it in several areas. I wouldn't be surprised if Java only was the most popular language for a couple of years.

I'm sure it depends a lot on how you measure popularity, but Java is usually near the top. It certainly dominates enterprisey web stuff, and that's a pretty big market, both in money and in number of programmers. I think it's past its peak, though. I hope it's past its peak (as a language -- the JVM is cool).

Berengal wrote:
mcv wrote:(especially now that Java performs at least as good as C++)

That's still a stretch. C++ usually beats Java in various benchmarks, and it (or C) is still the go-to language for high-performance applications like games.

Yet there's a lot of games nowadays that do a lot in Python. Java's game support isn't terribly great, I have to admit. But Java's support of clustering and multithreading is excellent, and easier to work with than those of C and C++, which helps quite a lot in high performance environments like big servers.

For low-level high-performance stuff, C is definitely the language to go to (unless you want to do it in assembly), but for big applications, especially server-side stuff, Java doesn't lag much behind, if at all. A couple of years ago, I read it was at most 10% slower, and JVM 7 is even faster, I'm told.

Berengal wrote:
mcv wrote:Also, in Java, it's really hard to completely fuck up your code.

This part I disagree with. It's just as easy to fuck up Java as it is to fuck up C++. You'll get a different class of errors, and the JVM makes debugging that much easier, but you'll still get the same amount of bugs, and they may be just as time-consuming and horrible as the C++ bugs. They're a different class of bugs (no more segfaults (well, the JVM can cause a segfault by not checking for null before dereferencing, but in these cases it intercepts the SIGSEGV and recovers)), but giving bad programmers the ability to make broken code run without actually fixing it makes for at least as subtle bugs. This assumes a bad programmer.

The bugs are less fatal. How many security holes are caused by buffer overflows and stuff like that? Can't do that in Java. In C/C++, you can access memory you're not supposed to, and you can do it in a way that's not immediately obvious or easy to fix. Java protects you against that.

Berengal wrote:I could agree with it normalizing programmers though: There's less of the really bad ones, but also less of the really good ones. Since programmer productivity is on an exponential scale (or at least a polynomial one) I don't think this is a great tradeoff.

Depends. In big organisations, the people in charge aren't always capable of distinguishing between good and bad programmers. And guess where Java is most popular?

There's also plenty of really good people working with Java, though. They're the ones desperately trying to make everything pretty and fun again.

Berengal wrote:
mcv wrote:I'd say Scala is the language of tomorrow, whereas Groovy is the language of today.

Groovy does look interesting, and indeed Scala does even more so. I'm investing lots of resources pushing Haskell at work, hoping we'll at least switch to Scala in the near future.

Haskell is also a language I need to look at some day. A good friend is a big fan of Haskell, and I respect his opinion quite a bit.
Last edited by mcv on Wed Nov 04, 2009 8:31 pm UTC, edited 1 time in total.
mcv
 
Posts: 44
Joined: Tue Nov 03, 2009 8:52 am UTC

Re: Java vs C/C++

Postby headprogrammingczar » Tue Nov 03, 2009 10:15 pm UTC

mcv wrote:Java's game support isn't terribly great, I have to admit.

Not entirely true. Its verbosity makes game development a bitch, but it has several powerful OpenGL libraries, plus it has ports of Bullet and ODE for physics. Right now, the engine I linked to is more featureful than Source. The rest of your post is spot on though.

Edit: incidentally, it seems the Java 7 spec dictates that bytecode support dynamic typing, which will bring in even more powerful JVM-enabled languages.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you
User avatar
headprogrammingczar
 
Posts: 2953
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Java vs C/C++

Postby 0xBADFEED » Wed Nov 04, 2009 12:35 am UTC

mcv wrote:C++ has been basically obsolete for application development ever since...

Not even close to true.
C++ continues to be an extremely popular choice for application development. Maybe not for your run-of-the-mill CRUD or web applications, but it's still very popular. Primarily because it has a lot of the highest quality and most mature libraries available across any language.
C++ will continue to be viable for a long, long, long time. I don't know if that's a good or bad thing, but that's how it is.
0xBADFEED
 
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Java vs C/C++

Postby MoghLiechty2 » Wed Nov 04, 2009 12:46 am UTC

Yeah C++ is still the only thing that the core components of every single Xbox 360, PS3, and major PC video game is written in. With the new C++ standard and constant improvements to the standard library, there's no end in sight to C++'s usage in this industry.
MoghLiechty2
 
Posts: 629
Joined: Sat Jan 24, 2009 8:55 pm UTC
Location: iSemester % 2 ? Seattle : Indiana

Re: Java vs C/C++

Postby OOPMan » Wed Nov 04, 2009 7:31 am UTC

Yeah, but that might be more because there isn't really any competition for C++ as a games lang that anything else. C, Objective-C and DMD are both somewhat viable alternatives but get beat out by C++ due to library support.

Still, I'm not going to complain while buffer overflows and the like allow me to run homebrew on my Wii and DS ;-)
Image

Image
User avatar
OOPMan
 
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Re: Java vs C/C++

Postby gametaku » Thu Nov 05, 2009 3:30 am UTC

You, sir, name? wrote:
gametaku wrote:
Spoiler:
You, sir, name? wrote:
P4r4digm wrote:So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...

Basically: This --^

P4r4digm wrote:anyone know a type of problem that java would be able to solve easier/more effectively than C?


Portability problems. Java is write once, run everywhere. C is write once, compile everywhere if you've managed to write portable code. Otherwise it's write once, spend a week fixing portability issues everywhere else.



No, its write once, run everywhere people have the java platform installed. (admittedly it's fairly universal but it's not run everywhere)


The point is that you don't actually have to change the code to run Java programs somewhere else.


Accept when you can't. (for example using JNI, various platform specific java libraries, anywhere the JVM is implemented differently).

Anyways as long as one is targeting the same platform they don't have to change and recompile code written in C or C++. The difference is that C or C++ can be used among various platforms: of X86 Windows, a cell phone, the the java platform, etc. The java language 99.9%* of the time is used on one platform: the java platform.





Berengal wrote:Some comments:
mcv wrote:Feels like a blast from the past, this discussion. I didn't think there'd still be people unfamiliar with Java, considering how it's the most popular language of the past decade.

You sure about that? C is still pretty popular. langpop shows java as being the currently most-popular language, but C is right behind it, and beats it in several areas. I wouldn't be surprised if Java only was the most popular language for a couple of years.

mcv wrote:(especially now that Java performs at least as good as C++)

That's still a stretch. C++ usually beats Java in various benchmarks, and it (or C) is still the go-to language for high-performance applications like games.


The site seems fairly poor in terms of determining popularity.
1. I did a quick yahoo search for C, the numbers were similar but the 4th result was the Wikipedia article on C++, I've found some references to C# no doubt that there are plenty more like that.
2. There is no direct information regarding usage in the professional world. (and the indirect isn't that good)
3. Open source projects, overwhelmingly target Linux either by itself or as part of a collection of targets. Given the the nature of group linux think** (TM) no doubt many projects were written in C/C++ because Java programmers are "mediocre".


mcv wrote:Also, in Java, it's really hard to completely fuck up your code.

This part I disagree with. It's just as easy to fuck up Java as it is to fuck up C++. You'll get a different class of errors, and the JVM makes debugging that much easier, but you'll still get the same amount of bugs, and they may be just as time-consuming and horrible as the C++ bugs. They're a different class of bugs (no more segfaults (well, the JVM can cause a segfault by not checking for null before dereferencing, but in these cases it intercepts the SIGSEGV and recovers)), but giving bad programmers the ability to make broken code run without actually fixing it makes for at least as subtle bugs. This assumes a bad programmer.

I could agree with it normalizing programmers though: There's less of the really bad ones, but also less of the really good ones. Since programmer productivity is on an exponential scale (or at least a polynomial one) I don't think this is a great tradeoff.

There are a lot more programmers now which means that there are a lot more mediocre programmers using all types of languages because there are a lot of mediocre people.

*not scientifically accurate.
**a smug superior attitude that believes computers should be hard to use, and write Microsoft as M$ (thankful they are not as prevalent as they use to be.)
gametaku
 
Posts: 146
Joined: Tue Dec 30, 2008 2:21 am UTC

Re: Java vs C/C++

Postby MoghLiechty2 » Thu Nov 05, 2009 3:41 am UTC

gametaku wrote:group linux think**
...
**a smug superior attitude that believes computers should be hard to use, and write Microsoft as M$ (thankful they are not as prevalent as they use to be.)

The people 'round here who write Microsoft (may she live forever) as M$ seem to be particularly intelligent though, if misguided in their judgments of Microsoft as a corporation.
MoghLiechty2
 
Posts: 629
Joined: Sat Jan 24, 2009 8:55 pm UTC
Location: iSemester % 2 ? Seattle : Indiana

Re: Java vs C/C++

Postby mcv » Thu Nov 05, 2009 7:28 am UTC

gametaku wrote:Anyways as long as one is targeting the same platform they don't have to change and recompile code written in C or C++. The difference is that C or C++ can be used among various platforms: of X86 Windows, a cell phone, the the java platform, etc. The java language 99.9%* of the time is used on one platform: the java platform.

But it's a platform that's available just about anywhere. Come on, you're not seriously going to suggest that C is more portable than Java, are you? It really, really, very much isn't.


Berengal wrote:3. Open source projects, overwhelmingly target Linux either by itself or as part of a collection of targets. Given the the nature of group linux think** (TM) no doubt many projects were written in C/C++ because Java programmers are "mediocre".

Take a look at the Apache projects. There's a ton of Open Source stuff in Java.
mcv
 
Posts: 44
Joined: Tue Nov 03, 2009 8:52 am UTC

Re: Java vs C/C++

Postby 0xBADFEED » Thu Nov 05, 2009 3:16 pm UTC

gametaku wrote:...
3. Open source projects, overwhelmingly target Linux either by itself or as part of a collection of targets. Given the the nature of group linux think** (TM) no doubt many projects were written in C/C++ because Java programmers are "mediocre".

It has little to do with any kind of "Java programmers are mediocre" mindset. It's, for the most part, a technical decision. It's about being able to take advantage of OS services. If you're writing an application that targets a specific OS, it's because you want to use some OS-specific services. If you're using Java and you want access to OS-specific services you have two choices:

1) Hope there's a Java binding available for the service(s) you want. (may or may not be likely)
2) Write the binding yourself with JNI or SWIG or whatever. (which is a pain)

Writing a correct, robust binding for the required service(s) functionality could be a larger project in itself than the original application.

Or... you could save yourself a whole mess of trouble and just use C or C++ where it's as simple as can be to call OS functionality. If you want to get some of the productivity gains of newer languages, expose a scripting API and embed Python or Lua. Hybrid systems of C or C++ w/ an embedded scripting API can give the best of both worlds.

This is just a use-case where Java doesn't really shine and C and C++ do.
Last edited by 0xBADFEED on Fri Nov 06, 2009 10:53 pm UTC, edited 1 time in total.
0xBADFEED
 
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Java vs C/C++

Postby gametaku » Fri Nov 06, 2009 10:11 pm UTC

MoghLiechty2 wrote:
gametaku wrote:group linux think**
...
**a smug superior attitude that believes computers should be hard to use, and write Microsoft as M$ (thankful they are not as prevalent as they use to be.)

The people 'round here who write Microsoft (may she live forever) as M$ seem to be particularly intelligent though, if misguided in their judgments of Microsoft as a corporation.


I was referring to the internet as a whole, not the xkcd forum.

mcv wrote:
gametaku wrote:Anyways as long as one is targeting the same platform they don't have to change and recompile code written in C or C++. The difference is that C or C++ can be used among various platforms: of X86 Windows, a cell phone, the the java platform, etc. The java language 99.9%* of the time is used on one platform: the java platform.

But it's a platform that's available just about anywhere. Come on, you're not seriously going to suggest that C is more portable than Java, are you? It really, really, very much isn't.


I stated before the Java platform was widely installed.

gametaku wrote:No, its write once, run everywhere people have the java platform installed. (admittedly it's fairly universal but it's not run everywhere)


The fact that the Java platform is available just about anywhere has nothing to do with portability, it just says that it's a platform with a large market share. Large market share != portability. Portability requires moving from one target* platform, to another separate target. The fact that one can write Java code on Linux and run the program on Mac-OS is irrelevant because neither Linux or Mac-OS were never targets.

*target would be the hardware and software that is needed to run your program.

mcv wrote:
Berengal wrote:3. Open source projects, overwhelmingly target Linux either by itself or as part of a collection of targets. Given the the nature of group linux think** (TM) no doubt many projects were written in C/C++ because Java programmers are "mediocre".

Take a look at the Apache projects. There's a ton of Open Source stuff in Java.


One I never said that nothing open source is in Java.
Two I was criticizing the method the site Berengal posted because there method of collection is biased in favor of C.
gametaku
 
Posts: 146
Joined: Tue Dec 30, 2008 2:21 am UTC

Re: Java vs C/C++

Postby Emu* » Sat Nov 07, 2009 9:04 pm UTC

My next fresh webdev project at work will use Grails, which is an MVC Groovy framework, which we'll deploy on Apache TomCat. Yay for JVMs!

I think if apps don't need specific OS features, there is little reason to use C++ over Java. I would consider C# over Java for internal apps except I'm not gonna waste money on buying VS and Windows for my work PC.

Games are a special case though.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!
User avatar
Emu*
 
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK

Re: Java vs C/C++

Postby Magic Molly » Tue Nov 10, 2009 2:31 am UTC

I'm getting an error trying to subscribe to this topic, hopefully this will fix it...

Currently, I'm learning Java as my first computer language. It's fun, but we're still on using for loops to create gradients and such.

<continues lurking>
Last edited by Magic Molly on Wed Nov 11, 2009 12:52 am UTC, edited 1 time in total.
User avatar
Magic Molly
 
Posts: 94
Joined: Sat Sep 26, 2009 10:42 pm UTC

Re: Java vs C/C++

Postby davidw » Tue Nov 10, 2009 10:12 am UTC

gametaku wrote:The site seems fairly poor in terms of determining popularity.
1. I did a quick yahoo search for C, the numbers were similar but the 4th result was the Wikipedia article on C++, I've found some references to C# no doubt that there are plenty more like that.
2. There is no direct information regarding usage in the professional world. (and the indirect isn't that good)
3. Open source projects, overwhelmingly target Linux either by itself or as part of a collection of targets. Given the the nature of group linux think** (TM) no doubt many projects were written in C/C++ because Java programmers are "mediocre".


As the creator of said site, I think you would be well within your rights to claim that the data are 'imperfect' or 'biased' but I do not think they are 'poor'. And where there are problems, the site is up front about them.

1. As the site says, the searches for C/C++/C# are imperfect - there is not really a way around that. However, the other statistics that do not suffer from this problem seem to confirm the relative rankings returned by the search numbers.
2. I think job postings are fairly direct and good ways of looking at what people are using in the professional world.
3. If you want to reduce the weight of the open source statistics, you can do that via the javascript controls on the site, and see how the numbers turn out.

In any case though, I do the best I can with the data that are publicly available, and think the results are fairly accurate, judging by what I see used in the real world. "Popularity" is something that you're never going to determine precisely, so giving people a rough idea from many data sources and letting them weight the sources themselves is probably about as good as it's going to get.
davidw
 
Posts: 0
Joined: Tue Nov 10, 2009 9:57 am UTC

Re: Java vs C/C++

Postby spiderham » Tue Nov 17, 2009 11:08 pm UTC

P4r4digm wrote:So I guess it would come down to development...no language is necessarily better than another, only suited for certain tasks and platforms...anyone know a type of problem that java would be able to solve easier/more effectively than C?


Java is much better suited in a business environment where you're pressured to produce software solutions on tight deadlines. Many components of such solutions are already available to you in the huge Java api, or the large volume of high quality open source software. So lots of the work is already done for you if you're using Java, and this makes you all the more valuable if you are called upon to come up with the solution.

C would be the the best choice if you need exceptionally high performance. C gives you access to memory and the operating system's native api. Java only gives you access to the native api that the creators of the virtual machine chose to give you access to (unless you use the JNI). So there are things you can do in C that you just can't do in Java. But mistakes in C can be costly. Your flawed C program with a memory leak could cause a server to crash. If you deployed it in a business, on a server that runs hundreds of other programs, it could be a nightmare for everyone to find out what program caused the crash, and it could cost the business large sums of money while the server is down. Everyone makes mistakes. How would you like to be the poor sap who made that one?

Java is the best when it comes to integrating different systems. Just about every vendor of database or ERP system offers an api in Java. IMHO, it's also the best for larger scale web application development.
spiderham
 
Posts: 60
Joined: Tue Jul 21, 2009 11:56 am UTC

Re: Java vs C/C++

Postby Xanthir » Thu Nov 19, 2009 2:05 pm UTC

spiderham wrote:Java is much better suited in a business environment where you're pressured to produce software solutions on tight deadlines. Many components of such solutions are already available to you in the huge Java api, or the large volume of high quality open source software. So lots of the work is already done for you if you're using Java, and this makes you all the more valuable if you are called upon to come up with the solution.

Though, enough languages are built on the JVM and can call into native Java code that it's really quite unnecessary to use Java itself anymore. Use a halfway decent language like Clojure and get the best of both worlds.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 3988
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Java vs C/C++

Postby headprogrammingczar » Thu Nov 19, 2009 4:32 pm UTC

Or if you want to be really crazy, Jython interfacing with the JNI interfacing with compiled Haskell.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you
User avatar
headprogrammingczar
 
Posts: 2953
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Java vs C/C++

Postby qbg » Thu Nov 19, 2009 10:29 pm UTC

Xanthir wrote:
spiderham wrote:Use a halfway decent language like Clojure and get the best of both worlds.

Is Clojure only halfway decent?
qbg
 
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Java vs C/C++

Postby headprogrammingczar » Thu Nov 19, 2009 11:51 pm UTC

Let's put it this way: Clojure isn't this.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you
User avatar
headprogrammingczar
 
Posts: 2953
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Java vs C/C++

Postby Xanthir » Fri Nov 20, 2009 12:47 am UTC

qbg wrote:
Xanthir wrote:
spiderham wrote:Use a halfway decent language like Clojure and get the best of both worlds.

Is Clojure only halfway decent?

I wasn't trying to impugn Clojure. It is at least halfway decent.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 3988
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Java vs C/C++

Postby Berengal » Fri Nov 20, 2009 1:33 am UTC

qbg wrote:
Xanthir wrote:
spiderham wrote:Use a halfway decent language like Clojure and get the best of both worlds.

Is Clojure only halfway decent?

It's based on LISP, which is based on lambda calculus, and that makes it an excellent term language. Unfortunately, it lacks a type language, so it's only halfway there.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.
User avatar
Berengal
Superabacus Mystic of the First Rank
 
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway

Re: Java vs C/C++

Postby Xanthir » Fri Nov 20, 2009 5:49 am UTC

Note that I hold the opposite view; the lack of a type language is a plus in my book.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 3988
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Java vs C/C++

Postby OOPMan » Fri Nov 20, 2009 7:02 am UTC

headprogrammingczar wrote:Let's put it this way: Clojure isn't this.


Jaskell would be useful if it was still maintained but last time I checked it's pretty much abandoned which means Clojure is automatically more useful than it.
Image

Image
User avatar
OOPMan
 
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Next

Return to Religious Wars

Who is online

Users browsing this forum: No registered users and 4 guests