Six main programming languages (C, C + +, Python, JavaScript, PHP, Java) features comparison

Source: Internet
Author: User
Tags array definition class definition constant definition function definition garbage collection

Over the years I have learned six programming languages, some people will say that linguistics to the end of the same. In fact, it can be said, or not to say so. Although the expression ability of each language is coincident mostly, but the grammatical manifestation is different, but because of the historical development reason, each language has formed own support environment, therefore has its main application scope.

C, C + +, Python and Java four are general-purpose programming languages, JavaScript and PHP are the specialized programming languages for web environments. C language because of its underlying operating characteristics and historical accumulation, in the embedded field is a well-deserved king; C + + is a complex language that supports the broadest programming paradigm, which has not been well developed over the years and currently has a niche in the server background and gaming arena; Python, as a flexible and lightweight general-purpose scripting language, The use of a wide range, from the application software to the Web development has its shadow, because of its interpretation of the characteristics of the language, more suitable for lightweight or prototype development; The JavaScript language is the mainstream of Web front-end development because it is a browser-built scripting language, in recent years due to Google's V8 engine open source A JavaScript background development framework such as Node.js has been developed to extend JavaScript's application domain to the web background; php, as a simple Web server background scripting language, has the greatest usage in Web sites around the world; Java, due to its cross-platform portability, is large in the field of web development The splendor, especially in enterprise-level Web development, and as Android is used to develop applications in Java, is becoming more widely used as Android grows.

To clarify the differences between the main grammatical characteristics of different languages, we can better apply the appropriate programming language in the appropriate field or scene to meet the needs we face. These six languages are developed from the C language, so their syntax is more like C language, I have a comparison of the main grammatical characteristics of each language.

1. Constant definition

C: #define TEST 0

C + +: #define TEST 0

Or

Const TEST = 0;

Python:test = 0

JavaScript: Not supported

Php:define (' Test ', 1);

java:final int test = 0;

Analysis: JavaScript does not support constant, C, C + + all use unique predefined macros, PHP with a special define syntax, the rest are used to define invariant variables.

2. Variable definition

C:int test = 0;

C++:int test = 0;

Python:test = 0

Javascript:val test = 0;

PHP: $test = 0;

Java:int test = 0;

Analysis: This is the most basic support.

3. Function definition

C:int Test (int param) {}

C++:int Test (int param) {}

Python:def Test (param):

Javascript:function Test (param) {}

Php:function Test ($param) {}

Java:public class test{

public int test (int param) {}}

Analysis: This is also the most basic, but Java is more special, do not support the definition of functions outside the class.

4, class definition (including inheritance)

C: Not supported

C++:class Test2:public test1{}

Python:class test2 (test1):

Javascript:function test2 () {}

Test2.prototype =inherit (test1.prototype) {}

Php:class test2 Extend test1{}

Java:class Test2 extends test1{}

Analysis: C Because the traditional process-oriented language does not support classes, others are supported, but JavaScript's class model is more special, the function as a class to use.

5. Object definition

C: Not supported

C++:test2 obj = new Test2 ();

Python:obj = Test2 ()

Javascript:var obj = new Test2 ();

PHP: $obj = new Test2 ();

Java:test2 obj = new Test2 ();

Analysis: In addition to c other languages are through the new one object.

6. Array definition

C:int a[] = {1, 2, 3};

C++:int a[] = {1, 2, 3};

Python:a = [1, 2, 3]

Javascript:var a = [1, 2, 3];

PHP: $a = Array ("1", "2", "3");

Java:int a[] = {1, 2, 3};

Analysis: Arrays are the basic features of language, all supported, except that PHP is done by a syntax similar to a function call.

7, conditional statement

C:if (Test > 0) {}

else if (test < 0) {}

else{}

C++:if (Test > 0) {}

else if (test < 0) {}

else{}

Python:if Test > 0:

Elif Test < 0:

Else

Javascript:if (Test > 0) {}

else if (test < 0) {}

else{}

Php:if ($test > 0) {}

ElseIf ($test < 0) {}

else{}

Java:if (Test > 0) {}

else if (test < 0) {}

else{}

Analysis: This is the most basic statement, are supported.

8. Circular statements

C:for (idx=0; idx<num; idx++) {}

C++:for (idx=0; idx<num; idx++) {}

Python:for idx in range (1,10):

Javascript:for (var idx=0; idx<num; idx++) {}

