Java environment and tools

Source: Internet
Author: User
Java not only provides a language and runtime environment with rich features, but also provides developers and end users with tools to develop and use Java.
Java provides an extension class library for programmers to better create and run their programs faster. A Java class library is a set of pre-developed code that can be linked to a separate application. The Java class library provides programmers with a thoroughly tested set of classes with good robustness. By using these class libraries, programmers do not need to rewrite the code, saving time and improving efficiency. These class libraries represent the core part of object-oriented computing.
The following describes how to use some major Java tools. The Java tools in the Java environment are listed as follows:
* Appletviewer small application Browser
* Java interpreter
* Javac Compiler
* Javah header file Generator
* Javadoc API document Builder
* Javap-type file reassembler
* Jdb Java Debugger
These files are included in the/Java/bin/directory and can be run in any directory, provided that you have set the path in the system where the program is running.
2.1 appletviewer small application Browser

Appletviewer provides a Java runtime environment where you can test the applet of a small application. Appletviewer reads HTML files containing small applications and runs them in a window.
The following options are available in the menu of the small application:
* Restart: re-run the small Application
* Reload: Re-Fetch the small application. This command is useful if the. Class file is changed after being read.
* Clone: Create a New appletviewer Window Based on the command line variable of the HTML file.
* Tag: displays the <APPLET> tag used in the HTML file to start a small application (see Figure 2-1 ).
(Figure 2-1 tag dialog box of appletviewer)
* Info: provides useful information about small applications (see Figure 2-2 ).
(Figure 2-2 info dialog box of appletviewer)
* Properties: This command allows you to set different network and security configurations for appletviewer (see Figure 2-3 ). The submit dialog box allows appletviewer to specify the HTTP proxy service provider and the firewall proxy service provider to run. You need to know the address and port number of the two proxies. You can get the information from your site manager. Network Access Security Control includes different levels of security, including prohibiting network access. Only hosts that access small applications are allowed, and unlimited access is allowed. When selecting class access, you can specify whether class access is restricted on the machine.
(Figure 2-3 Properties dialog box of appletviewer)
Appletviewer is a basic tool similar to HTML, which processes and displays small Java applications. Java small applications are only part of all WWW pages. It is very important to observe the adaptation of small applications in other HTML files. Therefore, a full-featured browser such as Netscape or hotjava is required.
The only option of appletviewer is debug, which starts appletviewer in the Java language debugger jdb.
2.2 Java interpreter
The Java interpreter can directly explain and execute Java byte code. The specific command line format is as follows:
C:/> JAVA options classname arguments
Classname must include information about all software packages. Not only the class name itself, but also the class name expected by the Java interpreter (not the file name of the Java Byte Code ), all classes running in the interpreter environment must include the main member functions required by the interpreter for the first call to pass the variables included in the command.

Public static void main (string ARGs [])
{
......
}

Table 2-1 contains all the options of the Java interpreter.

Option
── ─
-CS-checksource: This option enables the interpreter to recompile the updated class of the Java source file-re-compile
Compile a modified class.
-Classpath path this option overrides the classpath environment variable to tell Java where
Find the class library. If they are separated by colons, they may contain multiple
Directory.
-Mx X: This option sets the maximum value of the memory allocation pool. The specified pool must be
More than 1,000 bytes. In addition, "K" and "m" can be attached to numbers.
Specify whether it is a kilobytes or megabytes. The default value is 16 Mb.
-Ms X this option sets the minimum value of the memory allocation pool. The specified silence pool is required.
More than 1,000 bytes. In addition, "K" and "m" can be added to numbers.
Whether it is a kilobytes or megabytes. The default value is 1 MB.
-Noasyncgc this option disables the asynchronous useless Unit collection function, only in the program
When it is called or memory overflow, useless Unit collection will be excited.
Active.
-Ss x this option sets the maximum value of the C thread stack to X, and X must be greater
1 kb. The setting method is the same as-MS.
-Oss x this option sets the maximum java stack value to X.
-V,-verbose this option tells Java to set to the standard output whenever the class is called
Backup output information.
-Verify this option tells Java to use verification on all code.
-Verifyremote: This option informs Java to only school the classes loaded by the class loader.
Verification.
-Noverify this option informs Java that verification is not performed.
-Verbosegc this option tells Java to allow useless unit collectors to release memory
Displays a message.
-T this option is available in the Java-G interpreter and
Print them one by one.
-Debug: This option allows the Java debugger to be associated with the Java interpreter session.
. When it is running, Java will display a password for starting
This debugging session.
-D propname = newval This option allows you to change the attribute value at runtime.

Table 2-1 all options of the Java interpreter

2.3 javac Compiler

The javac compiler reads the Java source code and compiles it into byte code. The command line that calls javac is as follows:
C:/> javac options filename. Java
It is worth noting that, unlike the Java interpreter, the javac compiler expects that the file being compiled has the extension. java. Its command line is shown in Table 2-2:

Option
── ─
-Classpath path: This option is used to set the path. On this path, javac looks for the path to be
The called class. This path is a list of directories separated by semicolons.
-D directory this option specifies a root directory. This directory is used to create reflection Software
The number of directories of the package inheritance relationship.
-G this option enables the debugging table in the code generator.
Try to generate byte code.
-Nowarn this option prevents the compiler from generating warnings.
-O this option tells javac to optimize static, final, and
Code generated by the privite member function.
-Verbose: This option indicates that Java displays the compiled source file and any
Information of the called class library.

