C++/about c


dear ralph McArdell

i have the following questions:
what are the main uses of the c/c++ programming language?
what i want to know is what type of jobs can i get with the C/C++ programming language and what would be the differences between learning c/c++ and the java programming language.

is one programming language enough to get a job as a programmer?
would i have more advantages if i learn more than one programming language?

i ask you these questions because i see a lot of syntactic similarities between the c/c++ and java programming language
(for example: both languages use objects, classes, arrays, if, for, while statements)
i think that creating two languages (java and c) with similar syntax and similar uses is pointless, so i believe that there must be a purpose of creating c/c++ and java and i would like to know these differences, and how these differences would affect a programmer looking for a job

thank you very much

C++ is used for many different application types. However managed development environments such as Java and .NET are becoming popular in many areas for which C++ is used.

There are still many jobs that use C++, but also many that require knowledge of Java and/or other languages. You could visit online job sites for your area of the world and see what skills are currently asked for.

You will find that the language is only part of the requirement for a job - the platform (operating systems and machine architectures) are also important as well as middleware (CORBA, COM, SOAP etc..) APIs (Win32, POSIX, etc..) libraries and frameworks (MFC, ATL, GTK+, Qt, ACE) and often application or industry sectors - telecoms, banking, financial etc.. As you are presumably staring your career you would be looking for junior positions or graduate hire positions - where the lack of experience is to be expected on the employer's side and training is to be expected on your side.

As to learning more than one programming language - yes do so - many jobs require using more than one language - C or C++ here, some Java or C# there, some shell script or Perl etc.. to glue things together, a bit of SQL to get information into / out of databases, some MS Office VBA or VB.NET to link into MS Office, some installer script over there. Probably some HTML, ASP, PHP, JavaScript etc.. for web work. Oh and you will almost certainly bump into some XML somewhere...

You need the mind set to be able to pick things up as required and to see the best way to put the pieces of a solution together.

As to the supposed similarities between C++ and Java:

C++ is considerable older than Java and has always been designed to be as compatible with C as possible - C being a much simpler language that has no classes and is sometimes described as a high level assembler. Like C, C++ uses a traditional approach: compile each source code unit to an object module then link them all together, together with existing object code in libraries, using a link loader to produce an executable. The object code modules and the executable generally contain native machine instructions for the target processor in a format usable by the intended target system. There are many object / executable file formats, having names like aout, COFF and ELF.

Java (and the MS .NET languages for that matter) are newer and do not usually generate code that can be directly run on the target machine. Instead they require a runtime environment - called the Java Runtime Environment (JRE) which includes a Java Virtual Machine (JVM). For .NET we have the Common Language Infrastructure (CLI) (The MS commercial version of the CLI is called the Common Language Runtime or CLR). A Java compiler will generate Java byte code rather than native machine instructions which are interpreted by the JRE which runs them on a native machine - or the byte code is compiled just in time (JIT) (i.e. when first executed) to native machine instructions. A similar situation exists for .NET.

So whereas with C++ (and C) you do not necessarily need anything else to run an executable with Java (and .NET languages) you require a runtime system to be installed. So you would be able to create low level software with C and C++ such as operating systems etc.. and you have a lot of control over what is done with regards to system resources. In reality most C and C++ code relies at least on the provided language libraries and so at least indirectly on operating system functionality. It has to be asked whether many applications require this level of performance and control?

With languages such as Java and C# that target a managed environment - the JRE or CLI - you have the overhead of the runtime environment. However that environment can provide benefits such as much improved security and some automatic reclamation of system resources such as memory (by using garbage collection techniques) which can simplify development. They also tend to ship with a huge framework of useful classes. For many applications you find these benefits outweigh the overhead of the managed environment.

As to the language features of C++ and Java there are many basic similarities which allows people who come from a C/C++-style language background to not feel to overwhelmed (C# is similar in this respect). On the other hand they vary significantly, here are some of the differences:

- C++ has no direct concept of an interface - but it does allow multiple inheritance of implementation not just for interfaces as is the case for Java.
- C++ allows you to have global objects and stand alone functions that are not a member of any class.
- In C++ you tend to separate the declaration of a function - be it stand alone or a class member function - from its declaration. In Java the member functions are defined in the class definition.
- Java has no pre-processor that processes the source code before the compiler proper sees it.
- C++ has a simple minded way to share declarations and definitions between modules - you place those parts that form the shared interface into a separate file commonly called a header file which is included by those modules that wish to make use of the declared functions and objects and defined types. The include mechanism is part of the source code pre-processor and literally includes the source from the header in the including file at the point of the include directive.
Java uses a predefined file layout to define packages which other modules may then import. Each Java file generally contains a single class definition which includes the definition of all class member functions and data.
- In C++ objects are manipulated by value by default - you have to specify whether you wish to use a reference by adding a & to the type.
- C++ allows you to have pointers to objects that may be modified.
- in C++ new returns a pointer to an object on the heap rather in Java where reference is returned.
- In C++ you have to explicitly delete any object created on the heap. In Java you rely on the garbage collection to reclaim dead object memory.
- Unlike Java, in C++ class objects do _not_ have to be created on the heap - they can be global, local automatic (stack) or local static objects.
- In C++ you have deterministic destruction - when an object is destroyed either explicitly (for heap objects) using delete or implicitly because they went out of scope the destructor for that object will be called. In Java you have to wait until the garbage collector reaps the dead object and even then a destructor may not be called.
- In C++ object types (classes) are not automatically derived from some arbitrary super object type as they are in Java (Object).
- In C++ the size of the primitive data types is not fixed and may vary between implementations. This is due to the tighter relationship to the underlying machine that C++ has. If a C++ compiler targets some weird DSP chip that only has 24 bit registers then all its integer types are likely to be 24 bits in size. C++ also has signed and unsigned integer types. Java on the other hand mandates the size of all its primitive data types. Any discrepancy with the underlying machine is handled by the JRE implementation for that machine.
- Array types in Java are reference types - i.e. they have to be created on the heap - and they have some attributes such as length. C++ inherited its built in arrays from C and they just allocate an area of memory large enough to contain the required number of elements. They have no attributes. They do not have to be created on the heap. Using the name of an array in C++ in an expression (as in C) is equivalent to using the address of its first (zero) element.
- In Java String looks like a primitive type but is really a class. In C++ they are just arrays of characters terminated with a zero character (also from C). C++ now has a separate string class type provided by the C++ standard library.
- In Java type casts look more like the old C casts than the new C++ cast operators ( such as static_cast<T>(v) ).
- C++ allows operators to be overloaded for class types which allows producing code using user defined types that can look like using built in types - a complex number type is the usual example. Java has no such facility other than the predefined + operator used for string concatenation.
- Unlike Java, C++ has no thread or synchronisation primitives. When required it is usual to use the underlying operating system facilities or a facility such as a library that wraps up such facilities.
- Java misses a few C and C++ features such as bit fields, enumerated types and type aliases (typedef). It also has no goto statement!
- C++ misses a few Java features such as super and final.
- Java and C++ class member access differ. C++ has public, private, and protected. Java adds package access.
- Java has no type and function templates (although it now has generics which give some (very) limited template like facilities).
- C++ and C are defined by ISO/ANSI standards. Java is a propriety product controlled by Sun Microsystems.

And that is just a quick list!  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.


©2017 About.com. All rights reserved.