A Brief Analysis of the differences between Java program and C language

  • 2020-06-19 10:14:42
  • OfStack

Although there are similarities between Java and C languages, there are also definite differences between them. Java program simple is a kind of object-oriented, distributed, interpretation, robust, secure, structure neutral, portable, high-performance, multithreaded, dynamic language it is object oriented and C is process oriented, this is the biggest different, for we studied C language Java arguably simpler programming language.

In Java, all variables must be declared before they can be used.

There can be several classes in Java but there is only one public, and at least one main method in a class, otherwise the program cannot run. An C language consists of several functions, among which there must be only one main function of main, and the program execution starts with the main function of main.

* The following illustrates the differences between the two in terms of type, variable and expression.

Type 1.

1) C Language:

1. Character type. 2, integer (short, integer, long). 3. Real type (single precision, double precision, long double precision). 4. Null type.

2) Java Language:

1. Logic. 2. Character type. 3, integer (byte, short, integer, long). 4. Real type (single precision, double precision).

Identifier:

In the Java programming language, an identifier is the name given to a variable, class, or square length method, and it is named as follows:

1) Identifiers may start with a letter, underscore (-), or dollar sign ($), followed by any visible character other than the operator in Java.

2) Identifiers are contiguous strings that cannot be separated by Spaces or tabs.

3) An identifier cannot be a keyword, but it may contain a keyword as part 1 of its name. For example, thisone is a valid identifier, but this is not, because this is an java keyword.

4) The Java language is case-sensitive. For example, A and a, Day and day are two different identifiers

5) The maximum length is not specified for the identifier.

In the C language, an identifier is just a name. The sequence of valid characters used to represent the symbolic constant name, function name, array name, type name, and filename becomes an identifier.

1) It is stipulated in C language that identifiers can only be composed of letters, Numbers and underscores, and the first character must be a letter or underscore.

2) In C language, upper and lower case letters are not equivalent. For example, A and a, Sum and sum respectively represent two different identifiers.

3) In C, identifiers can be keywords.

4) In C language, identifiers can be of any length.

2.

1) Differences in text output:

1) C Language:

The printf statement implements text output, for example: printf (" C language ");

2) Java:

System. out. print(" Java language ");

2) Differences in text keyboard input:

1) C:

The scanf statement implements statement input.

2) Java statement:

1. Use scanner class to achieve keyboard input

Scanner is a new class to JDK1.5, a simple text scanner that USES regular expressions to parse basic types and strings. Such as:


import java.unil.Scanner;
public class ScannerDemo{
 public staticvoid main(String[] args){
 Scanner sc=newScanner(system.in);
 System.out.println( "Please enter 1 Round number, hit enter and end." ) ; 
 intnum=sc.nextInt( "You did 1 A:" +num) ; 
 System.out.println( "Please enter 1 String, hit enter to end." ) ; 
 Strings=sc.next();
 System.out.println( "You did 1 A:" +s);
 Sc.close();
 }
 }

2. Use Console class to achieve keyboard input

In comparison, the Console class is more convenient and flexible in formatting input than the Scanner class.

3. In addition, there are also differences in annotations.

1. C language

C only USES /*...... */ You can complete the comments by including those that require them.

2. There are three annotation languages in Java language:

1) The symbol "//" is used to comment on 1 line, which can be taken up to 1 line alone or placed at the end of the code line.

2) / *... */ is used to comment 1 block of code with /* at the beginning, */ in the middle and */ at the end, in the same way as C.

3) / * *...... */ is the doc annotation specific to Java and intended for use by the javadoc tool.

Supplement: The difference between c and java

Different syntax;

Single file compile time java is faster than C language;

C language can directly operate memory, java can not directly operate;

C can encapsulate dynamic libraries, but java cannot.

C code is not easy to cross platform, java code is easy to cross platform;

C has Pointers, java has no Pointers;

C language can directly operate the serial port, java needs the support of the third party jar package;

C language threads are more flexible, java threads have been packaged;

C language as a separate function, can increase efficiency, java is suitable for web application development;

unix was written in C and java was written in C.

When JAVA did the development of web, there were already a lot of formed framework technologies. There were few C languages and it was very difficult for developers who were not familiar with computer principles to deal with the underlying content.

JAVA has too many open source packages, the C language is available but few, and there are not as many frameworks for a particular business application as java.

Omit 10,000 words below...

C language combined with java language development, this is a bunker, can solve many application problems


Related articles: