I'd like an opinion, although it will probably be biased since I'm asking the members of the C++ forum and not the members of Java.

I'd also like to apologize in advance if this topic has been done before, but I don't like bumping old topics from years ago.


I normally wouldn't question something like this so soon because I don't know enough about C++ or Java to really understand an appropriate situation of why one would use one over the other unless it is one of the following reasons--

"Pushing for performance" - C++
"Platform Independence and huge API libraries" - Java

--However I just talked with an individual who claimed that Java is 70% of the programming industry. Lots of companies that rely on programs to run their business are switching to Java. Also he claimed that Java was initially meant to deal with hardware.

I may ask this question at a later time in the Java forum but for now I thought I'd ask experienced individuals here what their opinions are about this.

My other questions:


In all of your job-searches, were you more often asked if you could additionally program in Java? Or was it C++ ?

How many more jobs are there available between C and Java programmers?


I'd ask more, but I'm not really sure what else I should ask at the moment.

Recommended Answers

All 38 Replies

>I don't know enough about C++ or Java to really understand an
>appropriate situation of why one would use one over the other
C++ is well suited for back-end stuff, Java handles everything else. By "back-end stuff" I mean things like the JVM itself.

>I just talked with an individual who claimed that Java is 70% of the programming industry.
Did you laugh at his joke? :)

>Lots of companies that rely on programs to run their business are switching to Java.
Lots of companies that rely on programs to run their business are switching to .NET too. And the point is what, exactly?

>Also he claimed that Java was initially meant to deal with hardware.
It doesn't matter what it was initially meant to do. What matters is where Java fits in the here and now.

>In all of your job-searches, were you more often asked
>if you could additionally program in Java? Or was it C++ ?
It depends on the job. I was a Java programmer briefly, and they didn't care if I knew C++. Currently I work on C++ compilers, so my Java background isn't nearly as much of a factor.

>How many more jobs are there available between C and Java programmers?
It depends on the field, though I'd wager that you'll have an easier time finding a job writing Java than a job writing C or C++.

commented: Thank you Professor. +1

Though i'd like to believe otherwise but i think he's right to a large extent. Even in my own company they are porting the entire product from c++ to java and we have been asked to decide weather we'd like to move to Java or stay in c++ for supporting the old clients. Company is sponsoring java certifications too. I dont feel like moving to Java at all and so damn confused right now. My experience with Java is that it's pretty easy to learn and code. You dont need to worry about pointers and stuff, infact for sometime in between i did code in Java but then just left it completely. C++ is my choice and i hope to stick to it.

Another opinion is that as you move ahead in your career you'd rather be a jack of many trades so that you can handle projects on various technologies.

As of now i dont see any evident shortage of c++ openings atleast here in India.

C++ is powerful. As was mentioned, the JVM was written in C++. If you can't do something in another language, do it in C++. As is evident by the fact that the JVM is written in C++, you can create languages with C++. Almost all of the software you use relies in some way on C++. Certain things in C++ just seem like they're more correct than in other languages. I'm just beginning to learn Java, but Java seems to be a very web-oritented lanaguage (I read somewhere that its web oritentation iS why it doens't have pointers - since one of the qualities of being web-friendly is security, getting rid of pointers ensured that Java programs can't access memory outside of the JVM). Java code is not compiled. You can't create an .exe with Java. You create bytecode which is read by the JVM. Granted, getting the JVM is easy, and many machines have it, but still. You also can't make DLLs in Java, so if you want to create an API like DirectX - no Java.

One of the industries I have some minor knowledge of is the video game industry, and I know that C++ is big in games. The Unreal Engine is written in C++, and a lot of great games use the Unreal engine (Bioshock, Mass Effect, Oblivion (I think...),Gears of War, UT3, Rainbow Six, to name a few). I'm also very sure that the rest of these games and many other games are written in C++.

C++ is powerful.

And Java is powerful and so is Assembly.

As was mentioned, the JVM was written in C++.

It couldn't be written in Java, now could it? This is irrelevant.

If you can't do something in another language, do it in C++.

Or some other language. Take your pick, there are a ton to choose from.

As is evident by the fact that the JVM is written in C++, you can create languages with C++.