Table 2-2 javac compiler command line options

2.4 javah header file Generator

The javah program creates C header files and stub files, which are required to package local C member functions into Java. The created header file provides information about the Java class, which is required for C member functions to exchange data with the Java class. The stub file is used to create a c file that associates the structure of the defined Java object with the data of the Java object itself. The command line for calling javah is as follows:
C:/> javah options classname additionalclasses
The javah program is somewhat like a Java interpreter. It only needs the class name and does not need to write the. Class extension. The javah program accepts multiple class names to generate file headers and stub files. Table 2-3 lists the javah program command line options.

Option
── ─
-O outputfile this option tells javah all file headers or stubs that will be generated
Put them in a separate file "outputfile.
-D directory this option tells javah to put the generated file header or stub file
Directory.
-Td directory this option tells the javah program to put the temporary file into the Directory
"Dirrctory" instead of the tmp directory.
-Stubs this option tells javah that it will generate a stub file instead of a header file.
-Verbose: This option instructs javah to output the status of the generated file to the standard output.
Device.
-Classpath path: This option tells javah to use the "path" directory to find class files. Multiple
Separate directories with semicolons.

Table 2-3 javah command line options

2.5 javap anti-Assembler

The javap command disassembles a java byte code file and returns information about the variable part and the member function. The command line is as follows:
C:/> javap options classname additionalclasses
The standard output of javap is a member function of public variables and classes. The following is an output instance. It displays the results of processing the byte code of a simple Java small application using javap. the Java small application will be mentioned again in chapter 5.
Figure 2-4 Java anti-assembler javap output instance
The command line options of the javap anti-assembler are shown in Table 2-4:

Option
── ─
-H this option will create information that can be put into the C header file
-P this option will allow javap to output private and public member functions and variables
-C this option will make javap output the actually compiled
Byte Code
-Classpath path: This option enables javap to search for Java classes in the Path.
-V: Output all information
-Verify run the validator to verify and display debugging information
-Version: output the version information of the javap.

Table 2-4 javap anti-compiler command line options

2.6 Java debugger jdb

The Java scheduler provides a command line debugging environment for Java programs. It can be executed either locally or in a conversation with a remote interpreter.
Jdb can be started on a local machine using the following command:
C:/> jdb classname
When you use the-debug option to start a Java routine, you must provide a jdb password so that jdb can start to run. Table 2-5 contains all jdb commands.

Command function
── ─
Catch calssid is interrupted for a specific exception exit
Classes to list currently known classes
Clear classid: Line clears a breakpoint
Cont continues from the breakpoint
Down [N frames] Move down the stack of a thread
Dump ID [ID...] displays information about all objects
Exit (or quit) to exit the debugger
Help (or ?) List all commands
Ignore classid ignores specific exception exits
List [line number] Show source code
Load classbame load the Java class to be debugged
Locals displays all local variables in the current stack frame
Memory reports memory usage
Methods classid: list the member function sets of a class.
Print ID [ID...] List objects or fields
Resume [threadid...] restores threads (by default, all threads are restored)
Run class [ARGs] starts executing the downloaded Java class
Step: Execute the current row
Stop in classid: method sets a breakpoint in a member function
Stop at classid: Set a breakpoint for line
Suspend [threadid...] stops a thread (by default, all threads are stopped)
Threads threadgroup list threads
Thread threadid sets the current thread
Threadgroups list thread groups
Threadgroup name sets the current thread group
Up [N frames] Move a thread stack up
Use [path] to display or change the source program path
Where [threadid] or all leave the heap line of a thread empty
!! Repeat the previous command

Table 2-5 List of jdb debugger commands

In addition to the commands available during debugging, there are two optional command line variables. They can be used for remote debugging. The usage is as follows:
-Host hostname: This Command tells jdb where to create a remote Java interpreter conversation process-Password
This option tells jdb which password to use to connect to a remote Java conversation process. The Password is provided by running the Java interpreter with the-debug option.
2.7 javadoc API file Generator
The javadoc program reads a Java class file and automatically creates a group of HTML files. These HTML files describe the classes, variables, and member functions of Java class files, apihtml files of all Java class libraries can be created from this program. Javadoc treats the package name or source file list as a variable. Javadoc creates HTML files by marking @ headers. below is the annotation list, which is used by javadoc to create links in HTML files.

Tag Function
── ─
@ See classname This annotation adds a class to the list of provided classes
"See also.
@ See classname # method-This annotation creates a "see" to a specific member function
Name also "entry.
@ Version text this annotation adds a version information entry to the HTML file
@ Author text this annotation adds an author information entry to the HTML file.
@ Param Name Description This annotation uses the member function remarks to describe a member function.
Variable
@ Return Description This annotation uses the member function remarks to describe the return value.
@ Exception classname This annotation uses the member function remarks to connect to the member function to generate
Abnormal exit

Table 2-6 mark used by javadoc

In addition, javadoc can also use two command line parameters:
-Classpath path
This command line specifies the directory to find the Java File
-D directory
This command line is very useful to specify to put the final HTML file. By using it, you can add more comments to the source code, which is very useful for improving the readability of the program.

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.