Java and C ++ have what difference does it make?

Java and C ++ have what difference does it make? May be interested in the burgeoning software development friends, Java would ask good or C ++, learn that good? Both languages ​​What is the difference? So why are so many people? Today we take a look at the difference between Java and C ++ have what?

  1. pointer
  JAVA language so that programmers can not find the pointer to directly access memory, no pointers, and adds automatic memory management functions, effectively preventing the c / c ++ language pointer operational errors, such as system field guide caused by the crash. But it does not mean that there is no pointer JAVA virtual machine inside or use a pointer, but outsiders can not use it. This facilitates secure Java programs.

  2. Multiple inheritance
  c ++ supports multiple inheritance, which is a feature of c ++, which allows multiple parent classes derive a class. Although multiple inheritance function is very strong, but the use of complex and will cause a lot of trouble, compiler, it is not easy to achieve. Java does not support multiple inheritance, but allows a class to inherit more than one interface (extends + implement), to achieve a c ++ multiple inheritance function, but also to avoid bringing multiple inheritance implementation c ++ in a lot of inconvenience.

  3. Data Types classes
  Java is a fully object-oriented languages, functions and variables portion must be part of a class. In addition to basic data types, as are the rest of the class object, including arrays. Object and method for combining data, encapsulate them in the class, each object can be realized so that their characteristics and behavior. And c ++ allows to define the global variables and functions. In addition, Java canceled in c / c ++ in structures and unions, eliminating unnecessary trouble.

  4. Automatic memory management
  Java program, all objects are new operator based on the memory stack, this operator is similar to c ++ new operator. The following is a statement by the establishment of a class object Read, and then call the object's methods work:

  Readr=newRead();

  r.work();

  Statement Readr = newRead (); Read establish an instance of the structure on the stack. Java automatically useless memory recovery operation, the programmer does not need to be removed. And c ++ must release the memory resources used by the shell program, an increase of negative throwing program designers. When Java, when an object is not to be reused, memory garbage collector it will be tagged to show deleted. JAVA in memory recovery program is useless threads run in the background, use of free time to work.

  The operator overloading
  Java does not support operator overloading. Operator overloading is considered to be a prominent feature of c ++, Java, although in general class can achieve this functionality, but the ease of operator overloading are still missing a lot. Java language does not support operator overloading is to maintain the Java language as simple as possible.

  6. The pre-processing functions
  Java does not support pre-processing. c / c ++ compiler has a pre-programmed course of Chak stage, known as the preprocessor. Preprocessor provides convenience for developers, but it increases the complexity of Ding compiled. JAVA virtual machine does not pre-processor, but it provides the import statement (import) and c ++ preprocessor functionality is similar.

  7.Java does not support the default function parameters, and c ++ support
  in c, the organizing code in a function, the function can access the global variables program. c ++ adds class, providing class algorithm, which is a function of the type connected, c ++ class methods with the Java class methods are very similar, however, because the c ++ still supports c, we can not stop c ++ developers to use the function, the results of functions and methods mix makes the program a bit confusing.

  Java does not function as a purer than c ++ language, object-oriented, Java developers to force all routines included in the class, in fact, the method may be implemented by routines encourages developers to better organize coding.

  8 string
  c and c ++ does not support the string variable, using the Null terminator string representing the end of the c and c ++ program in Java class object is a string (strinR and stringBuffer) implemented, these classes are objects the core of the Java language to achieve string class object has the following advantages:

  (1) method for establishing access strings and string element in the entire system is the same;

  (2) J3 male string class is defined as part of the Java language, rather than as an extension of the external portion;

  Ullage (3) Java runtime execution string, can help eliminate some of the errors that occur when running;

  (4) can be connected with a string to a "ten."

  9 "goto statement"
  "horrible" goto statement is c and c ++ the "relic", which is technically legitimate part of the language, references goto statement caused confusion in program structure, easy to understand, to be used for sub-goto statement unconditionally jump subroutine structure and multi-branch technology. Given the extensive grounds with, Java does not provide a goto statement, although it specifies goto as a keyword, but it does not support the use of the program simple and easy to read.

  l0. Type Conversion

  Sometimes implicit conversion of data types in c and c ++ in, which involves the automatic mandatory conversion issue. For example, in c ++ may be a floating point value to an integer variable, and remove the mantissa. Java does not support automatic casts in c ++, if required, must be cast by the program explicitly.

  11. Abnormal

  JAVA abnormal mechanism for capturing exceptions, enhance system fault tolerance

  try {// possible exception code

  }catch(exceptionTypename){

  //deal with

  }

  ExceptionType which represents the type of exception. The C ++ is not so convenient mechanism.

  to sum up:

  1, C ++ has the advantage that as a compiled language with the efficiency and generic object-oriented features combine disadvantage is that too complicated gorgeous, tend to encourage the process overly complex designs.

  2, we can say that in addition to the system programming and high efficiency requirements of the program, Java C ++ is better than in most areas.

071204.jpg

  See above for an analysis of the difference between Java and C ++, I believe we have to understand that software developers learn the language more suited to the current development.

  Tips:

  1, if you are reading this article have any questions or concerns please contact our professional teachers help you answer.

  2, much to remember: from beginning to end, practice is the process of learning technologies in an extremely important part. Out of practice, it is bad science technology!

Guess you like

Origin blog.51cto.com/14512197/2446259