Java Lecture 1

xiaoxiao2021-03-06  15

Chapter 1 Java Language Overview

Through this chapter, learn the development, characteristics of Java language, and the differences between Java and C , master how the general structure of Java applications and how the Applet applet is generated. Through skill training, master the basic use of Java operating environments.

1.1 Java language profile

1.1.1 Development of Java Language

The predecessor of Java language is known as Oak language. It is a software project called "Green", developed by SUN Microsystem in 1991. The original intention of the project is to develop a platform-independent of the consumer electronics. Software technology. Since then, Oak language has been considered to be tools for developing consumer electronics and interactive TV controllers. In 1994, the two developers of Sun created the first version of Hotjava on the basis of Oak. At that time, it was called WebRunner, ie the graphical browser used on the web. It is called Java after a period of time. In May 1995, Sun has officially released Java language, and then immediately got a strong support, and joined the Applet applet on the browser (using a small application written in Java language) and through the Internet around the world. Communicate.

So far, there are 4 main versions of the Java language: Java 1.0 (1995), Java 1.1 (1997), Java 2 (1998) with SDK1.2 and Java 2 with SDK1.3 ( 2000).

In fact, Java language is a new type of network language that is developing synchronously with the Internet, which is one of the most meaningful progress in computer software environments in the past 20 years. The Java language is as important as the HypertExt Markup Language in the network. The Java language is a powerful network programming language that maximizes network resources, and the Applet applet can run across platforms, cross-operative systems, cross-network operations. Due to small applet code, it is easy to download and easy to download and Send and have new features that can increase the web page without modifying applications. Java also provides many public system interfaces for programming technicians. As Internet is widely popular in the world, as well as penetration in various fields, Java languages ​​have been accepted by people from all walks of life.

1.1.2 Characteristics of Java Language

The Java language is widely recognized because it has many advanced technical features:

1. Good transplantability

