Job Recruitment Website - Ranking of immigration countries - Why have so many programming languages ??been developed?
Why have so many programming languages ??been developed?
The similarities between C# and JAVA: Since C# and JAVA are both developed based on C++, there are many similarities between the two, as follows:
1. The compilation results of C# and JAVA languages ??are independent of computers and programming languages, and executable files can be executed in a managed execution environment;
2. Both C# and JAVA languages An automatic garbage collection mechanism is adopted;
3. Both C# and JAVA languages ??cancel pointer operations;
4. Neither C# nor JAVA languages ??have header files;
5. Both C# and JAVA languages ??only support single inheritance. To achieve functions similar to multiple inheritance, it must be implemented through interfaces;
6. Classes are derived from the Object class. Class objects are generated through the keyword new;
7. Both C# and JAVA languages ??support threads;
8. Neither C# nor JAVA languages ??have global variables and global functions. and functions belong to a certain class;
9. Both C# and JAVA languages ??support strict checking of array and string boundaries, and boundary overflow will not occur;
10 , C# and JAVA languages ??both use the "." operator, and no longer use the "->" and "::" operators;
11. Both C# and JAVA languages ??use null and bool as keywords;
12. All values ??in C# and JAVA must be initialized before they can be used;
13. If statements in C# and JAVA do not allow integers to be used as judgment conditions ;
14. The try statement block in C# and JAVA languages ??can be followed by a finally statement block.
The differences between C# and JAVA:
Although C# and JAVA have many similarities, since they are high-level programming languages ??developed by two different companies, they are different. Independent of each other,
is a self-contained system, each with some unique characteristics. The differences between C# and JAVA are as follows:
1. Properties
< p> For developers who frequently use rapid development tools such as Delphi or Visual Basic, properties are a very familiar concept.Generally speaking, the value of the attribute can be read through getXXX, and the value of the attribute can be set through setXXX.
Common attribute operation statements in JAVA: foo.setSize(foo.getSize()+1); label.getFont().setBold(true);
Comparison in c# Common property operation statements: foo.size++; label.font.bold=true;
Obviously, the above property setting method is simpler and more readable than JAVA. This fully reflects the simplicity of C#.
JAVA’s definition of attributes: public int getSize(){ return size; } public void setSize(int value){ size=value; }
C#’s definition of attributes has been Simplification: public int Size{ get{ return size; } set{size=value; }}
2. index
C# provides index to add an index to the object, so that Objects are processed in a similar way to arrays. The JAVA language does not support index
The typical way to define index in C# is as follows:
public Story this[int index]
{
get{return stories[index]; }
set{
if(value!=null){
< p> stories[index]=value}
}
3. delegate: can be considered a type-safe, object-oriented function pointer.
C# allows a delegate to access different functions through a name. It implements similar functions to the interface in JAVA, but it is more easy to use than the interface.
4. event
C# provides direct support for events, and it handles events through the delegate and event keywords. The event keyword hides all delegate methods, and the operators "+=" and "-+" allow programmers to freely add or delete time handlers.
5. enum: Enumeration is used to specify a series of objects.
C# defines and uses enumerations through the following statements:
Definition: public enum Direction{North,East,West,South};
Use: Direction wall=Direction.North;
JAVA does not directly support enumerations. If you want to implement functions similar to C#, you must first define a class
public class Direction{
public final static int NORTH=1;
public final static int EAST=2;
public final static int WEST=3;
public final static int SOUTH=4; }
After defining the Direction class, JAVA can use the enumeration by referencing the value in the class:
int wall= Direction.NOTRH;
p>6. foreach statement
C# provides a standard for loop, and also provides a foreach statement (introduced from VB) to loop through the elements in the collection.
The typical processing method of JAVA traversing all elements in a collection is as follows:
while(!collection.isEmpty())
{
Object o=collection.get();
connection.next();
…
}
C# traverses the collection All elements of: foreach(object o in collection){…}
7. Unified data types:
Most high-level programming languages ??have basic data types, such as integers , floating point type, etc. At the same time, in order to better meet actual needs, different data types have different processing methods. Obviously, if the processing of simple data types and the processing of complex data types can be combined and processed in a consistent way , will undoubtedly greatly improve the efficiency of application design and enhance the flexibility of program design.
JAVA language also adopts a separate processing strategy when dealing with basic data types, but provides a series of classes that encapsulate these basic data types based on basic data types, such as: integer (int) It is encapsulated by class Integer, and double precision floating point (double) is encapsulated by class Double.
C# provides a different way from JAVA to achieve unification of data types. In fact, in C#, even a simple data type such as int is implemented internally through a structure Int32. In C#, it can be considered that int is just an alias of the structure Int32. Since the structures in C# also inherit from the Object class, each structure also has the methods defined in the Object class. Therefore, integers can be manipulated in the following ways in C#: int I=5; System.Console. WriteLine(i.ToString());
8. Operator overloading
Through operator overloading, various data types can be manipulated in a more natural way, thus greatly improving the efficiency of the program. Readability and flexibility. The "==" operator in C# is defined in the Object class. The == operator defined in Object obtains the final result by comparing the references of two values. If there is a class related to collections, the ICompar interface must be implemented in such a class. This interface defines a method CompareTo, which returns the comparison result of the two objects. On this basis, each implementation comparison can be further defined. Operators, such as
">", "<", ">=", "<=", etc. In fact, numeric types (int, long, etc.) can directly use these comparison operators, and they all implement the ICompare interface internally.
9. Polymorphism
Virtual methods provide polymorphism support.
Polymorphism means that a derived class can define a method with the same name as the base class. Although both JAVA and C# support polymorphism, there are still certain differences in their specific implementation methods.
In the JAVA language, by default, the object of the base class can directly call the virtual method in the derived class. In the C# language, the base class must call the virtual method in the derived class through virtual Keywords to achieve. At the same time, in the C# language, if a method wants to override the method of the same name in the base class, it must also use the override keyword.
A typical program to implement polymorphism in C# is as follows:
Class B{ public virtual void foo{}}
Class D:B{ public overried void foo(){}} < /p>
The above is just a simple comparison of the similarities and differences between C# and JAVA. In fact, the comparison between the two goes far beyond what is introduced above. To learn these two languages ??well requires a lot of practice. Work, distinguishing the two languages ??in practice
- Related articles
- What are the current visa prices in Thailand and Singapore?
- What are the works of American composer Anderson?
- How to write a summary of vaccination publicity day?
- Do rural residents in Yichun have forestry hukou?
- What are the advantages of high school students studying abroad?
- Where is the way out for environmental specialty? Studying in Britain or Australia. Ask others for advice.
- What policies does macroeconomics have to promote economic growth?
- Physical examination of American immigrant visa in Guangzhou
- Ningxia College Entrance Examination Plus Points Policy
- In the ancient history of China, when did northerners migrate to the south of the Yangtze River for the first time?