You can create languages from most any language. They are just mechanisms to convert text instructions to machine code.

Almost all of the software you use relies in some way on C++.

No, it all relies on machine instructions, as does C++ itself.

Certain things in C++ just seem like they're more correct than in other languages.

Seem more correct to whom? You? Computer scientists? Your third grade teacher? Jesus? "Seem more correct" is hardly an objective basis for any comparison.

I'm just beginning to learn Java, but Java seems to be a very web-oritented lanaguage

It was originally designed with network computing needs in mind, yes, but there is plenty in Java that has nothing whatsoever to do with networks or the web.

(I read somewhere that its web oritentation iS why it doens't have pointers - since one of the qualities of being web-friendly is security, getting rid of pointers ensured that Java programs can't access memory outside of the JVM).

Not allowing direct operations on memory addresses is just part of being a managed-memory language.

Java code is not compiled.

Certainly it's compiled. It's pre-compiled to bytecode and then compiled (and tuned) to machine code at runtime by the Just-In-Time (JIT) compiler.

You can't create an .exe with Java.

Sure you can: http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=java+to+exe
But you give up platform portability and may lose out on JVM/JIT improvements down the road. You can do it, it's just not a good idea for most cases.

One of the industries I have some minor knowledge of is the video game industry, and I know that C++ is big in games. The Unreal Engine is written in C++, and a lot of great games use the Unreal engine (Bioshock, Mass Effect, Oblivion (I think...),Gears of War, UT3, Rainbow Six, to name a few). I'm also very sure that the rest of these games and many other games are written in C++.

Yes, this is one areas where C++ is definitely favored for a few reasons. One being low-level performance concerns and another is leveraging extensive existing and tuned code bases. Java can and has been used to create large games, but it's unlikely to take the place of C++ in this industry. That in itself is simply one example of an area in which C++ would be more suitable for a given task. It does little to support the notion that you seem to be arguing, which is that C++ is better than Java for everything.

Alex, for a side-by-side comparison of the two this might be useful:
http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B

The choice really comes down to educated trade-offs based upon the task at hand. Both are powerful languages with differing strengths and weaknesses.

commented: Great post. +5

>And Java is powerful and so is Assembly.
The point is Assembler and C++ are the most efficient, when written right.

>You can create languages from most any language. They are just mechanisms to convert text instructions to machine code.

But sometimes languages throw in useless ASM/binary code that makes it slow.

C++ is better than Java for some things - Java better for others, like string parsing.

The game industry uses C++ because it's one of the fastest languages, if you did the same game with Java I bet you wouldn't get the same fps.

why did I post here...

Exactly. You are just supporting the same point that I was trying to make: each has it's own strengths and weaknesses that need to be taken into consideration when deciding which to use for a specific purpose.

commented: Ezzaral, you rock dude! +1

Mhm. That's the whole point, choose the language for the job. Java is better than C++ at string parsing, C++ is better than Java at low-level things, bit manipulating, memory stuff, games... whatever.

I keep repeating, don't I... :P Oh well.
/thread

Thanks everyone, for your responses.

I'll look into the link you provided Ezzaral. Thanks be to you too Professor for giving me an opinion based on your experiences.

It couldn't be written in Java, now could it? This is irrelevant.

I simply meant that Java is dependent on C++, while C++ is not dependent on Java.

No, it all relies on machine instructions, as does C++ itself.

I meant that in addition to programs that are actually written in C++, programs written in Java also rely on C++, since they rely on the JVM (which is partly why I mentioned the point above).

Seem more correct to whom? You? Computer scientists? Your third grade teacher? Jesus? "Seem more correct" is hardly an objective basis for any comparison.

Actually, one of my programming friends does looks a bit like Jesus. Mrs. Salisbury though, she wasn't a big programmer. No, just kidding. I meant myself. I do like to think of myself as a computer scientist in training, but like I mentioned, I'm young and have no actual industry experience, so to say that I'm speaking for "Computer Scientists" would be a bit arrogant. There are just certain things in C++ that just seem more "correct" to me (like the ability to have global functions, to name one).

It was originally designed with network computing needs in mind, yes, but there is plenty in Java that has nothing whatsoever to do with networks or the web.

