The difference between C language and Java

Source: Internet
Author: User
Tags naming convention

the same place:1 , syntax similar: because Java can be considered from C + + development, so Java and C language syntax comparison is similar2. Proficiency in programming is the mastery of the Language program library:
to some extent, the programming language is composed of syntax and corresponding library, Java has its own class library, C language has a standard library. The so-called programming is to use and syntax to invoke and assemble functions in the library. different places: 1. Memory Management  
in Java, basically do not consider the memory of the problem, if you want to use an object, the new one can, the process is behind the JRE for the object classification of a certain memory, when the JRE found that you no longer use this object, he will automatically reclaim memory, that is, you just borrow things, do not return, Because with someone when your valet, you do not use the time to return the things, but this process is still there, but it is only the JRE.
but C is different, if you want to use, you can use malloc and other methods to apply for memory, when you are finished, because there is no valet, you need to return this piece of memory, that is, call the free method to complete the task. Because of the need to explicitly return memory, when a function needs to return a piece of memory to the caller, the problem is more complicated than the object-oriented and the memory-recycling Java is so intuitive. For this problem, there are several solutions in C language:
(1) Allocate the memory in the caller first, and pass it as a parameter into the called function
(2) allocated in the called function, freed in the caller after use
(3) using the static variable in the called function, you can return the variable
2. Object-oriented  
Java's object-oriented features are obvious, while C is an authentic, structured language. There is a string class in Java that can know the length of a string by calling String.Length (), but in C you need to call function strlen (str) to get the length of the string (character array). Because C is not an object-oriented language, there is no concept of this, so when you use a function that is related to something, it takes a lot of time to pass the variable that represents the "thing" as a parameter.
3. Name Space  
Java uses the package to implement namespaces, in the C language, all functions are in the same namespace, that is, there is no namespace, so many programs provide API interface functions have a prefix, such as MySQL Mysql_init (), MySQL _real_connect (), Mysql_real_query (), and so on before the function name Mysql_. 4, in the mode of Operation C: The original C is process-oriented. That is, it is done by line. JAVA: Absolute object-oriented. It's like doing it by module. (add: Of course, C also has a shift to object-oriented mode in C + +, and C #) 5, in the sentence structure C: In China should be regarded as the peak application of programming language. C is like a fully obedient soldier. He does what you ask him to do. You have complete control of him, but you must know him all the way to control him.c inside unique pointers, addresses and so on. And arrays are stored differently than Java.JAVA: User-friendly object-oriented programming language. He can think of everything as a basic object, and then copy and rewrite them. Java to think a bit like a factory, you in the factory first separate a small parts, and then use the wire to connect them together. Assembled into usable things. 6, the use of C: pure C is generally used in the embedded. Write the lowest-level program. Because his language is easiest to connect to hardware. C + +: application software, Web programs can be. Java:j2ee,j2sm,j2me. anything.c Embedded Low-level software operating system various functions Library engine library software core code server-side underlying tools C + + graphics image game client-side desktop software various high-performance client software near the bottom software Java embedded mobile device application software Development Web page Background Logic development part of the desktop program C, Java is actually available in a variety of fields. syntax is different: the compilation time of a single file is faster than the C language, C language can directly manipulate memory, Java can not directly manipulate, C language to encapsulate Dynamic library, Java does not, C language code is not easy cross-platform, Java code Easy cross-platform, C language has pointers, Java does not have pointers, C can directly operate the serial port, Java needs third-party jar package support, C language thread is more flexible, Java threads are already packaged, C language to do a separate function, can increase efficiency, Java for Web application development; Unix is written in C. Java is also written in C language, Java Web Development, there are many formed framework technology, C language is very few, and need to deal with the underlying content, corresponding to the computer is not familiar with the principle of the developer is very difficult; Java's open-source package is too many, C language has but a little, And the framework for a business application domain does not have much Java;

