As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been writing Java professionally for the last 5 years. Recently, I've had to dig into JNI a bit to call some Windows specific functions.
This experience has highlighted my poor command of the C (or C++ for that matter) language. My only introduction to C was a brief "dummies" book that I read in high school 11 years ago.
I know that both languages have advanced in that time frame, especially C++ and the standard library.
Would it be appropriate for me to learn C or C++? Which books would be best?
Do folks also have any recommendations for Windows programming as well? I can read through MSDN well enough to figure out certain API calls but I have a feeling I'm missing things in regards to the "big picture".
Thanks
Good question. On the surface, it'd be obvious to recommend C++, because "it's object oriented like Java". Only problem is, it's not really true.. C++ allows OOP, yes, but it's just one of several paradigms that C++ supports. Treating C++ like a OOP language (and especially, treating it like Java) will only lead to frustration.
The problem is that Java and C++ don't actually have much in common. Java programmers often believe that Java was inspired by C++, but that's only true if by C++ you mean the very earliest versions of C++, which might more appropriately be called "C with classes".
Since then, C++ has transformed completely into its own language with its own way of doing things. It has probably changed far more since then than Java has. A Java programmer back then would still be able to make sense of today's Java code. Not so for C++. So I'd argue that C is actually closer to Java than "modern C++" is. C is what you get if you take Java and strip away the GC and the concept of classes and a few other abstractions. To arrive at C++, you have to add a similar number of features to our hypothetical stripped-down Java as well.
Further, C++ is a remarkably complicated language, and learning it well takes ages. And if you don't learn it well, you're going to shoot yourself in the foot over and over again.
Finally, it depends on your objectives.
C++ is a much more modern language than C, and once you learn it, very expressive and powerful and, surprisingly, it can even be very elegant and concise. But the learning curve is nasty. So for native programming in the long term, I'd recommend C++ over C.
But if your goal is primarily to interface with the Win32 API (or other native API's for that matter), you won't need C++. Win32 and most other API's are written in C, not C++, and you most likely won't need very complex code to interface between that and Java in any case.
About learning Win32, you're right, all the details you need are on MSDN. If you want the big picture, Petzold is the book on the subject.
I guess it depends on your objectives.
If you want to get closer to the machine, then C.
If you want to supplement you knowledge of a OO Java-like layer above C, then C++.
Accelerated C++ (sanitised Amazon link) is an awesome book to learn C++ from the point of view of C++ and not just C with other bits tacked on,
And K'n'R C (sanitised Amazon link) is still the way to go for learning C IMHO!
BTW For C++ follow up with the wisdom of Scott Meyers in the Effective C++ books! And his Effective STL book as well.
HTH
cheers,
Rob
Learn enough C++ to use it as "a better C". You don't have to try to map all of it onto your understanding of Java. All you want is to be able to use C++ objects as abstract data types, new and delete, etc. If STL comes along for the ride, so much the better.
The real question is: Why do you think that JNI is such an absolute necessity? The Windows calls will ruin any thought of keeping your app portable. I'm sitting next to a guy who's having to dig into a Java app that uses JNI. It randomly brings down a server with a SEG FAULT. His hypothesis is that the heap fills up, a JNI call is made to a routine that calls malloc to allocate space on the heap. It's not available, the routine doesn't check the returned pointer for null, deallocates it, and down comes the server. He's still trying to reproduce the error locally, because it requires precise timing to call the JJNI method just before the GC starts up.
100% sure they're required? Just asking....
If you have a good understanding of Java, I'd recommend that start with C, if you start directly with C++ there're a lot of differences between it and Java, and you probably will dislike it.
If you are serious about learning both languages I'd recommend "The C++ Programming Language" by Bjarne Stroustrup, and "The C Programming Language" by Dennis Ritchie.
I think that C++ would be much easier for you to become proficient in than C.
If you've been using Java, you'd have a hard time doing away with conveniences like classes, exceptions, a form of references, dynamic binding, etc. and of course, decent libraries.
However, you should learn C first to make sure you really understand what's under the hood and get to experience pointers and their use and the feeling of working "with no protective gear".
Once you master that, learn about the inheritance mechanisms in C++ and how it's different from Java (e.g., multiple inheritance).
This really depends on your strengths and weaknesses. If you really like design patterns, then I'd suggest using C++, but if you just have to implement a couple simple methods in JNI, then I would recommend C. Learning C before C++ should give you a better understanding of memory management without having to worry about some of the complexities of C++ (constructor call order, destructors, and other differences between C++ and Java).
I would suggest "The C Programming Language" by Kernighan and Ritchie as the definitive manual for learning C. http://www.amazon.com/Programming-Language-Dennis-M-Richie/dp/0876925964
If you're on a *nix system, there's ample documentation in the manpages for different functions. For example,
bash$ man malloc
If you want an excellent resource for C, "The C Programming Language" by Dennis Ritchie is the book to get.
If your intent is to continue writing JNI code then I'd definitely recommend C++.
In particular, the JNI interface requires you to acquire (and subsequently release) references to Java objects. Using C++ auto variables you can get these references using 'RAII' (Resource Allocation is Initialisation) techniques which makes memory management far simpler.
100% sure they're required? Just
asking....
Unfortunately, yes.
Thanks everyone for your answers.
To answer some of the follow up questions, I'm not looking for a career change to C or C++. I'd just like to learn the fundamentals so I don't feel like I'm flying blind when I do need to write bits and pieces.
In particular, the JNI interface
requires you to acquire (and
subsequently release) references to
Java objects. Using C++ auto variables
you can get these references using
'RAII' (Resource Allocation is
Initialisation) techniques which makes
memory management far simpler.
Thanks, that is helpful. One of the areas that stoked the growing concern in my stomach was dealing with manually managing the memory associated with the JNI objects
If your "main goal" here is to do windows programming, I'd recommend C# over C or C++. However I believe every programmer on Earth, and in Lower orbit, SHOULD know C. Not knowing C++ is acceptable, although you might not get invited to a few parties :) But C is something of a rite of passage, between Applications (high-level) programmer and Library (low-level) programmer.
Related
I'm a Java guy doing mostly Android stuff.
I want to get into game programming for Android and was wondering if there is any point learning C (not for android obviously as there you can only write in C++). What do people still use C for? Isn't it a bit old and overrun by Java and Objective-C?
I will definitely learn C++ as everybody says you need it for game programming. Would you learn it simultaneous to Java (I'm still learning) or should I learn Java first?
Despite being quite an old language, C is in fact still one of the most frequently used languages. According to the well known Tiobe language index, it only trails behind Java: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
C is still being used a lot in many environments, among which embedded systems but also regular desktop applications. Especially on Linux, C has a strong following even for work outside systems/kernel development.
The Java / C++ connection is legendary though. It's clear the Java syntax heavily leans on the C++ one, but in concepts the language is actually much closer to Objective-C. Patrick Naughton (one of the early Java language designers) has recently posted about this: Java Was Strongly Influenced by Objective-C
So to better understand Java it definitely pays off to learn C++ and Objective-C at some time, but it absolutely isn't a requirement. If you've learned any of those two, you have automatically learned (large) parts of C.
In general, better learn one language reasonably well before hopping on to the next one.
I learned C as my first language. The focus was on memory allocation and deallocation, and simple datatypes such as dynamicly allocated arrays, variable sized dynamic allocated arrays, pointers et cetera.
This was enough to do a fully fledged application of course, but looking back at it now, it was much harder to do things in; I was limited to arrays, dynamic or static, so the complexity of it was horrible.
Anyway, it meant that later on I could focus on object oriented programming and efficient data structures, algorithms et cetera in C++ and Java without worrying at all about programming.
All methods work, but I'm very glad that I understand how memory works. Most of the people I meet at my University that learned programming through Java, do not understand this. And I think it's quite important :)
C is one of the most powerful languages available. And as they say with great power comes great responsibility. Due to its immense flexibility it is very easy to make mistakes and drive programmers crazy while programming/debugging in C. Anyhow I feel that to be a 'great' programmer, you need to learn the nuts and bolts of how memory and pointers are allocated/deallocated, garbage collection.. from C which is never exposed to programmers in Java. And for your game programming ambitions it will definitely help too as you use it to optimize performance.
I'd recommend you learn C along with Java, so that you better appreciate their differences and similarities or you would become too dependent on Java and the transition to C becomes more hard.
To learn any language, the best way is to program. Here http://cslibrary.stanford.edu/, you would get the best exercises to get you started.Have fun!
If you learn C++, learning C is only a small step. As a first approximation, C is more or less a subset of C++.
I'd thoroughly learn Java together O-O design skills and design patterns, before taking on C / C++. Once you start with C / C++ you have to deal with issues like pointers and explicit memory management ... and language specifications that say "the behavior of X is undefined" a lot more.
It is easy for the complexity of languages like C and C++ to get in the way of learning design skills.
Firstly Objective-C is basically only for development on Apple technologies so it is definitely not as powerful in its compatibility/portability aspect as opposed to C. C++ was actually only created as a library to add classes to C. When developing in C++ you are really developing in a massively updated C. Java has not overrun C rather provided another approach to programming. Java does not have the low level power of C(editing memory...).
C is used for system programming in particular in Linux kernel.
But in fact, learning programming languages != learning programming.
So, its best for you to learn Java first as your primary programming language AND read some books listed here: What is the single most influential book every programmer should read?
After that expanding your knowledge would be easier.
C is used for many things. Most of (PC) applications you use are still written in C or C++. You can read about the details here for example ;-)
Java is different, and it is not really that evolutionary step that many advocates try to suggest.
I am ActionScript 3/Flex programmer, it is the first language I learned.
I want to learn either Java or C++.
Would one of these be easier to learn based on my current knowledge?
It really depends what you want to do. C++ is more powerful and fast. But Java has a smaller learning curve.
I'd say learn C++, only because it will require you to gain a better understanding of how computers work under the hood. It will also help position you to learn Java, C#, or any other language down the road.
Java seems more likely to be directly relatable to your work in AS3; C++ is better for giving you a grounding in a different technology (pointer-style OO rather than object-style. C++ may feel eerily similar yet different).
If you are doing C-ish C++, the pointer language learning process can be very informative as to how OS-level calls are written...
The places where you will reach for one tool or the other are very different, and the use you have for the tool may be more important in deciding than their relative merits as languages - employability IS a use for a tool, after all.
Well, AS3 more closely resembles JavaScript - they both follow the ECMAScript specification.
But to answer your question, I would say learning Java will be more beneficial and easier for you. Java supports Interfaces, and single inheritance, like Flex, whereas C++ supports multiple inheritance and lacks a formal notion of Interfaces. Java and Flex both manage memory for you, whereas C++ forces you to manage your own memory. Both Java and Flex have large helper libraries out of the box, and both have native String types, whereas C++ forces you to find a library to use and doesn't support native String types.
This may be my own bias, but it also seems more likely that you'll find a job that is looking for a Flex/Java developer, rather than a Flex/C++ developer. Java and Flex seem to work well together, with Flex as a front end and Java as a middle and back end.
I would say Java is more similar to AS3 than C++. You will find lots of familiar metaphors and mechanisms.
C++ on the other hand, will require more effort to learn. It is closer to the machine and demands an undertanding of lower level mechanisms. For instance, there is no garbage collection so you have to manage your memory resources yourself.
Which is better to know depends on what you plan to do with the language. C++ is good at performance critical applications (games, all kinds of real time simulations etc.). Java makes it easier and safer to build things, but at the cost of performance.
hope this helps
regards
C++ is, generally, harder to learn than Java. You will find this true pretty much no matter what your previous experience. Therefore, if you want to learn the easier, learn Java.
(This is partly a matter of design philosophy. C++ was designed to be mostly upward compatible from C, at least the C at the time C++ was being designed. It was also designed
to be useful and permissive, with ease of learning being secondary. Java was designed partly as a reaction to C++, as a generally safer and easier language. C++ is more expressive than Java, but this comes at a price: it's harder to learn C++, and easier to screw up with it.)
That being said, you never said why you wanted to learn another language. You might well be better off learning C++, even though it is more difficult.
Whatever you'll finally decide to learn, do yourself a favor and read either Thinking in Java or Thinking in C++.
Both books are available - for free! - at Bruce Eckels website. They are very, very good.
C++ is more complex than Java so I'd suggest to take a look at Java, first.
However, this isn't meant as C++ bashing. Both are great language, it just depends on what you'd like to do in the end.
I would go with Java. It will be easier to learn and, given your background, I'm guessing you do more web/internet work in which case you'll probably find more ways to apply the Java knowledge then you would C++.
I think you would find Java more similar.
Learning C++ will likely require you to learn concepts that you could avoid with other high level languages (such Java and AS3) e.g. manual memory management, pointers, non forward looking compiler, multiple inheritance, etc.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What is the difference between Java and C++? Are both object-oriented?
This is far too general a question to be answered here.
Java is an explicitly object-oriented language, with the harder-to-use bits snipped off.
C++ is a multi-paradigm language with the safety off. You can do object-oriented programming in it, as well as procedural and generic.
If you had a more specific question, we could be of more help. Why did you ask? If you want recommendations for a particular platform, or project, or whatever, we could be more responsive.
A C++ programmer will tell you that Java is rubbish. A Java programmer will tell you that C++ is rubbish. Therefore I conclude that they are indeed the same thing.
Each language designed with different purposes in mind, so IMO it's not fair to compare the two from one perspective, and ignore the other.
Generally speaking, C++ is an open standard, designed for implementing high performance systems where speed and performance and critical, there are lots of impressing projects designed using this language like Phoenix Lander, Adobe Acrobat Reader and others. C++ gives the developer the ability to program using a very high level abstraction -using generics for example, and, when needed, go down deep to the bare metal of the machine -to handle an interrupt for instance.
Java was designed with other purposes in mind, when Sun was planning Oak (later called Java), it focused on web applications so it supported the language with a bunch of heavy libraries of easy-to-use interfaces considering that. and portability (Compile once, run anywhere) using JVM, which prevents the programmer from coding to specific machine, but instead coding to a sandbox which in turn runs the code on the hosting machine, and this has obviously negative reflections on performance/speed.
Comparison of those two language is a popular cause of debate between programmers, and this is due to their different working demands and nature, IMO every language has made mistakes in order to mature, for example, C++'s exported templates, and Java's lack of procedural programming (Big Mistake). plus, each one has its pros and cons regarding different aspects, hence the one that balance productivity/performance issue IS the right language.
For more information Wikipedia's comprehensive article on Comparison of Java and C++
It might be interesting to take a look at what languages are used (and being used) to create major systems (like Google) from here.
One of the most important differences hasn't been mentioned yet - one is compiled to machine code, the other is compiled to bytecode which is interpreted by a virtual machine.
Everything is Object in Java as everything is derived from java.lang.Object But this is not the case in C++
No pointers in Java whereas C++ has provide support for pointers
No destructors in java (Java has automatic garbage collection) but C++ has destructors to do that
Thread support is built in Java but not in C++
No scope resolution operator in Java
No Goto statement in Java
No Multiple Inheritance allowed in Java but C++ allows that
No operator overloading is allowed in Java but C++ allows that
Java is interpreted for most part and hence Platform independent
Both are object oriented but they are very different languages. This probably isn't the best forum to ask for the differences... I would suggest you look both up on Wikipedia and review the descriptions there. You will be able to see the differences very quickly for yourself.
I love c++ but unless you absolutely need to use c++ then use something else. When you need to use c++ then you will know the difference, Grasshopper.
(hint do not write device drivers, video decoders, encryption libraries, 3-d graphics engines or language run-time engines in java).
Yes, both are object oriented programming languages.
C++ is an evolution to C. Which was a system programming language. C++ Added many features to the language to make it object oriented. It became the mainstream programming language for that reason.
Java is an evolution of C++, with different goals ( cross platform for instance ). It remove some of the features that make C++ so hard to learn. Simplify others and remove others.
The main difference is C++ programs are compiled directly to machine code ( understood by the CPU ) while Java programs are compiled to be run in a "Virtual Machine" the JVM most of the cases. For these reasons java programs were interpreted by another program and at the beginning were veeeery slow programs. Nowadays the VM may optimize this code and make it run very very fast.
See this link.http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html
Gross but accurate oversimplification: Java is easier. C++ is faster.
Just a quick addition to what David Thornley posted. C++ is a procedural language that supports Objects and OO design. Java is pure OO. Java does less but on more.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Is the D language a credible alternative to Java and C++? What will it take to become a credible alternative? Should I bother learning it? Does it deserve evangelizing?
The main reason I ask is that with the new C++ standard (c++0x) almost here, it's clear to me that the language has gone well past the point of no return with respect to anyone ever understanding it. I know that C/C++ will never die but at some point we need to move on. Even COBOL had its day and Java has in many respects undone C++. So what's next? Does D fill the bill?
What determines the success and popularity of a programming language for real-world software development is only partially related to the quality of the language itself. As a pure language, D arguably has many advantages over C++ and Java. At the very least it is a credible alternative as a pure language, all other things being equal.
However, other things matter for software development - almost more than the language itself: portability (how many platforms does it run on), debugger support, IDE support, standard library quality, dynamic library support, bindings for common APIs, documentation, the developer community, momentum, and commercial support, just to name a few. In every one of those regards, D is hopelessly behind Java, C++, and C#. In fact, I'd argue it's even behind so-called "scripting" languages like Python, Perl, PHP, Ruby, and even JavaScript in these regards.
To be blunt, you simply can't build a large-scale, cross-platform application using D. With an immature standard library, no support in any modern IDEs (there are plugins for both Visual Studio and Xamarin Studio/MonoDevelop), limited dynamic/shared library support, and few bindings to other languages, D is simply not an option today.
If you like what you see of D, by all means, learn it - it shouldn't take long if you already know Java and C++. I don't think evangelism would be helpful - at this point if D is going to succeed, what it really needs is more people quietly using it and addressing its major shortcomings like standard library and IDE support.
Finally, as for C++, while most agree the language is too complex, thousands of companies are successfully using C++ as part of a healthy mix of languages by allowing only a smaller, well-defined subset of the language. It's still hard to beat C++ when both raw performance and small memory usage are required.
Just to add my own experiences into the mix:
About a year ago I worked on a small scale game project (3 coders) lasting 3 months, where we used D as our primary language. We chose it partly as an experiment, partly because it already had bindings for SDL and some other tools we were using, and mostly for the benefits is appeared to have over C++.
We loved using it. It was quick to learn and easy to write. Many of it's features proved invaluable, and I miss them having gone back to C++.
However, the following points made our lives more difficult:
There was no good IDE at the time which was a major issue. We ended up making our own by customising Scite. This worked ok, but was not ideal.
There was no debugger at the time. We managed to get WINDBG to work on a hit-or-miss basis, but it was unreliable. Debugging code without a debugger made life hellish at times.
There were 2 standard libraries to choose from at the time (Tango and Phobos). We started with one, switched to the other, and really needed a mixture of features from both (Tangobos!). This caused headaches and some code re-write.
Bindings to other tools not available. In the end we had to switch to DirectX (for reasons I won't get into). There were no bindings for DirectX available so we had to write our own in C++, build it as a .dll and bind to that. This was fairly nasty work and took some time.
Overall, we loved to write D. It made actually writing code easy and was quick to learn. The issues I've mentioned echo the answer that has been accepted for this question - it's the "extra" bits that need addressing in D, the core of it is solid.
I agree that C++ is becoming a dead-end language - and it pains me to say that, after having used it for the last 17 years.
I think D is the rightful successor to C++. From a language perspective it "does all the right things" (even if I don't agree with every minute decision). I think with C and C++ on the decline there is no other systems level language that can really do what they do, while holding itself up in the world of modern languages - except D! Not only does D fill this role - it excels at it! A look at D1.x should be enough to convince you of that - but when you look at D2.0 it blows you away. It is my opinion that there is no other language around today that works as well as D2.0 in bridging the imperative and functional programming paradigms - which is only going to get more significant in coming years.
Lack of mainstream acceptance - or even visibility - as well as large scale, mature, libraries - are an obstacle of course. However I don't think you can write it off because of this. I am convinced that D will grow to become one of the most important languages around within the next few years - and those that are taking it seriously now are going to be well placed to take the lead when that time comes.
I think the difference is going to come about due, in large part, to Andrei Alexandrescu's involvement. That's not to discredit Walter Bright in any way, who has done a momentous job in bring D to the world. But Alexandrescu is an important, and compelling, figure in certainly the C++ community - and there's where most of the potential D switchers are going to come from. And he has also made a significant and important contribution to D2.0 in its support for functional programming.
It may still turn out that D is doomed to be the Betamax of systems level languages - but my money is on it turning around within the next two years.
I like that D is the work of a genius, primarily one mind - Walter Bright, whose Zortech compiler was fantastic in its day.
In contrast C++ is too much design by committee, even if Bjarne is an influence. Too many add-on features and weird new syntax. This difference reflects in the ease of learning and ease of everyday use, fewer bugs.
The more coherent languages lead to better productivity and programmer joy - but this is subjective and arguable! (i guess i should vote my own answer down)
D is a good language and decently popular, but like all languages, it is just another tool. Which tool to use depends on the kind of person you are, how you think, the environment you are working in, what restrictions of the languages apply the the program, and most importantly, the program itself. If you have the time, I would definitely recommend learning D. Worst case scenario, you will never use it. More likely you will learn what aspects of it you like the most, and under what conditions it shines brightest, and take advantage of that for when making new programs.
I would recommend looking at the D comparison chart to see what the features are for the language and see if it sounds right for you.
D language is modern. No language is perfect, and there is no doubt about this. But languages are born to make life easier. Where D language compared to C++ has lot of good features, in terms of complexity. Many other language combination specialty is involved, which helps coders to code faster, with TOP features introduced by other languages. Please see also:
for more details about D and other languages
D vs C++, is the compatibility, where huge C++ languages are involved and requires compatibility with D. D allow already 100% compatibility with C, which is a good win still.
D vs C++, C++ is my opinion very nice language, but its hard to code, and time consuming, requires more and more experience to get success, but D allow to do the same with simplicity
D vs C++, i am not sure if C++ does, but D do allow none type restriction variable assignment using "auto", which is good to have a variable dynamic, when require you can make a strict type
D vs C++, if you have other language experience, you can straight get started with it, it has easy learning road map, and its getting designed by a strong experienced team and company support
D vs C++, the very nice thing i found of D, is the code style, it gives the look and feel exactly the same like C/C++, while coding it reminds i am doing really modern C/C++ which called D
There are lot of more good reason for D language, there is no reason to underestimate any language, its always the user choice.
It really depends on what your needs are - large scale commercial applications written in D do exist on the server side, and for that D (typically using Tango/Mango) is a perfect fit, and you are likely to be able to serve more requests than with any other language/platform.
For more specialized solutions in terms of protocols and interactivity (which many are) you will have more problems finding the needed libraries, and the lack of tools is likely to affect you more.
D is pretty impressive, and Andrei's book about it is well-written. But as others have said, you need the tools and the platform support. GDC may, over time, be the answer to both.
Have you seen this?
"GNU Debugger adds D language support":
http://www.linux.com/news/enterprise/biz-enterprise/358956-gnu-debugger-adds-d-language-support
Also, the digitalmars site has pages discussing interfacing to C and C++ (for those libraries you just can't live without). I wonder if there are any tools that, given a C header file, will take a stab at writing the D prototypes.
Personally I wouldn't at this point push for doing a large project in D, but I would use D for in-house tools, getting experience with it and introducing others to it.
The original question was whether D is a credible alternative to Java and C++. I don't think D and Java are really going to compete much in practice; D competes with C++ and now Go. Other questions address the differences between D and Go, but Go is generally considered easier to use. So I suspect that the future of D depends a lot on how much room there is for it to breathe between C++, the current king of the hill, and Go, the much easier alternative that has Google's backing.
UPDATE: I just discovered that my favorite chapter of Andrei's book, the one on concurrency, is available for free online. Definitely worth a read!
And here's a loooong discussion about the relative merits/objectives/approaches of Go and D.
It looks like the question has been answered. D is the better language compared with C++.
The question of whether for practical purposes D has better infrastructure around is secondary.
In short if they are both brand new languages without any support around them D is the better language, ergo it is the better language.
As a language, I always felt that D is closer to C# than C++. Not in features and libraries, but in "feeling". It's much cleaner,nicer ... fun (than C++).
IMHO the biggest obstacle in becoming a credible alternative is tools,IDE and debugger. If D overcomes some obstacles of widespread usage/adoption, more tools and libraries will manifest. (I myself will return to D, if there will be an usable IDE and debugger.)
Works great for my own pet projects. I'd use it for employers' projects but for not knowing how hard it would be for them to find someone to take over the source after i move on. There are no technical reasons to avoid it, at least on the supported platforms. (knock on wood)
One approach is to search for jobs in your area. Find the jobs you would like to do and see what skills they are asking for. If they are asking for C++ or Ruby or Oracle or D, then that is the skill which is mostly to help you to get the job you want.
It looks like a very well designed language; much better than C - C++ - Objective C.
I can live without an IDE or a debugger for a while, but not without a good, documented library for D 2.0.
I'll check back in 6 months...
I've had little exp. with java and since now i've worked with c++. what makes this one more special and preferred?
Moreover I would like to know about the use of System.in classes and parseInt classes.
Java is vastly easier to work with, especially when developing large programs.
Debugging: Java generates nice Stacktraces
Stability: You can catch every exception
Development Speed: you need no linker (which can take many minutes in C++); with a modern IDE (e.g. eclipse) you can edit code in-place while the program is running
Garbage Collection and run-time type safety eliminate whole classes of errors
really good free (as in beer) IDEs
In theory (and sometimes in reality) Java programs also run on multiple platforms, "write once - debug, er, run everywhere" type of thing. That makes it very useful for a variety of projects.
In my personal experience, while learning Java shortly after being introduced to C++, Java seemed simpler and easier to learn and understand, hence more productive, as was said before. While program structure and syntax is very similar, there is no need to worry about pointers and other potentially dangerous language features.
This is really very broad and I think these are really 2 or 3 different questions. I'll address the first one very briefly. Java utilizes garbage collection, or autmatic memory management. That is, arguably, the biggest difference between it from a language like C++. There are clearly some potential for increase in productivity in that you don't have to worry as much about memory, although in reality you do need to pay attention to your references. Perhaps you could refine your question a bit.
Java works in browsers! (Milpa for example). You can say Flash too, but with Java you can leverage the numerous classes coming with it (another advantage over C++, even if both languages has a good set of free libraries on the Net) and your knowledge of the language.
As said, Java is supported on many platforms with minimal adjustments, with a fast, efficient VM, from big servers to mobile phones.
OO support is arguably better designed, avoiding mistakes done in C++. Somehow, C# is to Java what Java is to C++ ^_^ (I won't argue on this, I don't know C# enough actually, it is just an historical point).
In the same spirit, Java is slightly more abstract, avoiding pointers, manual memory management and some other low level stuff.
That doesn't mean than one is better than the other, STL helps C++ for some of the issues above, etc.
I am not sure how to answer the last sentence, these are object and method respectively, not classes.
I never used System.in yet, I suppose it is usable if you feed the Java program with < or | on the command line. And parseInt is a static method of Integer class.
The language features have already been mentioned (GC, reflection etc.). But there is another major difference: Libraries. I know there is the STL and Boost and all kinds of libraries out there, but they are not all of a piece, they all feel different. Often you are forced to use all kinds of C-APIs (e.g. threading or sockets, just to mention two things). All the C++ evangelists will now jump in and tell about some kind of cool OO-socket or OO-threading library, but they are not part of the STL. They should be. Its almost 2009 and everything is networked and multithreaded. This ought to be part of the standard library.
Why is it bad to use those C-APIs? Because it is hard to use them in an object oriented programm. Try using Win32's CreateThread() with the listener-pattern (C#-users: read "delegates").
For a "rich client application", where performance is not a big deal, I would always use Java or C#. If I need raw speed (think signal processing or embedded applications), I would rather use C instead of C++.
BTW: I have used all four languages (C, C++, Java, C#) for a long time.
If you like to program really the object oriented way, then you need to go from C++ to Java. One of the problems with C++ is that most programmers actually use it as C and don't exploit all its OO features. Java is here stricter.
With C++ you're programming "on the metal", whereas with Java you're programming towards a virtual machine. The Java software stack all the way down to the VM is constructed to give a highly abstracted programming experience. This is most clearly apparent in the use of datatypes "that just are" (i.e. the programmers need no understanding of how they translate into memory areas), garbage collection "that just works" (the programmers don't have to deal with allocation and deallocation issues) and the ubiquity of exceptions for error handling and propagation. Pointers are not part of Java, the system takes care of where and how things are allocated.
From this, you might see that the design philosophy of Java is very different from C++: Java tries to enforce that the programmer should stick to certain ways of working which are considered to be safe and to make programming easier. Some people hate this aspect of Java, other people love it.
It really depends on what you're trying to do.
For a lot of higher level functionality where optimal performance may not matter, Java is easier and more reliable to use. For example, garbage collection, array checking, etc. It's also sandboxed, of course.
For me, another major benefit of Java is the use of reflection and of run time class loading. I write a lot of plugins within pluggable architectures, and can ensure I can add more new classes to a running program on any platform. Last time I tried to do that in C++, I had to mess with DLLs and COM.