Really? Like what (genuine curiosity)?

Not allowing direct operations on memory addresses is just part of being a managed-memory language.

What's that, exactly?

Certainly it's compiled. It's pre-compiled to bytecode and then compiled (and tuned) to machine code at runtime by the Just-In-Time (JIT) compiler.

Sorry, I meant no executables. But apparently that's not true either.

Java can and has been used to create large games

Just wondering - I've begun to write some games, and I find that I'm heavily reliant on linked lists to keep track of any set of objects that change during runtime (like bullets). How do you handle stuff like that in Java?

It does little to support the notion that you seem to be arguing, which is that C++ is better than Java for everything.

That's not what I'm trying to say. My current perspective of the two was that C++ is more, I want to say "basic", but that seems like the wrong word. To make an analogy, C++ seems to me more like raw silver, while Java seems more like a ring. Not that that analogy is meant to show the magnitude of the difference between them, just the actual relationship.

Yeah, and you have more control over objects in C++. Pointers, references, whatever. They all allow you greater control over what you code.

Really? Like what (genuine curiosity)?

Well, if you take a glance at the API docs for Java SE (Standard Edition, not EE which denotes the Enterprise Edition APIs) you'll quickly see that a majority of the content is unrelated to or not specific to networking or web concerns. It encompasses things like basic i/o, collections, math, graphics, printing, GUI components, event handling, multi-threading, database access, regular expressions, xml, cryptography, security, and a lot more. Some of those can certainly apply to network operations, but they are by no means specific to them.

Just wondering - I've begun to write some games, and I find that I'm heavily reliant on linked lists to keep track of any set of objects that change during runtime (like bullets). How do you handle stuff like that in Java?

Just like you would in C++. Java's references function just like pointers with the exception that you can't alter the memory address itself. A basic linked list just needs a reference to the head element and the next element. Linked lists, doubly-linked lists, circular linked lists, stacks, queues, and any other generic data structure for handling collections of things are easily implemented in Java. The standard API even offers many implementations of them for you in the Collections Framework

That's not what I'm trying to say. My current perspective of the two was that C++ is more, I want to say "basic", but that seems like the wrong word. To make an analogy, C++ seems to me more like raw silver, while Java seems more like a ring. Not that that analogy is meant to show the magnitude of the difference between them, just the actual relationship.

I understood the intention and much of your post was basically correct. It just ran toward a subjective assertion that C++ was better for everything rather than an objective view of the differences between the two. I wanted to address your points individually to illustrate the point that I ended my post with

The choice really comes down to educated trade-offs based upon the task at hand. Both are powerful languages with differing strengths and weaknesses.

C++ is most definitely an exceptionally powerful and flexible language. With that comes a greater degree of complexity and cautious attendance to managing that appropriately. C++ gives you a ton of rope to accomplish most anything - more than enough to hang yourself if you aren't careful with it :P

It just ran toward a subjective assertion that C++ was better for everything rather than an objective view of the differences between the two.

Ya, that was probably because I don't know Java well enough to say anything good (or bad) about it, whereas C++ is the only real language I know well.

I didn't know that Java's references could create linked lists. So what exactly is the benefit of C++ pointers? That you can do something like: int* pnVar = &someOtherVar; ?

Pointers allow you to alter the memory address itself, not just the contents of that memory address. The C++ gurus here can probably give you a lot better answer, but this FAQ might help a bit: http://www.parashift.com/c++-faq-lite/references.html

>So what exactly is the benefit of C++ pointers?
You have much more control with pointers than you do with references. References (in Java at least) are designed to be pointers without the dangerous aspects of pointers, but it's those very dangerous aspects that give pointers incredible power if you know what you're doing.

Pointers allow you to alter the memory address itself, not just the contents of that memory address. The C++ gurus here can probably give you a lot better answer, but this FAQ might help a bit: http://www.parashift.com/c++-faq-lite/references.html

Err, what I got from that was essentially that you can't rewrite a reference, but you can assign multiple addresses to a pointer (other than how pointers and references actually work - I mean in terms of the uses of them). Is that the gist of it? Or not? Or is it sort of hard to explain the precise differences between them, and that you just "get it" after a while?

