The characteristics and application of Java language

Source: Internet
Author: User
Tags goto java se

Java language definition:

    1. Java is an object-oriented programming language that can compose cross-platform applications .
    2. Java technology, with its versatility, efficiency, platform portability and security, is widely used in PCs, data centers, game consoles, science supercomputers, mobile phones, and the Internet, while owning the world's largest developer professional community.
    3. Composition: Java is made up of four aspects: the Java programming language, the syntax. Java file format, which is the suffix of various folders and files. The Java Virtual machine (JVM), the interpreter that processes the *.class file. Java Application Interface (Java API).
    4. Java is divided into three systems, namely Java SE (J2se,java2 Platform standard Edition, Standards edition), Java EE (J2ee,java 2 Platform, Enterprise Edition, Corporate Edition), Java ME (J2me,java 2 Platform micro Edition, mini version).
    5. Java is a well-functioning, general-purpose programming language that can be used to develop reliable and demanding applications.

Advantages:

    1. Pointers : Anyone who has studied C or C + + knows that pointers are important to them, why pointers can support direct memory manipulation, and that direct manipulation can bring about efficiency gains. But any one thing has side effects, The confusion that the pointer brings to the programmer is unparalleled. For a not very strong C programmer, pointers are deadly (and for me, I can hardly write C code). And Java saves us the hassle, or Java completely restricts the direct manipulation of memory, Let programmers have peace of mind to engage in business logic, without having to take care of the piles of memory in their backyard.
    2. Garbage Collection: In fact, garbage collection is also one of the limitations of Java for memory operations, but also greatly frees the programmer's hands and feet. But it is also the presence of a memory nanny that leads Java programmers to almost no concept in memory ... A purely Java programmer's problem with memory leaks is never a concept, because he never has to worry, because in most cases, even if he's too extravagant, it's going to lead to a very obvious flaw in Java, as we'll talk about later. Here, let me say something I think of. In fact, Java does not let the programmer completely worry, his agent is just memory, and other resources of the call and release are still need the programmer to care about, such as databases, such as files. Of course, we can not expect to eat anything out of the box, there is always something to do it yourself.
    3. The true meaning of platform independence lies in the high portability of programs and the ability to migrate smoothly across multiple platforms. This is especially suitable for Web applications.

Disadvantages:

1 Efficiency

Such a problem, along with Java's origins, has plagued our poor Java baby for a long time, though he has been cultivating himself to change the problem after he grew up. But innate is innate, eh ... Let me say what's good for you ...

1.1 Of course, the first is the memory operation limit brings security and the side effect of the same time ....

1.2 Second, is to face the object of a very important characteristics brought about-polymorphic, this thing is womb bring out, who also have no way, and this factor "consequence is very serious" (I will say our Java children themselves with others learned a recruit to solve this problem). But no, C + + does not also claim to face the object, this problem he also has, why do you say me? The argues from Java. Haha, this you are not as good as C + + sleek bar, people's multi-state is the compiler and the implementation of the connection, you are the implementation of the runtime, efficiency problems can be seen in the bar.

Java children think for a long time, think of a trick ... I don't remember when he started this, but he really would, for some non-change program, he let everyone can be precompiled to achieve. Actually, this is what C + + really does. But such a solution masks the ability to create and connect dynamically. It is also necessary to note that such a method is generally used when there are few changes and the performance requirements are particularly high. After all, our hardware should be able to meet this requirement if we are not dealing with large batches of processing and centralized requests.

1. 3 Platform-independent nature brings. Because of the need for platform-independent, so Java is not directly invoke the OS API, Java needs to call its own API to implicitly invoke the OS API, we can imagine this effect. More than one layer of calls, it is inevitable that more than one layer of code needs to load inside the stack. But there is a solution to this problem now ... I am not very good at this aspect, just see some information, contact too little. such as JNI (Java Native Interface)

2 Inverse compilation issues

It's really the first time I've heard of such a problem, oh my God, the thing that didn't touch really. There is only a book to be set up here.