Php:for ($idx =0; $idx < $num; $idx + +) {}

Java:for (idx=0; idx<num; idx++) {}

Analysis: This is also the basic statement, are supported.

9, the foreach statement

C: Not supported

C + +: not supported

Python:for I in A:

Or

For key in D:

D[key]

Javascript:for (i in a) {}

Php:foreach ($a as $i) {}

java:for (int i:a) {}

Analysis: foreach is a variant of the loop statement, in the operation of the order container is very useful, you can see C and C + + is not supported, the other language built-in support.

10. Print Statements

c:printf ("Test:%d", Val);

c++:cout<< "Test:" <<val<<endl;

Python:print "Test:" +val

JavaScript: Not supported

Php:echo "test: $val";

Java:System.out.println ("Test:" +val);

Analysis: Printing is the supporting library of the environment in which the language is run, except for JavaScript, because JavaScript is used to manipulate the DOM tree, so there is no need to support it without its own output window.

11. String definition

C:char test[] = {"HelloWorld"};

c++:string test = "HelloWorld";

Python:test = "HelloWorld"

Javascript:var test = "HelloWorld";

PHP: $test = "HelloWorld";

java:string test = "HelloWorld";

Analysis: This is supported, where C + +, Java is a standard library to the reality.

12. Strings String Connection

C:test = strcat (test1, test2);

C++:test = Test1 + test2; (STL library)

Python:test = test1 + test2

Javascript:var test = test1 + test2;

PHP: $test = $test 1. = $test 2;

Java:test = test1 + test2;

Analysis: Very useful features, in addition to C is the use of standard library functions to implement, the other is the language built-in support.

13, String segmentation

C: Not supported

C++:TEST.SUBSTR (3, 8);

Python:test[3:8]

JavaScript:test.slice (3, 5);

Php:substr ($test, 3, 5);

Java:test.substring (3, 8);

Analysis: Commonly used functions, C does not support, Python is language built-in support, the rest rely on the library to complete.

14. String Regular Expressions

C: Not supported

C + +: not supported

Python:test.replace ("Test1", "test2")

JavaScript:test.replace (/test1/gi, "test2");

Php:str_replace ($test, "Test1", "test2");

Java:test.replaceAll ("Test1", "test2");

Analysis: Commonly used functions, but C, C + + does not support, others have a standard library to support.

15. Built-in container type

C: Arrays

C + +: arrays

Vector of sequential containers

Associative container Pair mapset

Python: List/tuple

Dictionary

JavaScript: Arrays

Object

PHP: Arrays (including associative arrays)

Java: Arrays

Sequence Collection

Map Table Map

Analysis: c The simplest only supports arrays, others support containers, but mainly the sequence of containers and associated containers two major categories.

16. Annotation Mode

c:/* *

c++://

python:#

javascript:/* *

//

php:/* *

//

#

java:/* *

//

Analysis: About/**/,//, #三种方式, the respective support situation is different.

17, multithreading support

C: Support

C + +: Support

Python: Support

JavaScript: Not supported

PHP: Not supported

Java: Support

Analysis: All four general-purpose programming languages are supported and are not supported by both specialized programming languages.

18. Socket Support

C: Support

C + +: Support

Python: Support

JavaScript: Not supported

PHP: Support

Java: Support

Analysis: It is supported in addition to JavaScript, which is also determined by the application domain limitations of JavaScript.

19. Garbage collection mechanism

C: Not supported

C + +: not supported

Python: Support

JavaScript: Support

PHP: Support

Java: Support

Analysis: This is an important mechanism of modern language, C and C + + is not supported, the others are supported.

20, the introduction of other documents in the function

C:export int test ();

C++:export int test ();

Python:from Test Import *

Javascript:<script language= ' javascript ' src= ' test.js ' charset= ' utf-8 ' ></script>

Php:require_once (' test.php ');

Or

Include_once (' test.php ');

Java:import java.util.test.*;

Analysis: All support, C and C + + with Export,python and Java using Import,javascript to rely on HTML script, PHP with its own function calls.

21. Execute the string as an instruction

C: Not supported

C + +: not supported

Python:eval ("port=5060")

Javascript:eval ("port=5060;");

Php:eval ("port=5060;");

java:porcess proc = new Processbuilder ("Test"). Start ();

Analysis: A very useful dynamic language features, C and C + + are not supported, Java to class library to support, other languages built in the Eval keyword to support.

Finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.