Also, if someone had an example of something you can do with C++ pointers that you can't do with Java references, that would help.

Pointer arithmetic is one thing. Such as traversing an array by incrementing the pointer. That is not possible with references.

I see. But is that really all the useful? I mean what's the benefit of that method over using an array and the [] operator?

I see. But is that really all the useful? I mean what's the benefit of that method over using an array and the [] operator?

Not exactly sure how pointer arithmetic has superiority over the [] operator, but I do know that Ezzaral's statement about manipulating memory is true.

For example, you can take a location of memory in the heap and directly allocate it with enough space to hold a standard int (4 bytes), a standard double (8 bytes), or other data types.

In Java, you cannot do this. You have no direct access to the Heap. You do use the Heap by creating objects via the new keyword, but that's it. Also anything that falls out of scope and does not have some type of reference pointing to it in java is immediately finalized (or rather, its destructor is called, though in Java this is finalization). Note that you CANNOT finalize a java object manually unless NOTHING is pointing to it! This leads to serious memory-management restrictions, aside from the fact that you don't have any real access to the heap anyways.


[Edit] As for C++ and its pointers...

If you wanted to manage memory properly, you can assign new memory in the location of an old address that you assigned then deleted. I'd imagine that this would be useful when you need to keep memory in a tight spot or if you simply want to reuse locations in the event that you have some type of numeric-reference to them and you don't want to allocate memory in random locations.

There are more memory manipulating operations that you can do in C++ that you can't do in Java. I've seen some device-handling procedures where pointers are used and bit-shift operators are used to access locations of memory specific to the device but I haven't done enough research nor know enough to provide a valid example.

I also believe that pointer arithmetic diminishes the amount of code you need to write to do something.

Coupled with comma-spaced statements that perform operations, you can do a great deal all at once especially with pointer arithmetic.

I see. But is that really all the useful? I mean what's the benefit of that method over using an array and the [] operator?

Well I don't know how useful this is to others (it's been useful to me though) and whether you can do it in Java or not, but sometimes you might want to have a sub-array of a larger array and be able to pass that sub-array to some function for whatever reason. For example, what if you are a teacher and you have 20 students and you've sorted them by exam score. 15 of the 20 have passed and you want to do whatever with them (in the case below, just display the grades) in three different groups (all students, passing students, failing students). In Java, as far as I know, you can't have an array start in the MIDDLE of another array like you can in C++. So in this case in Java you'd have to create three arrays and set aside separate memory for three arrays and do a copy from the original array to the other two arrays. I can't think of a way to have three separate arrays like below in Java without doing a big array copy, which takes time and memory. Feel free to correct me if I am wrong. I may well be.

#include <iostream>
using namespace std;

int DisplayScores(int scores[], int numStudents);

int main ()
{
    int numStudents = 20;
    int numPassingStudents = 15;
    int numFailingStudents = numStudents - numPassingStudents;
    
    int* allScores = new int[numStudents];
    
    for (int i = 0; i < 20; i++)
        allScores[i] = i + 1;
        
    int* passingScores = &allScores[numFailingStudents];
    int* failingScores = allScores;
    
    cout << "Here are all the scores\n";
    DisplayScores(allScores, numStudents);
    
    cout << "Here are the passing scores\n";
    DisplayScores(passingScores, numPassingStudents);
    
    cout << "Here are the failing scores\n";
    DisplayScores(failingScores, numFailingStudents);
    
    return 0;
}
    
        
int DisplayScores(int scores[], int numStudents)
{
    for (int i = 0; i < numStudents; i++)
        cout << "Student " << i << ": Score = " << scores[i] << endl;
}

Well I don't know how useful this is to others (it's been useful to me though) and whether you can do it in Java or not, but sometimes you might want to have a sub-array of a larger array and be able to pass that sub-array to some function for whatever reason. For example, what if you are a teacher and you have 20 students and you've sorted them by exam score. 15 of the 20 have passed and you want to do whatever with them (in the case below, just display the grades) in three different groups (all students, passing students, failing students). In Java, as far as I know, you can't have an array start in the MIDDLE of another array like you can in C++. So in this case in Java you'd have to create three arrays and set aside separate memory for three arrays and do a copy from the original array to the other two arrays. I can't think of a way to have three separate arrays like below in Java without doing a big array copy, which takes time and memory. Feel free to correct me if I am wrong. I may well be.

#include <iostream>
using namespace std;

int DisplayScores(int scores[], int numStudents);

int main ()
{
    int numStudents = 20;
    int numPassingStudents = 15;
    int numFailingStudents = numStudents - numPassingStudents;
    
    int* allScores = new int[numStudents];
    
    for (int i = 0; i < 20; i++)
        allScores[i] = i + 1;
        
    int* passingScores = &allScores[numFailingStudents];
    int* failingScores = allScores;
    
    cout << "Here are all the scores\n";
    DisplayScores(allScores, numStudents);
    
    cout << "Here are the passing scores\n";
    DisplayScores(passingScores, numPassingStudents);
    
    cout << "Here are the failing scores\n";
    DisplayScores(failingScores, numFailingStudents);
    
    return 0;
}
    
        
int DisplayScores(int scores[], int numStudents)
{
    for (int i = 0; i < numStudents; i++)
        cout << "Student " << i << ": Score = " << scores[i] << endl;
}

I think I understand what you mean, and I'm pretty sure you're correct.

From the above example, it looks as if you're taking the address of the array at the location just after indice numFailingStudents which will act as a sub-array for the student range from indice numFailingStudents to numStudents.

I seriously doubt this is doable in Java.

public class Testing_Something_5{

	int value1[] = {5, 6, 1, 2, 3};
	int value2[] = value1[3]; // illegal

}

Edit: I'd have to look at the Array class to see if its possible to return a portion of an array starting at a valid address.

This does seem doable via a linked list though, since linked lists rely on root values. But a Linked list isn't directly an array.

anything that falls out of scope and does not have some type of reference pointing to it in java is immediately finalized (or rather, its destructor is called, though in Java this is finalization). Note that you CANNOT finalize a java object manually unless NOTHING is pointing to it! This leads to serious memory-management restrictions, aside from the fact that you don't have any real access to the heap anyways.

Ahh, ok. This seems much more useful. So there's no way to keep an object in scope after it normally would've been finalized (or is it just easier to do than in C++).

I'd just like to say that apparently it is possible to user part of an Array in java but it's not obvious--

import java.util.*;

public class Testing_Something_5{
	public static void main(String[] args){
		Testing_Something_5 value1[] = {
			     new Testing_Something_5(), new Testing_Something_5(),
			     new Testing_Something_5(), new Testing_Something_5(), new Testing_Something_5()
		}, value2[] = Arrays.<Testing_Something_5>copyOfRange(value1, 2, value1.length);
		for(Testing_Something_5 num : value1)
			System.out.println(num + " " + num.toString());
		System.out.println();
		for(Testing_Something_5 num : value2)
			System.out.println(num + " " + num.toString());
	}
}

You'll notice the proof in the addresses printing to the screen.

There may or may not be methods of doing this for wrapper classes - it's fairly hard to tell since the toString() representation of the class is overridden with the value of the number/String.

Edit: Disregard this post. I see your main point - there's no way to do this without doing additional work, like you said before.

Ahh, ok. This seems much more useful. So there's no way to keep an object in scope after it normally would've been finalized (or is it just easier to do than in C++).

These links may be helpful for you to study to further understand how Garbage collection works--

http://en.wikibooks.org/wiki/Java_Programming/Destroying_Objects

http://www.javaworld.com/jw-06-1998/jw-06-techniques.html

Ezzaral or any Java-proficient individual please correct me if the following below isn't 100% correct--

import java.util.*;

public class Testing_Something_5 extends Object{

	Integer i1 = 999, i2 = 888, i3 = 777;
	int l = 9999999, m = 1;

	public Testing_Something_5(){
		System.out.println(this.toString() + " Constructed!");
	}