Since Java programs are dynamically connected, references from one class to another are symbolized. In statically connected executable programs, there is just a direct pointer or offset between the classes. Conversely, in a Java class file, a reference to another class clearly indicates the name of the class pointed to by the string. If the reference points to a field, the name and descriptor of the field are described in detail. If a reference is to a member variable, the name and descriptor of the member variable (the return type of the method, the number of method parameters, and the type) are also described in detail.

What does it matter? However, it is said that this can be done by reverse compilation of my original code to get the ... I've been writing for so long. It seems that ... The question of property rights (whistling, rising to the law ...) Sissy, I like it)

3 Thread Scheduling issues

About thread scheduling, to tell the truth, I am learning the operating system, all the threading problems are under Linux with C to do, the reason is the Linux thread API is relatively clear, and I can not stand the windows of those API name constructs. The 2nd is because I think Java is a total process of multi-threading, but the scheduling between the threads is not very clear, compared to a direct call to the operating system of the thread support (although Linux is not particularly good for thread-level support, but after all, there is no package support), I remember the philosopher hunger problem I finally was a Java deployment results, but in the end I was dizzy. These are my personal views, and probably some prejudice, as for others, the book's professional explanation is that Java can only take such a general and loose thread specification in order to support different threading support strategies for multiple systems.

In fact, the advantages and disadvantages are relative, have done a comparison to know, in fact, the advantages and disadvantages sometimes is the same factor brought. It also requires that we look at the dialectical principle of materialism (I just say materialism, no nationality). More often we need to make the right trade off between what we need and the price we need to pay for it. (the word that the operating system teacher likes to say).

Pros and Cons:

    • JAva Advantage, is suitable for team development, software engineering can be relatively standard, this is a difficult to compare the advantages.
    • Java disadvantage, is the architecture of the EE is perfect, the first version of the software can be satisfied, but it is not suitable for the continuous modification of the Internet model. The inadequacy of the Internet Software Engineering management, the continuous tinkering leads to the destruction of the architecture. System updates require a restart of the Web service, which is difficult to accept.

Characteristics:

    • Language Features

The Java programming language is very similar in style to the C, C + + language. Java is a purely object-oriented programming language that inherits the core of the object-oriented technology of C + + language. Java discards features such as the C + + language prone to error pointers (substituted by reference), operator overloading (operator overloading), multiple inheritance (superseded by interfaces), and adds the garbage collector function to reclaim memory space occupied by objects that are no longer referenced. So that programmers no longer have to worry about memory management. In Java 1.5, Java introduced language features such as generic programming (Generic programming), type-safe enumeration, variable-length parameters, and auto-loading/unpacking.

