Difference between C and Java languages ​​(excerpt)

xiaoxiao2021-03-06  178

Java has no pre-regulator

Java does not include a pre-processor and does not define any similar # define, # include, and #ifdef pseudo directive. Constants definitions are replaced using the Static Final field in Java. There is no macro definition in Java, but advanced compiler technology and inline have made them less important. Java does not require the #include pseudo directive because Java has no header files. The Java class file includes API and class execution processes, and the compiler reads information from the class file when necessary. Java lacks any form of conditional compilation, but her transplantability of her crossing means that this feature is not necessary.

No global variable

Java defines a very neat namespace. Incontonate classes, classes include fields and methods, and the method includes local variables. However, there is no global variable in Java, so there is no name conflict between these variables.

Clearly defined basic data type size

All basic data types in Java have defined size. In C, SHORT, INT, and long data types are dependent on their implementation platform, this feature obviously hinders their portability.

No pointer

Java classes and arrays are reference types, and reference to the references to the objects and arrays are similar to the pointer in C, however, the pointers in the C are different, and the references in JACA are completely opaque, there is no way to convert a reference to a basic Data types, and one reference cannot be added or decreased. There is no similarity in Java, similar to * or-> reference operators, or SIZEOF operators, pointers are an important reason for the program error, eliminating them will simplify this language and make Java programs more strong and Safety

Useless storage unit collection

The Java virtual machine performs the useless storage unit collection, so that the Java programmer does not have to clearly manage the memory used by all objects and arrays. This feature eliminates the common program error of another allocation, and almost eliminates memory leaks in the Java program.

No goto statement

Java does not support GOTO statements unless defined in a clear environment, using a GOTO statement is often considered poor programming habits, Java adds exception handling and tag statements Break and Continue to replace stream control statements provided by C language. Instead of GOTO statement

Variables can be declared everywhere

c requires a local variable statement to be placed at the beginning of the method or block, but Java allows the statement to appear everywhere. Noth of programmers, many programmers still like to set all the variable declarations and put the beginning of the method.

Forward reference

The Java compiler is smart than the C compiler because it allows you to call it before defining methods, which do not have to declare them in a header file before defining a function in a program file. C has this requirement.

Method

Java programs can define multiple methods using the same name, and the conditions are the parameter lists of these methods.

No struct and union type

Java does not support C's type Struct and Union, but Java's Class's Class is designed as an enhanced structure.

No enumeration type

c Keywords ENUM is used to define a fixed set of fixed sets, Java does not support this keyword, which is amazing phenomenon for strong types like Java, but uses object constants Can simulate this feature

Omnipotent field

c You can specify that the number of each field of the STRUCT structure is used, and Java does not support this (unusual) function.

No Typedef

c Use Keyword TypeDef to define an alias for the type, Java does not support this keyword, because Java does not have a pointer, more simple than the name mode of C, so many common usage in Typedef is unnecessary in Java.

None way

c You can store the address of a function in a variable and pass this function pointer to other functions. For Java's method, you cannot do this, but the object to deliver a particular interface can usually achieve a similar effect. And the Java method can be represented and called by java.lang.reflect.Method object

No variable length parameter list

Java does not allow methods for defining the number of parameters, such as PRINTF (). Although this function can be simulated by method overloading, there is no universal method to replace this feature.

转载请注明原文地址:https://www.9cbs.com/read-128580.html

New Post(0)