	public static void main(String[] args) throws Throwable{

		Runtime rt = Runtime.getRuntime();

		// memory before garbage collector is called--

		System.out.println("Free Memory: " + rt.freeMemory() + "        Total Memory: " + rt.totalMemory());

		long initialFreeMemory = rt.freeMemory();

		Testing_Something_5 ts5 = new Testing_Something_5(); // object with reference
		new Testing_Something_5(); // anonymous object

		rt.runFinalizersOnExit(true); // unsafe method - deprecated warning

			{
				Testing_Something_5 ts5_2 = new Testing_Something_5(); // object defined within block scope through pointer
			}

		rt.gc(); // runs the garbage collecter, finalizing any objects that no longer have a reference pointing to them
		// finalization of anonymouse object--

		// notice no finalization of block scope - proof that Java reference-variables are indeed pointers

		// displaying the memory bump after garbage collector called--
		System.out.println(rt.freeMemory() - initialFreeMemory);

		// Displaying the new amount of free memory
		System.out.println("Free Memory: "+rt.freeMemory() + "        Total Memory: " + rt.totalMemory());

		// pausing the program to differentiate between garbage collected objects and objects still being referenced
		Thread.sleep(3000);

		// all objects should be finalized before exit due to deprecated method
	}

	@Override
	protected void finalize() throws Throwable{
			try{
				System.out.println(this.toString() + " No longer has references pointing to it and fell out of scope!");
			}catch(Throwable t){
				System.out.println(t);
			}finally{
				super.finalize(); // calls the finalize method of the base Object of this class
				System.out.println(this.toString() + " was finalized!");
			}
	}
}

Actually the language spec makes no guarantee as to when or what order finalizers will be called or which thread will call them.

The Java programming language does not specify how soon a finalizer will be invoked, except to say that it will happen before the storage for the object is reused. Also, the language does not specify which thread will invoke the finalizer for any given object. It is guaranteed, however, that the thread that invokes the finalizer will not be holding any user-visible synchronization locks when the finalizer is invoked. If an uncaught exception is thrown during the finalization, the exception is ignored and finalization of that object terminates.

The whole section on finalization is here: http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.6
Also, System.gc() and System.runFinalization() are documented as only "suggesting" that the JVM perform these operations.
Anyway, the people here in C++ world probably don't care much about the details of Java garbage collection, so I won't drag along the discussion :)

Actually the language spec makes no guarantee as to when or what order finalizers will be called or which thread will call them. The whole section on finalization is here: http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.6
Also, System.gc() and System.runFinalization() are documented as only "suggesting" that the JVM perform these operations.
Anyway, the people here in C++ world probably don't care much about the details of Java garbage collection, so I won't drag along the discussion :)

I wouldn't say that.

It might be interesting enough for an individual who wants to program a Garbage Collector in C++ with the usage of threads.

In Java, as far as I know, you can't have an array start in the MIDDLE of another array like you can in C++. So in this case in Java you'd have to create three arrays and set aside separate memory for three arrays and do a copy from the original array to the other two arrays.

How about using 3 integers that resembles the index.
all_stud = 0 ;
fail_stud = 0 ;
pass_stud = numFailStud ;
and access allScores[pass_stud+i] or something like that.
Works with both language, though I know it cant completely replace the need of pointers.


Are C++ & JAVA the only 2 dominant language in the industry? If yes why not any other language like BASIC. If no, what are the other languages used?
I want to know this. Please

>Are C++ & JAVA the only 2 dominant language in the industry?
Hell no. They're just the most commonly bitched about. ;)

>If yes why not any other language like BASIC.
BASIC itself tends to be restricted to students these days, but variants of Visual Basic are still going strong.

>If no, what are the other languages used?
Some of the more popular/trendy are assembly, C, VB6, VB.NET, C#, Ruby, Haskell, F#, Perl, Python, PHP, Delphi, Javascript, VBA, and about fifty-jillion others that don't come immediately to mind.

So many languages are used widely in industries & I have not even heard of some of those languages. My head is swinging.

What is .Net? Is it a language? I have heard people say VB.Net, ASP.Net, C#.Net, etc. What do they mean

So many languages are used widely in industries & I have not even heard of some of those languages. My head is swinging.

What is .Net? Is it a language? I have heard people say VB.Net, ASP.Net, C#.Net, etc. What do they mean

Because they need .Net FrameWork I guess.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.