Java differs from the general compilation of the execution computer language and the interpretation of the execution computer language. It first compiles the source code into a binary bytecode (bytecode), and then relies on virtual machines on various platforms to interpret the execution byte code. This enables cross-platform features such as "Compile once, execute everywhere". However, each time the execution of the compiled bytecode takes a certain amount of time, which in some way reduces the efficiency of the Java program running.

    • Key Features
  1. The Java language is simple. The syntax of the Java language is close to the C and C + + languages, making it easy for most programmers to learn and use Java. Java, on the other hand, discards features that are seldom used in C + +, which are difficult to understand and confusing, such as operator overloading, multiple inheritance, and automatic coercion of type conversions. In particular, the Java language does not use pointers and provides automatic scrap collection, which makes it unnecessary for programmers to worry about memory management.
  2. The Java language is object-oriented. The Java language provides primitives such as classes, interfaces, and inheritance, and for simplicity, only single inheritance between classes is supported, but multiple inheritance between interfaces is supported, and the implementation mechanism between classes and interfaces is supported (the keyword is implements). The Java language fully supports dynamic binding, while the C + + language uses dynamic binding only for virtual functions. In short, the Java language is a purely object-oriented programming language.
  3. The Java language is distributed. The Java language supports the development of Internet applications and has a network application programming interface (Java net) in the basic Java application programming interface, which provides a class library for network application programming, including URLs, URLConnection, sockets, ServerSocket and so on. The RMI (remote method Activation) Mechanism of Java is also an important tool for developing distributed applications.
  4. The Java language is robust. Java's strong typing mechanism, exception handling, and automatic collection of scrap are important guarantees of Java program robustness. Discarding pointers is a wise choice for Java. Java's security check mechanism makes Java more robust.
  5. The Java language is secure. Java is typically used in a network environment, and Java provides a security mechanism to prevent malicious code from attacking. In addition to many of the security features of the Java language, Java has a security mechanism (class ClassLoader) for classes that are downloaded over the network, such as assigning different namespaces to prevent the substitution of locally named classes, byte code checks, and provides security management mechanisms (class SecurityManager) for Java applications to set up Security Sentinel.
  6. The Java language is architecture-neutral. Java programs (files that are suffixed with Java) are compiled into an architecture-neutral bytecode format (a file with a suffix of Class) on the Java platform and can then be run on any system that implements the Java platform. This approach is suitable for heterogeneous network environment and software distribution.
  7. The Java language is portable. This portability comes from architecture neutrality, and Java also strictly specifies the length of each basic data type. Java system itself is also very strong portability, Java compiler is implemented in Java, Java operating environment is implemented with ANSI C.
  8. The Java language is an interpreted type. As mentioned earlier, Java programs are compiled into bytecode format on the Java platform and can then be run on any system that implements the Java platform. At runtime, these bytecode are interpreted by the Java interpreter in the Java platform, and the classes required during execution are loaded into the runtime environment during the join phase.
  9. Java is high-performance. Java is really high-performance compared to those high-level scripting languages that are interpreted. In fact, the speed of Java is getting closer to C + + with the development of JIT (just-in-time) compiler technology.
  10. The Java language is multithreaded. In the Java language, a thread is a special object that must be created by the thread class or its child (grandchild) class. There are usually two ways to create a thread: one is to wrap an object that implements the Runnable interface into a thread using a constructor of type thread (Runnable), and another to derive a subclass from the thread class and override the Run method, and the object created with that subclass is a thread. It is important to note that the thread class has implemented the Runnable interface, so any thread has its run method, and the Run method contains the code that the thread wants to run. The activity of a thread is controlled by a set of methods. The Java language supports simultaneous execution of multiple threads and provides a synchronization mechanism between multithreading (the keyword is synchronized).
  11. The Java language is dynamic. One of the design goals of the Java language is to adapt to dynamically changing environments. The classes required by the Java program can be dynamically loaded into the runtime environment, or they can be loaded into the network to load the required classes. This also facilitates software upgrades. In addition, classes in Java have a run-time representation that enables type checking at run time.
  12. The Java language's excellent features make Java applications incredibly robust and reliable, which also reduces maintenance costs for application systems. Java's full support for object technology and the embedded API in the Java platform can shorten application development time and reduce costs. Once Java is compiled, the ubiquitous features allow it to provide an open architecture anywhere and a low-cost way to deliver information across multiple platforms. In particular, the Java Enterprise Application programming Interface (Java Business APIs) provides technology and a rich class library for enterprise computing and e-commerce application systems.


and C + + differences

Readers familiar with the C and C + + languages must want to understand this problem, in fact, Java is actually from the C language and C + + language inherited a lot of components, and even Java as a Class C language development and derivation of the product. For example, the Java language variable declaration, operator form, parameter transfer, flow control and other aspects and C language, the C + + language is exactly the same. However, Java and C, the C + + language, there are many differences, mainly in the following aspects:

(1) The allocation of memory in Java is dynamic. It uses operator new to allocate memory space for each object. Also, the actual memory will change with the program running. In the program running, the Java system automatically scans the memory and collects the long-term unused space as "garbage", which makes the system resources be used more fully. By this mechanism, the programmer does not have to focus on memory management issues, which makes the Java program writing simple and clear, and avoids the memory management errors caused by the system problems. The C language allocates and frees memory by using the two library functions of malloc () and free (), respectively, by operator new and operator delete in the C + + language. In C and C + +, programmers must be very careful with memory usage issues. On the one hand, if you release the memory to release or release the unallocated memory will have unpredictable consequences, on the other hand, if the long-term unused or no longer used memory is not released, it will waste system resources, and even cause resource exhaustion.

