Hello Guys,

I am Confused between the two languages Java and C++ that Which is the better Language to learn?

What do You Guys Think about These languages and Can You make difference between these Languages Guys?

Recommended Answers

All 7 Replies

There's no good answer to this question without a significant amount of context.

This is a dangerous question, things can easily escalate into a flame war.

It is very difficult to answer this question without knowing the specific kinds of differences you want to know about. There are countless technical and application differences between the two languages. You should probably start by reading both wiki entries, C++ and Java.

Here are some of the broad strokes (I'll try not to sound too much in favor of C++):

Main goals of the language:
C++: Performance and robustness.
Java: Safety and portability.

Syntax and style:
C++: Syntax is based off of C, with additional keywords for the plethora of additional features it has. Style varies, usually with the paradigm being used.
Java: Syntax is based off of C with most object-oriented syntax borrowed or heavily inspired from C++. Style is quite uniform, the Java-style is the de-facto standard style for "pure" object-oriented programming.

Typical running environment:
C++: Compiled to native machine code, runs as a native program on the target architecture (e.g., x86), must be recompiled for any different-enough platform (majorly different operating systems or architecture). Target platforms are anything from micro-controllers to super-computers and server farms.
Java: Compiled to bytecode (a kind of pseudo machine code), runs inside a virtual machine (Java Virtual Machine, or JVM), one Java "executable" can run on any platform (i.e., that is running the virtual machine). Target platforms are mostly consumer platforms (PCs, smart-phones, etc.) and servers (server-client applications).

Programming paradigm:
C++: Multi-paradigm language, the main "imperative" paradigms are procedural programming, object-oriented programming, generic programming and template meta-programming, which are generally mixed together (it's hard to say in which proportion, because it varies a lot between libraries and application domains). Declarative paradigms are also commonplace.
Java: Vowed as an Object-Oriented Programming (OOP) language, because the language features and community of developers both strongly favor object-oriented programming as the paradigm of choice (pretty much, exclusively "pure" OOP). However, procedural programming is, in essence, also very common (although somewhat clumsy, syntactically). Declarative paradigms are also possible, but not very common, AFAIK.

Variables' semantics:
C++: All variables are objects (literally speaking) residing in the memory of the scope in which they are declared. Objects are statically-typed with deterministic life-times. To refer indirectly to an object (i.e., "point to" an object), one must explicitly use either a reference or a pointer variable. This overall behavior is called "value-semantics".
Java: All variables are references to objects. All objects are dynamically-typed with stochastic life-times (i.e., the virtual machine handles allocations and deallocations in any way it sees fit, which cannot be predicted, hence, "stochastic" life-times). All variables are references to objects and thus, explicit pointers or references do not exist. This overall behavior is called "reference-semantics".

Resource management:
C++: Resources (dynamic memory, opened files, network connections, etc.) are commonly tied directly to automatic objects, and thus, allocation and deallocation of resources happen deterministically and automatically. However, it is the responsibility of the library-programmers to write (correctly) the classes that handle "raw" resources, users of that library are not burdened with that though.
Java: Dynamic memory (which is any memory in Java) is handled by a garbage collector which ensures that all objects no longer being used get deleted and their memory freed. All other resources in Java are handled in a pseudo-procedural fashion (similar to C-style resource handling), it is entirely the responsibility of the end-user (programmer) of a resource to handle it correctly.

Standard libraries:
C++: The standard library is composed of legacy C libraries (very basic) and a number of generic components. The C++ standard library is designed to be minimalist in order to be able to run on any platform (i.e., it's a "system" programming language) with only very basic features like file I/O and timing. The libraries provide generic algorithmic building-blocks and data structures. Recently, the standard library was extended considerably, now includes multi-threading, more sophisticated timing functions, some advanced numerical analysis functions, etc. But still, requirements on the system features are minimal (file IO and a clock (and now, multi-threading as well)). Evidently, it does not include any graphical user interfaces, network connections, image loading/saving, and so on, all of these things must be done with additional "external" libraries (either the OS's system libraries, or other special-purpose libraries).
Java: The standard library in Java is very extensive and covers a plethora of features. Given that Java provides only very difficult access to platform-specific APIs, it must provide a standard library that includes the super-set of all features that most (desktop) platforms have in common. Additionally, Java's standard library includes a large amount of utility functions and classes. The richness of Java standard library is by far Java's strongest selling point. The only drawback is that it limits its application to feature-rich, capable platforms (i.e., desktops, laptops, tablets, smart-phones, etc.), and applications to smaller devices are harder or require special Java distributions with only the essential parts of the standard library.

Conclusion:
There is no doubt that C++ and Java are two fundamentally different languages. People tend to lump them in a similar category only because they are in the same syntax "family" (and they can sometimes be mistaken from one-another, by an untrained eye, of course). But these two languages are very hard to compare, in the sense of "which is best", because they are so radically different: different aims, different philosophies, different application areas, etc.

You can choose any one..it actually depends on your needs and requirements i.e for what purpose you want to learn any of the language.
Both of these languages work on different concepts.
Well, both are object oriented but java is purely object oriented.

GO with your interest , because even if you choose it with the industries importantace you have to be more interested to go heights in your career

these r two languages of computer so i think u must go wd both of them

As an additional plug for Java (though my heart belongs to C++), you can write wrappers around native libraries to give Java access to them.

For example, the popular game Minecraft is written in Java, but includes hardware-accelerated OpenGL libraries which are only available natively. Wrappers were written for the OpenGL libs so that Java programs could use them.

I like to say that Java is C++ with training wheels, and a 1 speed transmission... :-) For whatever it's worth, I do professional systems development with both languages, but for speed and efficiency, C++ wins hand's down. That said, Java has a LOT of support for stuff that would be a much more difficult to incorporate into C++ programs.

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.