One of the biggest differences between Java and C is the cross-platform. by parsing the Java virtual machine, programs written on Windows or UNIX can be run under other systems, and C is absolutely not. But the C language is the fastest when it comes to dealing with hardware. c comparative Basis, Java is more popular. But 2 people do not have the upper and lower points, one is the originator of the programming language, one is the current popular cross-platform language. Good at different fields, different languages in different situations. However, how to use this language is a test of the programmer. The problem of fish and bear paw, the choice is ultimately only to see yourself. C, C + +, C # are actually three different languagesC + + is an enhanced version of C., adding some new features, such as Object-oriented C + +, which is a language developed by Microsoft for. NET ,just a little bit like the C + + to say the difference, first of all to say contact, C is grandpa, C + + is dad, C # is the grandson of C. This image illustrates the relationship between the three. In terms of time, they first appeared in C, then C + +, and finally C #. C + + is the introduction of object-oriented to solve the software crisis,C # In order to achieve platform unification and Java competition for the product of the market. at present, there are two main methods of development of software development (corresponding language):1, Structured development method: C, Basic, Pascal;2. Object-Oriented development method: C + +, Java, C #, Ruby One, Java encapsulates a lot of classes and interfaces, and these are not in the C language. In fact, in order to improve the development efficiency, Java has emerged, these functions can be implemented in the C language, but to write more code. However, the same program, written in Java, generally runs much slower than the C language. The C language is a process-oriented language, while Java is an object-oriented language. Java, in contrast to the C language, removes the error-prone features such as pointers. In the Java language whitepaper, Java is described as "a simple, object-oriented, distributed, interpreted, robust, secure, structurally neutral, portable, efficient, multithreaded, dynamic languagethird, C language single-use non-extensive integration of high-level language, simple and easy-to-use assembly languages to implement the efficiency of Java Research E-Consumer products platform Internet application base implementation of the language characteristics of the C language development and make the image more self-improvement (security Code migration). Java program is composed of a class, a Java application contains at least one class, extreme, a class can be an empty class, does not contain any property definitions and method declarations. Five, at least one class should contain a method declaration such as public static void main (string[] args), otherwise the program cannot be run. Six, Java cross-platform, both different operating systems can be used by the JVM (Java Virtual machine) to interpret Java programs, and is platform-related, and some of the instructions can only be executed in some operating systems. Java is an interpreted language, and all code is translated into a unified, system-independent bytecode that runs on the JVM, and C is a compiled language, and the code is first converted to system-related intermediate code by the compiler before it can be run. Public indicates that the class can be accessed by other classes, class represents a class for Java, and static means that the main () method is a method that can be used directly, void indicates that the main () method does not return any information to the caller after executing the statements it contains. This is important because the Java programming language is cautious about type checking, including checking that the calling method does return the type of return value declared by these methods. String[] is a declaration of a string array that accepts arguments that are passed to the main () method by the outside world. Eight, Java programs are used for the network. C language security is not as good as java,c language without the Java garbage collection mechanism, the requested space to be released manually. Java is very versatile and can be ported directly across platforms, as long as there is a Java Virtual machine (JVM) installed. In speed, the C language program is better than Java, because Java must run in the environment of the virtual machine, but because the virtual machine, Java to obtain platform-independent, and C-language programs may need to re-modify the compilation to achieve the platform porting, on the other hand, C language than the Java language more "bottom", So you can write a driver like hardware in C, but Java doesn't. the naming convention for Java is that identifiers can begin with a letter, an underscore (-), or a dollar sign ($), followed by any visible character other than the operator in Java. Identifiers are contiguous strings and cannot be separated by tabs and spaces. An identifier cannot be a keyword, but it can contain a keyword as part of its name. The Java language strictly distinguishes the case of identifiers and does not specify the maximum length. 10, the basic Java type has eight kinds, respectively is the logic type, the character type, the byte type, the short integer type, the integer type, the long integer type, the single precision, the double precision. 11. Scanner is a class that implements input by invoking a method that scans the object. Println () method, Ln represents the line break.       

The difference between C language and Java

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.