(2) Java does not define global variables outside of all classes, but rather defines a common static variable in a class to accomplish the function of a global variable.

(3) Instead of a goto statement, Java uses the try-catch-finally exception-handling statement instead of the GOTO statement to handle the error function. There is a goto reserved word in Java, but it has no effect, in other words, we cannot use Goto to jump to a row. In fact, structured programming completely does not require a goto statement to complete a variety of processes, and the use of goto statements tend to make the program less readable, so Java does not allow Goto jump, The tags in Java are designed for loops and are designed for easy use of break and coutinue in multiple loops.

(4) Java does not support header files, while the C and C + + languages use header files to declare classes, variables, functions, etc., this adoption of the structure of the header file makes the system operation and maintenance is quite complicated.

(5) Java does not support macro definitions, but rather uses the keyword final to define constants, which can be used to implement constant definitions with macro definitions, which may be detrimental to the maintainability of the program.

(6) Java assigns a fixed length to each type of data. For example, in Java, the int type is always 32 bits, whereas in C and C + +, for different platforms, the same data type is assigned a different number of bytes, the same int type, two bytes in the PC is 16 bits, and in VAX-11, is 32 bits. This makes C language non-portable, while Java has a cross-platform (platform-agnostic) nature.

(7) Type conversion is different. In C and C + +, almost arbitrary type conversions can be done with pointers, often resulting in insecurity. In Java, the runtime system handles object processing for type-compatibility checks and early detection of conversion errors.

(8) No structure and union. In C and C + +, all members of the struct and Union are public and can cause security problems. In Java, there is no structure or union at all, and all content is encapsulated within the class.

(9) Java no longer uses pointers. Pointers are the most flexible and most error-prone data types in C and C + +. Memory address operations performed by pointers often cause unpredictable errors, and after an explicit type conversion of a memory address through a pointer, a private member in C + + can be accessed to compromise security. While Java has full control over pointers, programmers cannot perform any pointer manipulation directly.

(10) Avoid platform dependencies at runtime. Libraries implemented in the Java language can be used in Java applications in other platforms, rather than in the usual implementations of C, C + +, where the target code relies on a specific hardware architecture or even an operating system environment.

Basic concepts:

  • Final class: This class is not extensible to prevent others from deriving new classes from your class.
  • Polymorphic classes: In Java, object variables are polymorphic. Multiple inheritance is not supported in Java.
  • Abstract class: A class that prescribes one or more abstract methods must itself be defined as abstract.
  • Interface: The interface in Java is the declaration of a series of methods, is a collection of methods features, an interface only the methods of the characteristics of the method is not implemented, so these methods can be in different places by different classes implementation, and these implementations can have different behavior (function).
  • Each class in Java is extended from the object class.
  • The equal and ToString methods in the object class.
  • Equal is used to test whether an object is equal to another object.
  • ToString Returns a String that represents the object, each of which inherits the method from the object class, and some classes override the method to return the correct representation of the current state.
  • (The ToString method is a very important method)
  • Universal programming: All values of any class type can be substituted with variables of type object.
  • Encapsulation: It is the process of combining data and behavior in a package and hiding the data from the object's users, and the data in an object is called his instance field (instance field).
  • Overloading: Overloads occur when multiple methods have the same name and have different parameters. The compiler must pick which method to call.
  • Rewrite: In Java, subclasses can inherit methods from the parent class without having to rewrite the same method. But sometimes subclasses do not want to inherit the parent class's methods, but want to make some changes, which requires a method of rewriting.
  • Array list: ArrayList dynamic array list, which is a class library, defined in the Java.util package, that automatically adjusts the size of the array.
  • The GetClass method in class object class returns an instance of class type that is loaded when the program starts with the class containing the main method, and the virtual machines load all the classes that he needs, and each loaded class loads the classes it needs.

The characteristics and application of Java language

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.