1. Java preliminary
Java is a new object-oriented programming language developed by sun company, mainly used for the design of web pages.
The development of the Java language is quite legendary, and it is inseparable from the rapid development of the Internet's WWW. Due to its rapid development, some people compare it to Esperanto on the Internet. As mentioned earlier, the design of Web pages on the Internet uses HTML language. With the help of Web browsers (such as Netscape, HotJava, IE, etc.), users can access static, hyperlinked Web pages on remote web servers. The emergence of the Java language has changed the traditional static model of Web pages. By attaching some Apps (called small programs) written in Java to the Web page, the Web page can be made more diverse and changeable, so that users can Ability to access dynamic, interactive web pages.
For example, some small animations, real-time updated charts, sounds, etc. In short, the design of Web pages mainly uses HTML language, and the use of Java makes it the icing on the cake.
Sun officially launched the Java language in May 1995. Due to its simplicity, efficiency, and strong portability, once it was launched, it quickly attracted widespread attention from users and many manufacturers, especially Sum. The company positioned it on Internet application development, allowing Java to develop rapidly. Also launched at the same time was a browser called HotJava (Hot Coffee). Hotjava was a web browser entirely written in the Java language and based on typical Java applications, and was the first to support Java Applets. HotJava fully demonstrates the powerful power of Java on the global Internet, and also provides an ideal running platform for Java language programming.
After the introduction of Java language, major software manufacturers have successively announced their support for Java. First, Netscape supported Java in its Web browser (Netscape Navigator 2.0). Soon, three companies, Sun, SGI and Macromedia, developed open multimedia standards based on Java. Later, many companies, such as IBM, Microsoft, Oracle, etc., announced support for Java. Netscape further cooperated with Sun to launch a JavaScript language similar to Java. At present, Sun has established a special Javasoft division to manage the development and maintenance of the Java language (details can be found at http://www.Javasoft.com).
As for the name Java, the more popular saying is that it comes from an important island in Indonesia. The Chinese translation of the island is "Java". The island is rich in coffee, so the developers of Sun Company named it "Java". The new language is named Java, which means to associate it with steaming coffee and dedicate it to computer users around the world.
2. Characteristics of the Java language
In addition to its ability to compile Applets embedded in HTML files, the popularity of the Java language also lies in the fact that the Java language itself is object-oriented, simple, and platform-independent. performance, security, multi-threading and other features. The structure and writing method of the Java language are similar to the C++ language. Therefore, to learn the Java language, you must not only understand the unique programming characteristics of the Java language, but also have the basics of programming and object-oriented concepts.
lt; BRgt; The main features of the Java language are as follows:
(1) Simple and efficient
The Java language is similar to C++. If users understand the concepts of C++ and object-oriented, they can easily Write Java programs quickly; in addition, Java is different from the various methods provided by languages ????such as C++. It only provides basic methods, which reduces the complexity of programming, such as removing header files, pointer variables, Complex features such as structures, operator overloading, multiple inheritance, etc. Although the Java language is simple, it is very efficient. It can use object-oriented methods to describe every action of the user.
(2) Object-oriented
The Java language is a new object-oriented programming language. In addition to several basic data types, most of them are similar to objects in C++. And methods, most program codes embody the class mechanism, organized in the form of classes, and classes define various behaviors of objects. Java also supports class inheritance, which also reduces the complexity of programming.
(3) Platform independence The Java language is compiled to generate byte codes (Bytecode) that are independent of the computer hardware structure. These byte codes are defined as not relying on any hardware platform and operating system. When a Java program is running, the generated byte code needs to be interpreted and executed by an interpreter. This reflects the platform-independence of the Java language, allowing Java programs to run on any platform, such as MS-DOS, Windows, Unix, etc., so it has strong portability.
(4) Interactive features
Java is an object-oriented network programming language. Because it supports the TCP/IP protocol, users can access various programs on the Internet through the browser. Dynamic objects. And users can perform various actions interactively on the network, and the introduction of multi-threading technology makes this interactive operation easier.
(5) Multi-threading mechanism
The Java language supports multi-threading mechanism, which enables Java programs to process multiple tasks in parallel. Java programs can be designed to have multiple threads. For example, one thread is responsible for data retrieval and search, and another thread interacts with the user. In this way, the two threads can be executed in parallel. Multi-threading mechanism can easily realize interactive operations on the network.
(6) Dynamic memory management mechanism
The Java language uses an automatic garbage collection mechanism for memory management. In the C++ language, programmers must carefully handle the use of memory when writing programs. For example, when a certain memory is almost used up, it must be released in time for use by other programs. Once the memory is not managed properly, it may cause memory space failure. waste or program malfunction. lt; BRgt; The Java system includes an automatic garbage collection program, which can automatically and safely recycle memory blocks that are no longer used. In this way, programmers do not need to worry about memory management issues when programming, thus making the Java program Writing becomes easier while also reducing the possibility of errors in memory management.
(7) Security
In a distributed network environment like the Internet, security is an issue that cannot be ignored. The Java language introduces real-time memory allocation and layout in terms of security to prevent programmers from directly modifying the physical memory layout; the byte code is inspected through the byte code verifier to prevent the intrusion of network viruses and other illegal codes. In addition, the Java language also adopts many object-oriented exception handling mechanisms, which are responsible for handling some abnormal events, such as insufficient memory space, abnormal program termination, etc. lt; BRgt; The above introduces some main features of the Java language. In addition, it also has characteristics such as dynamics, rich class libraries, and high performance. These have made the Java language mature and perfect in all aspects, becoming increasingly popular among the public. One of the programming languages.
3. Java Application and Java AppletJava language is an object-oriented programming language. Using Java language, two major types of programs can be written: Java Application (Application) and Java Applet (Applet) ):
Java applications are written in the Java language. After being compiled and interpreted, they can run independently on MS-DOS, UNIX and other operating platforms. Java applications generally run from the command line.
Java Applet cannot run independently. App1et must be embedded in an HTML file and the browser needs to be started to run. In this way, the specified Applet will be automatically downloaded and run in the user's browser, thereby producing some special page effects, such as animation, sound, charts, images, etc. By embedding Applets in Web pages, dynamic interactions between the Web page and the user can be achieved, such as receiving user input and then generating different responses according to the user's needs.
As far as Java Applet is concerned, it is embedded in an HTML file. Most of the contents presented in HTML files are text, pictures, tables, sounds, etc., but these contents are generally static and two-dimensional. . But when Applets are embedded in HTML files, the entire page will show diversity and change, such as interactive functions, charts, etc. The difference between Java language and HTML language in terms of application is:
(1) HTML language is a simple markup language, and ordinary users can learn how to write HTML files within a few hours. The structure and writing method of the Java language are more similar to C++, so learning the Java language requires a foundation in programming and object-oriented concepts.
(2) Web pages are mainly written in HTML language, but if you want to make the page more changeable, diverse, and interactive, you can use Java language to achieve this effect, which is the icing on the cake. .
4. Embedding Applet in an HTML file language. Applet refers to a small program written in Java language, embedded in a Web page, and executed through a browser to produce special page effects. Web pages embedded with Applets will look more colorful and have dynamic interaction capabilities.
There are a large number of Applets on the Internet. Most of these Applets are designed by Java developers from Sun and other companies. For the majority of users, especially beginners, they can download these Applets to their own computers. By embedding these downloaded App1ets into your own Web page, you can obtain your own Web page with the same effect to enrich your own page content.