We know that there are tens of thousands of computer systems on the Internet online, and the computer is soft and hardware. To make the application can run normally in any computer system on the network, it must ensure that the portability of the application software is better. That is, the application software itself is not limited by the computer hardware and the operating system (ie, software code can run normally in different computer environments. The Java language is a platform-independent programming language, and the transplantable programming language is guaranteed to have the basic data type and the platform. The binary code generated by the Java source program is a collection of instructions that are independent of the specific instructions, through the Java Virtual Machine, JVM, can run on a different platform.

2. Pure object-oriented technology

Java is a programming language for completely faced objects (ORIENTED Obiect Programming, OOP). The Java language code consists in form of a class. Java deletes the non-objective characteristics of C , making the application development very easy. The characteristics of Java object-oriented technology include encapsulation, inheritance, and polymorphism, which will be detailed in the future. 3. distributed

The Java language provides a library that supports HTTP and FTP and other TCP / IP protocols, through these class libraries, Java applications can open and access objects on the network via URL. Therefore, it is convenient to use the Java language to easily write applications suitable for Internet and distributed environments.

4. safety

Distributed computing environment requires software with high stability and security. The Java language has a powerful security structure and security strategy. Java has high quality security because of the following measures:

(1) Cancel the pointer operation and not allowed to operate directly.

(2) Realize memory management automation, the memory layout is determined by JVM.

(3) Provide a bytecode inspection to ensure that the program code accepts a layer of security check during compiling and running, which prevents illegal programs or viruses.

(4) Provide a file access control mechanism to strictly control access to program code.

(5) Provides a user interface for a variety of network software protocols, users can use multiple encryption techniques in network transmission to ensure the security and integrity of network transmission.

5. Combination of compilation and interpretation

Java is a combination of compilation and interpretation. A Java language source program must be run, and must be compiled by a Java compiler (bytecode), ie the file extension is .class. This word code file is not the final executor, cannot run on a specific platform, and must be translated into a machine language on the byte interpreter on the running system, reaching the purpose of performing the program while the translation. Since this interpretation process is performed on the compiled bytecode, the running speed is still quite fast.

1.1.3 Comparison of Java and C

The C language is adapted to the object-oriented new trend of the software engineering, but C does not really meet object-oriented programs, which retains many non-domain features. The Java language realizes the characteristics of pure object-oriented, making it easier than C languages ​​and is more acceptable.

From the origin and development of Java language, on the one hand, it is developed by C , and its language style is very similar to C ; on the other hand, Java is simpler than C , it deletes C difficult to understand, easy to cause security hazards Content. The difference between Java and C is mainly manifested in the following aspects:

1. pointer

The most effective characteristics of the pointer and memory address are also the most hazardous features in C . Incorrect pointer operations will cause many errors. The pointer is not allowed in Java.

2. Memory allocation

Memory allocation in C is the same danger, and its memory allocation is implemented through the malloc () and Free () library methods and new operators in New and Delete, and programmers need to release space. There is no Malloc and Free functions in the Java language. Since each complex data structure is an object, they allocate space through the New operator, once the object is no longer accessed, the occupied memory space will be automatically recovered, and there is no need to intervene.

3. Global variable

The C global variable is not well packaged as the status signal of the program. Java language is only a class, it is impossible to create a global variable that does not belong to any class. 4. type of data

Different C compilers are assigned to the data type according to the actual configuration of the different machines to different word lengths. The basic data type given by the Java language determines a reasonable word length and remains unchanged. This strict and hardware-independent data type of the Java language interpreter is difficult to optimize and implement the code. The data type of Java language is Very fragile, but this is the only way to ensure cross-platform implementation.

5. Goto

Before C introduces exception handling, GOTO is often used to jump out of the loop in an exception handling. The Java language does not have a goto statement. It strictly defined the exception handling mechanism to make GOTO no longer exist, canceling this random jump statement facilitates optimizing the code and maintaining the stability and security of the system.

6. head File

C has the header file referenced by the include, the Java language has no header file, but the Java language has a package introduced by IMPORT.

7. Multiple inheritance

C has multiple inheritance characteristics, Java language does not directly support multiple inheritance.

1.1.4 Several basic concepts for object-oriented programming

Object-oriented programming technology is one of the technologies commonly used in today's software development. The Java language is a new type of pure object-oriented programming language, which uses a software object called "class", which can be reused and scalable, which can make these classes consisting of variables and methods. As a template, adding other functions on these templates to create the new classes you need yourself, no need to override a lot of code, so the development of applications is easy. Several main concepts that are often involved in object-oriented programming are as follows:

1. Object

Object (Object) can be any object in real life, such as a book, people or moving plants, computers, etc. are objects in real life, some invisible affairs, rules are also objective. Any object includes two basic aspects, one is an internal configuration of an object (e.g., various components that make up aircraft), and the other is the behavior of the object, that is, the operation of the object constitutes the operation or exchange of external information (for example , Launch, takeoff, etc.). Corresponding to the two fundamentals of the object, the objects in the OOP also have two basic components: data and methods. Data represents the composition of the object, the method represents the behavior of the object.

2. class

Class (Class) is a set of objects with the same basic ingredients. For example, university consists of many specific schools, university is a class, and the specific Peking University is an object of university class.

Category is the most basic, most important data type. As a data type, the corresponding type of data must be defined in the program, and the data defined by the class is referred to as an instance or object of this class. There are two basic components: data and methods, they are packaged in the body, separated from the outside world. Data is a member of the class, which can be a basic type of data (eg, int, char, etc.) or an example of a class. The method is also a member of the class, which is used to handle the data of the class, the method of the class is similar to the functions in other languages, and has the name, parameters, method and return value of the method.

3. Encapsulate

Encapsulation is to encapsulate the basic components (data and methods) of classes (or objects) within the type (or object), so that it is separated from the outside.

Generally, the mechanism with hidden complexity in the class. Each method or variable in the class can be defined as public or private. The public part of the class can let the outside user know or must know that the public instance variable and method are a class and an external interface, the application uses the functionality of this interface; and define the private method and instance data cannot be classified Access to the outside of other code. When performing OOP programming, first need to define classes, and point out the name, data member, and method of the class, determine the permissions of the class member to be accessed, etc .; Secondly, use the class to create the corresponding instance (or object); finally, in the program run Information is exchanged with objects as needed by the system.

4. inherit

Inherit refers to establishing a new class based on existing classes. The new class automatically has all methods and instance variables of the parent class, and then add the method or instance variable required to add new tasks as needed.

A class that is not born from other classes is called a base class; a recent father (its nearest superior class) is called the parent class of this class; the class of derived class is called the subclass of such class. In the Java language, a parent class can have multiple subclasses, but a subclass can only inherit from a parent class, that is, a subclass cannot have more than one parent class, which means that the Java language does not support multiple inheritance. . In order to solve multiple inheritance issues, the concept of interfaces introduced in Java language and overcomes multiple inheritance complexity.

Reasonable use inheritance can reduce much repetitive labor. If a special feature is implemented in a class, these features can be reused in its derived class without re-programming. You can use the Java language built-in class to create a class, or you can establish a class for the class you created yourself.

Inheritance and packaging have good cooperative. If a given class encapsulates some properties, then any subclass will inherit these properties.

5. Polymorphism

Polymophism means that there are multiple names in a class, but the type and number of parameters are different. When these methods are called, the parameter type and quantity of the method determine which method is called, which not only simplifies the implementation and call of the method, but also for memory.

The overlay (or rewrite) of the method means that the subclass can redefine certain methods of the parent class in the process of inheritance, and implement themselves.

In the Java language, polymorphisms are implemented by Overloading and overridding. Method Overloading refers to a plurality of methods have the same name, but the parameters of each method are different. When the method is called, the system automatically selects the corresponding method according to the actual parameters.

1.1.5 Use of Java language

Java language is increasingly affected and recognized by developers because of the characteristics and complete object-oriented characteristics, and it has also determined the special purpose of the Java language. The area of ​​Java language applications include a lot, but its side weight is different from other languages. It is hoped that the reader has mastered the knowledge related to the main application below through this book.

1. Java language can easily increase the function of the Internet / Intranet page

The performance form of the Applet applet execution result is based on the web page based on the web page, which can be easily embedded in the HTML code and is easily called and implemented. At present, people are very familiar with the web page, you can use some popular tools to make a web page. If you use the Java Applet applet to expand your web page, you can enrich the content of the webpage.

2. Java language can easily implement parallel work in multiple tasks

Many languages ​​have functions that implement multitasking parallel work, but the Java language is based on its network applications, plus multi-threaded programming technology provided by Java languages, making it easy to use Java language-based multitasking multitasking program. For example, complete the operation task for monitoring multiple tasks while simultaneously on the web page. 3. Java language can easily access network resources

Using Java language will easily develop procedures for network resources. For example, to access the information of a web page, including the domain name, IP address, information termination date, information modification date, length of information; to get the content of a file on a network server; design network client and server application Programs (such as postage, dialogue, etc.), etc., Java language presents a good network language.

4. Java language can easily implement web-based database access

The Java language provides technology for accessing the database. Using JDBC technology in Java language, users can easily develop web-based database access programs to expand the functionality of network applications.

5. Java language can easily implement distributed applications

The Java language provides many technologies to facilitate distributed applications. Using techniques such as JSP, RMI, CORBA, and EJB in Java languages, users can easily implement distributed applications.

1.2 Java program introduction

The Java source program consists of class definitions, so it can only be programmed in the source program. A Java source program can contain a class definition or multiple class definitions. The Java source program is saved with .java as the suffix name. When the Java source code is compiled, each class is saved in the output file that is .class as the suffix name. Before you start learning Java language programming, you should learn about the basic composition of the Java source, and how to write, compile, and run the Java program to create a general impression.

Generally, Java programs are divided into Java applications and two Java-based Applet applets.

1.2.1 A simple Java application

Write an application with Java language, and then get the result, you need to pass three processes, namely, write source programs, compile and run.

1. Write the source program

A simple Java application is shown in Example 1.1.

[Example 1.1] A simple Java application.

// File name: HelloChina.java

Public Class Hellochina, PUBLIC CLASS HelloCHINA

{

Public static void main (string [] args)

{

// Output a string

System.out.println ("Hello, China!");

}

}

Through this program, we can see the Java app is still relatively simple, the structure is not complicated. The reason why it is called an application, its flag is a main method, and there is only a Java program containing the main method to run with a Java command. The programming principle of Java language must be followed when writing a Java program. The basic format of a simple Java application has the following points:

(1) The Java program is an unformatted plain text file that can be written in any text editor (eg, Word, Word board) to write Java programs.

(2) The file name must be consistent with the name of the name, and the case is consistent. For example, class name Hellochina, then the file name at the time of the market should be Hellochina.java.

(3) First, use the keyword class to define a new class, and the class name is followed. Here PUBLIC indicates a public class, which can be omitted, and Hellochina is the class name defined in this example.

(4) A Java program can have multiple classes, each class can have multiple methods, but only one public class is available. (5) For an application, there must be a main () method, and can only have a main () method. This method marks the starting point when performing an application. The keyword public indicates that all classes can call this method. The keyword Static indicates that the method is a static method. The keyword Void represents the main () method without return value.

(6) There are multiple statements in any method. In this main () method of this example, only one statement is:

System.out.println ("Hello, China!");

This statement is used to output a "Hello, China!" String on the screen, and the functionality of System.out.Println () is the same as the Printf () function in the C language.

(7) Each statement in the Java program is to end with a semicolon ";", including the type descriptions, which appears in the later program.

(8) In order to increase the readability of the program, some annotation lines can be added, for example, using the "//" row.

See Chapter 2 for Note Definitions for Java Language.

This example is just a simplest Java program, only one class, only one method is included in the class, and does not include data. If the data is included in the class, there is also a type of description and other statements in the structure.

2. Compile

When the Java program is written, you must translate the .java source program into a two-input bytecode file that is independent of the processor complicated by the Java compiler. In the Java language environment, perform the following command to compile the HelloChina.java program, which will automatically get the HelloChina.class bytecode file after compiling.

Javac HelloChina.java

3. run

The bytecode file with .class is not an executable program. It must be translated by the bytecode detector and Java interpreter to run, through a special operating environment, can form .exe's executable . In the Java language environment, execute the following command to run the HelloChina.class program:

Java HelloChina

If everything is normal, the results will be shown in Figure 1.1.

Figure 1.1 HelloChina program operation results

1.2.2 Write the application as an Applet applet

The Applet applet based on Java language can be embedded in the HTML language and explained the execution of the program with a WWW browser (such as Internet Explorer, Netscape Communicator, etc.) with a Java interpreter. It is not possible to use the Java interpreter. carried out. The reason why the applet is called a small program is because its code is small and easy to download through Internet / Intranet.

Generally, a feature is implemented with an Applet applet. The last result is required to write Applet applets, compile the applet, write an HTML file, and perform HTML code programs. There are two ways to execute the HTML program, one is to perform an HTML program by running the browser; the other is the appletViewer command provided by the Java package executes an HTML program.

1. Write Applet applet

[Example 1.2] Applet small program example

// File name: HelloWorld.java

IMPORT JAVA.Applet.Applet;

Import java.awt.graphics;

Public Class HelloWorld Extends Applet

{

Public void init ()

{

Resize (400, 300);

}

Public void Paint (Graphics G)

{

g.drawstring ("Hello, the World!", 60, 40);

}

}

From Example 1.2, we see that the basic structure based on Java-based Applets is similar to Java applications, and different places are as follows:

(1) At the beginning of the small program, two system classes must be introduced into two system classes: java.applet.applet and java.awt.grapgics, the methods in these two classes are required in the program. When introducing the class provided by the system, you should use keyword import, which is the same as the #include function in the C language.

(2) Keywords EXTENDS indicates that the HelloWorld class is inherited by the Applet class.

(3) The init () method and the Paint (Graphics G) method are the public methods defined in the Applet class and the Graphics class, respectively, respectively, for the initialization and display output of the applet.

(4) All defined Applet techniques must be derived from the Applet class and cannot have the main () method.

For details on applet applet, please see Chapter 5.

2. Compile Applet applet

After the Applet applet HelloWorld.java is written, you need to compile it, automatically generate the bytecode file helloworld.class, which is the same as the Java application.

3. Write HTML code

The bytecode HelloWorld.class for the Applet applet must be embedded in the HTML code to complete the functionality of the applet. So, you must also write an HTML code file for HelloWorld.class, and introduce the bytecode program. Below is an HTML code file, the file name is HelloWorld.html. About HTML language, not the main content of this book, interested readers, please refer to relevant books.

[Example 1.3] Embed an HTML program example of the HelloWorld.class code, the file name is HelloWorld.html.

helloworld </ title></p> <p><Body> The program output is: </ P></p> <p><Applet code = "helloworld.class" width = 200 height = 80></p> <p></ Applet></p> <p></ Body></p> <p></ Html></p> <p>In the code of HelloWorld.html, the role of <applet code = helloworld.class width = 200 height = 80 </ applet> is that when the browser performs a HelloWorld.html program, call the applet HelloWorld.class and execute .</p> <p>4. Perform an HTML code program</p> <p>(1) Perform an HTML program in the browser</p> <p>Once you have written for HelloWorld.html, you can use the Internet Explorer Browser (IE IE) to explain it. The result is shown in Figure 1.2.</p> <p>Figure 1.2 Execute the result of HelloWorld.html in the browser</p> <p>(2) Run the HTML program using AppletViewer</p> <p>HTML design and use is before the Java language appears, SUN Microsystems have extended HTML in order to make Applets in web page, and developed AppletViewer tools in this background. AppletViewer is a simple Java browser for easy readers to learn Java, with most features of the browser, mainly for learning and debugging procedures. Use AppletViewer to run the HelloWorld.html command to use AppletViewer to:</p> <p>AppletViewer HelloWorld.html</p> <p>The result is shown in Figure 1.3.</p> <p>Note: Since the HTML program with an Applet applet is performed using IE, the running speed is slower, so this operating environment is not suitable for debugging. Typically, the programmer uses the AppletViewer tool to achieve the purpose of the debugger, but the AppletViewer tool does not recognize the HTML language, so sometimes some display results are not visible when using the AppletViewer tool to perform an HTML program. Please pay attention to the difference between Figure 1.2 and Figure 1.3.</p> <p>Figure 1.3 Execute the result of HelloWorld.html using AppletViewer</p> <p>1.3 Java program operating environment</p> <p>At present, the more popular Java program running the environment with the integrated environment-based JBuilder and two Java 2 SDK 1.3.1 based on the DOS platform. In contrast, due to the Windows platform, it is more favored by the user, but the operation is more complicated. The latter is relatively easy.</p> <p>1.3.1 Java 2 SDK 1.3.1 Introduction</p> <p>1. Java SDK package</p> <p>The Java Standard Development Kit (SDK) is an development environment for constructing applications, applet applets, and components published on the Java platform.</p> <p>Java 2 SDK 1.3.1 software package can be downloaded from http://java.sun.com, because Java packages are supported by different operating systems, so the downloaded files are different. For software packages running on the Microsoft Windows platform, the downloaded file is J2SDK-1_3_1_01-win.exe, running the file directly when installing. For packages running on the Solaris SPARC / Intel platform, the downloaded file is J2SDK-1_3_1_01-solx86.sh. For software packages running on the Linux platform, the downloaded file is J2SDK-1_3_1_01-Linux-i386.bin and J2SDK-1_3_1_01-Linux-i386-rpm.bin. Windows-based Java software packages are the main contents of this section.</p> <p>When installing a JSDK package, you must have a 100M available disk space. If you need to install the document directory separately, you will need 85m available disk space.</p> <p>The JSDK software contains some tools that can be used to develop and test the program written in the Java language, which is used in the manner of command line. These tools do not provide graphical user interfaces in addition to AppletViewer and PolicyTool.</p> <p>2. Environment setting</p> <p>(1) Path settings for bin directory</p> <p>In order to compile the Java source program and run the Java program with Java or AppletViewer, you need to edit the autoexec.bat file, add the path to the bin directory in the PATH environment variable.</p> <p>,E.g:</p> <p>PATH = "% PATH%"; D: /JSDK1.3/bin;</p> <p>(2) Setting and clearing ClassPath</p> <p>In order to use classes in other directories in the working directory, you can set the ClassPath environment variable in the AutoExec.bat file. Setting method is: set classpath = path1; path2 ...</p> <p>If the ClassPath environment variable is set to an incorrect value, or the startup file or scriptor sets an incorrect path, you can clear the ClassPath by using the following command:</p> <p>SET CLASSPATH =</p> <p>3. Javac's use</p> <p>The extension of the Java source program file is .java, it is a standard ASCII text file that uses the JavaC tool to compile it to an executable Java bytecode file, that is, the file named .class. The Javac compiler generates a corresponding .class file for each class, regardless of whether these classes are in the same file.</p> <p>(1) javac command syntax</p> <p>The Javac command line format is:</p> <p>Javac [Options] [Sourcefiels] [@files]</p> <p>The parameters in the command are as follows:</p> <p>1 parameter can be arranged in any order</p> <p>2 Options refers to the command line option, see the following content.</p> <p>3 SourceFiles refers to one or more source files to be compiled. If you need to compile multiple files at a time, the file name is separated by spaces.</p> <p>For example: javac hellochina.java helloworld.java</p> <p>4 @files refers to one or more list files. The list file contains one or more source program files to be compiled. If you need to compile multiple list files at a time, the list file name is separated by spaces.</p> <p>For example: javac @ f1 @ F2</p> <p>(2) javac command option</p> <p>The Javac compiler has some standard options, current development environment supports these standard options, and future versions will also support it. There is also a group of additional non-standard options that are unique to the current virtual machine implementation, and may have change in the future. Non-standard options are headed in -X. Some of the commonly used options are briefly introduced below:</p> <p>-classpath <path></p> <p>Set the user class path, which overrides the user class path in the ClassPath environment variable, and the path item is separated by a semicolon (;). If neither ClassPath is specified and -classpath, the user class path is the current directory. If the -SourcePath option is not specified, the class file and source file will be found in the user class path.</p> <p>-D <Directory></p> <p>Set the target directory of the class file. If a class is an integral part of a package, Javac will put this class file into the subdirectory reflecting the package name, if necessary, create a directory. If the -d option is not specified, Javac will put the class file in the same directory as the source file.</p> <p>-DepRecation</p> <p>Displays location information of the source program that cannot use the API interface.</p> <p>-ENCODING <encoding></p> <p>Set the encoding name used by the source file. If the -Encoding option is not specified, use the platform default converter.</p> <p>-g</p> <p>Generate all debug information, including local variables. By default, only the debugging information of the line number and source file is generated.</p> <p>-g: None</p> <p>Do not generate any debugging information.</p> <p>-g: {line, var, source}</p> <p>Only the line number, variable, debugging information of the source program.</p> <p>-NoWarn</p> <p>It is forbidden to generate warning information.</p> <p>-O</p> <p>Optimize the code to shorten the execution time. However, using the -o option may cause the compilation speed to make the program difficult to debug when generating a larger class file.</p> <p>-SourcePath <PATH></p> <p>Set the path to find the source code, the path item is separated by a semicolon (;).</p> <p>-Verbose</p> <p>Displays the operation prompt information on the compiler.</p> <p>-bootclasspath <path></p> <p>Combined with the specified bootstrap path set, the path item is separated by a semicolon (;). -extdirs <dirs></p> <p>Combine compilation according to the specified expansion directory. The directory item is separated by a semicolon (;).</p> <p>-Target <release></p> <p>Generate a class file running on the specified version of the virtual machine.</p> <p>4. Java's use</p> <p>(1) Java command syntax</p> <p>Java tools are used to run Java applications. It implements the functionality of the Java application by launching the Java runtime environment, loads the specified class and calls the same MAIN method. There are two kinds of Java command line formats:</p> <p>Java [option] class [argument ...] This command function is to execute a Java class program.</p> <p>Java [option] -jar file.jar [argument ...] This command function is to perform a program encapsulated in the JAR archive.</p> <p>The parameters in the command are as follows:</p> <p>1 Option means the command line option, see the following content.</p> <p>2 Class points out the class name to call.</p> <p>For example: java hellochine.class</p> <p>3 file.jar points out the name of the JAR file to call. Only use-JAR.</p> <p>For example: java -jar helloworld.jar</p> <p>4 argument points out the actual parameters to be passed to the main method. If there is a statement using an external parameter in the MAIN method of the application, the actual parameters of the corresponding number must be given when executing the Java command.</p> <p>(2) java command option</p> <p>The Java runtime has a set of standard options, currently running these options and future versions will also support them. There are also some additional non-standard options that are unique to the current virtual machine implementation, and may have change in the future. Non-standard options are headed in -X. Some of the commonly used options are briefly introduced below:</p> <p>-cp -classpath <path></p> <p>Specify a search path for finding class files. The classpath item is separated by a semicolon (;). Specify the -classpath -cp option, all settings of the ClassPath environment variable will be overwritten.</p> <p>-D <property name> = <value></p> <p>Set the value of the system properties.</p> <p>-verbose: Class</p> <p>Output class information loaded by each class.</p> <p>-Verbose: GC</p> <p>Output Each garbage collection event</p> <p>-verbose: JNI</p> <p>Output information about the use of the local method and other Java platform related code interface activities.</p> <p>-Version</p> <p>Exit after outputting the version information.</p> <p>-ShowVersion</p> <p>Continue after outputting the version information.</p> <p>-X</p> <p>Output information about non-standard options and exits.</p> <p>-? -Help</p> <p>Output help information.</p> <p>5. Used of the Java Applet browser (AppletViewer)</p> <p>The AppletViewer command can run the Applet applet in the absence of a Web browser environment, which greatly facilitates program debugging. The command line format is:</p> <p>AppletViewer [Option] URLS</p> <p>The AppletViewer command is connected to the document or resource pointed to by the specified URL (HTML file) and display the execution result of each Applet applet of the document reference in its own window.</p> <p>For example: AppletViewer HelloWorld.html</p> <p>The options in the command line have the following:</p> <p>-debug</p> <p>Start AppletViewer in the Java debugger, you can debug the Applet applet in the document.</p> <p>-ENCODING <encoding></p> <p>Specifies the character encoding name used by the HTML file.</p> <p>-J <runtime flag></p> <p>Pass the specified string as a single parameter to the Java interpreter, the parameters cannot contain spaces. The string consisting of multiple parameters, each of which must be started with a prefix -j. This will be useful when adjusting the execution environment or memory usage of the compiler. It is easy to master in Java 2 SDK 1.3.1. It is easy to master. Most of this book is based on this platform.</p> <p>1.3.2 jbuilder introduction</p> <p>JBuilder is the latest visual Java development tool in Borland, USA, is the current Java development environment preferred by computer developers. It supports the latest J2EE standard, and its visualization tools and development areas that make Java application development very convenient and fast.</p> <p>Using JBuilder to develop a variety of Java applications and systems, including Java Applet, database applications, and distributed multi-layer structures. JBuilder offers 100% pure Java development environment. All programs written in Java can run and debug in JBuilder. Compared to other Java development environments, JBuilder has better played the programming capabilities of Java language.</p> <p>JBuilder supporting J2EE standard has developed from JBuilder 4, JBuilder 5 to the latest JBuilder 6 version. Regardless of the user's use, its basic operation is similar. This section briefly introduces JBuilder's use of JBuilder with jbuilder 5 for windows.</p> <p>1. Start JBUILDER</p> <p>When JBuilder is successfully installed, you can start JBuilder by selecting the "Start" → "JBuilder 5" → "JBuilder 5 Enterprise" of the Windows desktop. The screen of the input serial number and key will appear when starting, if the serial number and key are correct, to enter the JBuilder integrated development environment is shown in Figure 1.4.</p> <p>Figure 1.4 JBuilder 5 integrated development environment</p> <p>2. JBuilder integrated development environment</p> <p>(1) Introduction to the main interface</p> <p>Figure 1.4 shows the JBuilder integrated development environment. In this window, users can create, edit, manage files and projects, and perform visual design, compile, debug and run applications. As can be seen from Figure 1.4, the integrated development environment includes some main interfaces.</p> <p>The description of the main interface here follows the principle from top to bottom, from left to right in Figure 1.4.</p> <p>· Main menu bar: Provide menu access method, such as File Menu, Edit Menu (Edit), View Menu (VIEW), Engineering Menu (Project), Run Menu (RUN), Wizard Menu (Wizard), and Tools Menu ( Tools, etc.</p> <p>· Main toolbar: By functional division into a number of gadgets, the button above corresponds to the quick access to the menu command item.</p> <p>· Engineering Toolbar: Includes a list of currently opened projects and some buttons, which are used to increase, delete files, shut down, and update project files in the project panel.</p> <p>· Engineering window: Show the contents of the selected project. Used to browse and operate the project tree.</p> <p>• Structure Window: Displays the structure of the current file in the content window. For a Java file, the window shows all methods, attributes and events in the form of a tree. The structural window has a downward function, double-click a class or interface, you can view its ancestry class.</p> <p>· Content window: You can view the open file in the content window. Each open file has a label showing its file name and a variety of view tags located at the bottom. These view tags include Source, Design, Bean, DOC, and History.</p> <p>• Message window: It is a multi-tab display area. It shows messages from subsystems, such as designers, search results, compilers, debuggers, and running processes.</p> <p>· Status bar: The latest information on the process and its results can be obtained.</p> <p>(2) The use of the editor</p> <p>In the integrated environment, you can select the Source tab access editor of the Content Window, and then write the Java application in the editor. JBuilder editor supports text search, syntax highlights, code templates, code forecasts. The content window in Figure 1.4 just shows an editor of the currently open file. (3) Use JBuilder 5 Wizard</p> <p>JBuilder 5 provides a number of wizards that can greatly save applications development. JBuilder 5 includes three types of wizards: a wizard for creating a new file to create the wizard of the application component, and the General Auxiliary Tool Wizard.</p> <p>After selecting the "New" command item under the "File" menu, the screen shown in Figure 1.5 appears. These include 6 pages: New, Team, Web, XML, CORBA, Enterprise. The New page contains wizards that use Java 2 Standard Edition technology, including create projects, applications, classes, interfaces and other wizards. The web page contains web-based technical wizards, including creation of an Applet applet. The New and Web pages are the generally used wizards.</p> <p>Figure 1.5 JBUILDER 5 wizard</p> <p>3. Use JBuilder Engineering</p> <p>(1) Engineering concept</p> <p>In the JBUILDER environment, the first step in the development of applications is to create a project. JBuilder uses engineering organizations and maintenance applications.</p> <p>The project file saves information related to the project. It contains the files and packages used by the project, as well as engineering properties. JBuilder needs this information when loading, establishing and distributing projects. A engineering structure is shown in the engineering window of Figure 1.4.</p> <p>Each project is saved in its own directory. Each project directory includes an engineering file (.jpr or .jpx), a selectable file (.html) saving project record, a class of saving class files, a SRC directory for saving source files, and a save backup BAK table of Contents.</p> <p>JBuilder's engineering guidewhere simplifies the creation of the project. When you create a new project using the Engineering Wizard, the guide is automatically set up the project's directory framework, creates and saves the project properties. You can also create an engineering record file for the project, which will appear in the annotation of the project source file and will appear in the document generated by Javadoc.</p> <p>(2) Creating a project step</p> <p>First, open the Engineering Wizard by selecting the "New Project" command entry of the "File" menu. The screen shown in Figure 1.6 appears.</p> <p>Figure 1.6 Engineering Wizard (1)</p> <p>In the first picture of the Engineering Wizard, you need to enter an engineering name, select a type of project file (JPR or JPX). Pick a project template. You also need to set the name of the root path and the engineering directory.</p> <p>Click the "Next" button to enter the second screen of the engineering wizard as shown in Figure 1.7.</p> <p>Figure 1.7 Engineering Guide (2)</p> <p>Next, in Figure 1.7, the path of the project can be set, compiling the JDK version used and the library required for the project. After the setting is complete, click the "Next" button to enter the setup project title, the author with the company name.</p> <p>It is worth noting that if the "Finish" button is selected in Figure 1.6 and Figure 1.7, the system selects but provincial settings and indicates that the new project creation is completed.</p> <p>(3) Management management</p> <p>The management of the project includes the following:</p> <p>· Open the file: By selecting the "Open Project" command item of the "File" menu.</p> <p>· Add and delete files: Right-click on a file in the project window, then select "Add Files / Packages" or "Remove from Project" command from the pop-up menu.</p> <p>· Save and shut down the project: By selecting the "Save ..." command item of the "File" menu.</p> <p>· Change the project name: By selecting the "Rename" command item in the "Project" menu.</p> <p>4. Create user interface</p> <p>Use JBuilder visual design tools to quickly create a user interface for Java applications. When building a user interface, a panel containing a plurality of components is required, which contain components such as buttons, text boxes, lists, dialogs, and menus. Click the "Design" tab in the content window to see various components. In order to set the properties of the component and respond to user interface events, it is necessary to write corresponding event handler for components.</p> <p>The method of adding the operation component is to select a component of the component panel, click the designer, or click on this component in the Content window to place the selected component in the designer, and the branch of the component tree in the structure window A new component node will appear. Create the contents of the user interface in JBuilder, you can learn after learning Chapter 8.</p> <p>5. Compilation and run</p> <p>The step of running the Java program in jBuilder is: First save the application or file you want to run; then select the application or file you want to run from the engineering window; if you want to run a Java application, then compile it first (with The "Make Project" command item under the "Project" menu, select the "Run Project" command item under the "Run" menu. If the application has been compiled, you can run it directly. If it is an Applet applet, you only need to compile it with the same method.</p> <p>This section only introduces the most basic content in JBuilder, interested in studying JBuilder readers, please refer to relevant books.</p> <p>Habit</p> <p>1.1. What are the characteristics of Java language?</p> <p>1.2. What is the difference between the Java language and the C language?</p> <p>1.3. Briefly describe objects, classes, packages, inheritance, and polymorphisms of object-oriented programming.</p> <p>1.4. What is an applet applet? Realize Applet applets, need to pass several processes? Please briefly describe its process.</p> <p>1.5. What is the difference between the Java application and the Applet applet?</p> <p>1.6. Find out the error in the following procedure:</p> <p>Goodbyeworld</p> <p>{</p> <p>Public static void main (String [] arg)</p> <p>{</p> <p>System.out.println ("Goodbye, World!")</p> <p>}</p> <p>Practice</p> <p>Skill training purposes:</p> <p>1. Familiar with the Java application environment. That is, master the basic use of Java 2 SDK.</p> <p>2. Familiar with the JBuilder integrated environment.</p> <p>3. Proficiency in the editor, compile and running the Java app.</p> <p>4. Proficiency in the editing, compile and running process of applet applet.</p> <p>Skill training content:</p> <p>1. Java application training</p> <p>(1) Use any text editor to enter the program of Example 1.1 into the computer, generate the Java file of HelloChina.java;</p> <p>(2) Compile this program with a javac command to generate a HelloChina.class file;</p> <p>(3) The guarantees that the program is correct, run the program with the java command;</p> <p>(4) View the files in the directory.</p> <p>2. Training of Applet applet</p> <p>(1) Use any text editor to enter the program of the Example 1.2 into the computer, generate the Java file of HelloWorld.java;</p> <p>(2) Compile this program with a javac command to generate a HelloWorld.class file;</p> <p>(3) Use the Word text processor to enter the program of the 1.3 input into the computer, generate the HelloWorld.html file; (4) Execute the HelloWorld.html code with the appletViewer command, and watch the result;</p> <p>(5) Execute the HelloWorld.html code with the IE browser command, and watch the result;</p> <p>(6) View the file structure in the directory.</p> <p>3. Familiar with the JBuilder environment if there is condition</p> <p>The above 1, 2 training tasks are implemented in the JBUILDER environment, and the application of JBuilder integrates the development environment.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-46424.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="46424" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.047</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'Qs_2Fy3YQGf_2FSV8jYmote9MWhR2VEQm6uH2iOkGKjR_2Fpw2c44tGHmqCyfhodyJr298dVV82eObMyw15_2BHt70YuFQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>