[ Pobierz całość w formacie PDF ]
.The runtime interpreter provides the support to run Java executable programs in compiled, bytecode format.The runtime interpreter acts as a command-line tool for running nongraphical Java programs; graphical programs require the display support of a browser.The syntax for using the runtime interpreter follows:java Options Classname ArgumentsThe Classname argument specifies the name of the class you want to execute.If the class resides in a package, you must fully qualify the name.For example, if you want to run a class called Roids that is located in a package called ActionGames, you would execute it in the interpreter like this:java ActionGames.RoidsWhen the Java interpreter executes a class, what it is really doing is executing the main method of the class.The interpreter exits when the main method and any threads created by it are finished executing.The main method accepts a list of arguments that can be used to control the program.The Arguments argument to the interpreter specifies the arguments passed into the main method.For example, if you have a Java class called TextFilter that performs some kind of filtering on a text file, you would likely pass the name of the file as an argument, like this:java TextFilter SomeFile.txtThe Options argument specifies options related to how the runtime interpreter executes the Java program.Following is a list of the most important runtime interpreter options:l-debugll-checksource, -csll-classpath Pathll-verbose, -vll-verbosegcll-verifyll-verifyremotell-noverifyll-DPropertyName=NewValuelThe -debug option starts the interpreter in debugging mode, which enables you to use the Java debugger (jdb) in conjunction with the interpreter.The -checksource option causes the interpreter to compare the modification dates of the source and executable class files.If the source file is more recent, the class is automatically recompiled.NOTEThe -checksource and -verbose options provide shorthand versions, -cs and -v.You can use these shorthand versions as a convenience to save typing.The Java interpreter uses an environment variable, CLASSPATH, to determine where to look for user-defined classes.The CLASSPATH variable contains a semicolon-delimited list of system paths to user-defined Java classes.Actually, most of the Java tools use the CLASSPATH variable to know where to find user-defined classes.The -classpath option informs the runtime interpreter to override CLASSPATH with the path specified by Path.The -verbose option causes the interpreter to print a message to standard output each time a Java class is loaded.Similarly, the -verbosegc option causes the interpreter to print a message each time a garbage collection is performed.A garbage collection is performed by the runtime system to clean up unneeded objects and to free memory.The -verify option causes the interpreter to run the bytecode verifier on all code loaded into the runtime environment.The verifier's default function is to only verify code loaded into the system using a class loader.This default behavior can also be explicitly specified using the -verifyremote option.The -noverify option turns all code verification off.The -D option enables you to redefined property values.PropertyName specifies the name of the property you want to change, and NewValue specifies the new value you want to assign to it.The CompilerThe Java compiler (javac) is used to compile Java source code files into executable Java bytecode classes.In Java, source code files have the extension.java.The Java compiler takes files with this extension and generates executable class files with the.class extension.The compiler creates one class file for each class defined in a source file.This means that many times a single Java source code file will compile into multiple executable class files.When this happens, it means that the source file contains multiple class definitions.The Java compiler is a command-line utility that works similarly to the Java runtime interpreter.The syntax for the Java compiler follows:javac Options FilenameThe Filename argument specifies the name of the source code file you want to compile.The Options argument specifies options related to how the compiler creates the executable Java classes.Following is a list of the compiler options:l-classpath Pathll-d Dirll-gll-nowarnll-verbosell-OlThe -classpath option tells the compiler to override the CLASSPATH environment variable with the path specified by Path.This causes the compiler to look for user-defined classes in the path specified by Path.The -d option determines the root directory where compiled classes are stored.This is important because many times classes are organized in a hierarchical directory structure.With the -d option, the directory structure will be created beneath the directory specified by Dir.An example of using the -d option follows:javac -d.\ FlowerIn this example, the output file Flower.class would be stored in the parent directory of the current directory.If the file Flower.java contained classes that were part of a package hierarchy, the subdirectories and output classes would fan out below the parent directory.The -g compiler option causes the compiler to generate debugging tables for the Java classes.Debugging tables are used by the Java debugger, and contain information such as local variables and line numbers.The default action of the compiler is to only generate line numbers.The -nowarn option turns off compiler warnings.Warnings are printed to standard output during compilation to inform you of potential problems with the source code.It is sometimes useful to suppress warnings by using the -nowarn option.The -verbose option has somewhat of an opposite effect as -nowarn; it prints out extra information about the compilation process.You can use -verbose to see exactly what source files are being compiled.The -O option causes the compiler to optimize the compiled code.In this case, optimization simply means that static, final, and private methods are compiled inline.When a method is compiled inline, it means that the entire body of the method is included in place of each call to the method.This speeds up execution because it eliminates the method call overhead.Optimized classes are usually larger in size, to accommodate the duplicate code.The -O optimization option also suppresses the default creation of line numbers by the compiler.The Applet ViewerThe applet viewer is a tool that serves as a minimal test bed for final release Java applets.You can use the applet viewer to test your programs instead of having to wait for HotJava to support the final release of Java.Currently, the applet viewer is the most solid application to test final release Java programs, because the HotJava browser still only supports alpha release applets [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • sp2wlawowo.keep.pl