Java Tutorial/Language/Introduction — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 05:06, 1 июня 2010
Содержание
- 1 A profiler is used to analyze how much time a program spends in each part of the code.
- 2 Commonly Used Java Command Options
- 3 Developing a Java program involves
- 4 Java Compiler Options
- 5 Java memory command line arguments
- 6 JDK Utilities
- 7 See the details of the compilation: use the verbose option
- 8 Set the memory available to the JVM
- 9 Some of the Options Supported by the javap Utility
- 10 The jarsignature Tool
- 11 The jar Tool
- 12 The javadoc Tool
- 13 The javap Tool
- 14 The java Tool
- 15 The jconsole Tool
- 16 The native2ascii Tool
- 17 The syntax to use the javac tool
A profiler is used to analyze how much time a program spends in each part of the code.
You can use this information to determine which parts of a program to optimize.
java -prof TestDrive
Commonly Used Java Command Options
Option Description
-client Runs the client VM
-serve Runs the server VM, which is optimized for server systems
-classpath adirectories A list of directories or JAR or Zip archive and archives files used to search for class files
-cp <search path> Same as -classpath
-D name=value Sets a system property
-verbose Enables verbose output
-version Displays the JRE version number, then stops
-showversion Displays the JRE version number, then continues
-? or -help Lists the standard options
-X Lists nonstandard options
-ea or -enableassertions Enables the assert command
-ea classes or packages Enables assertions for the specified classes or packages
-esa or -enablesystemassertions Enables system assertions
-dsa or -disablesystemassertions Disables system assertions
Developing a Java program involves
- writing code,
- compiling it into bytecode
- running the bytecode.
Your First Java Program.
public class MainClass {
public static void main(String[] args) {
System.out.println("Java");
}
}
Java Compiler Options
Folder Description
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines, vars, source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
Java memory command line arguments
java -Xms32m -Xmx200m -XX:MaxPermSize=128m com.SomeWonderfulApp
JDK Utilities
ToolFunctionjavacThe Java compiler. Converts Java source code into bytecodes.javaThe Java interpreter. Executes Java application bytecodes directly from class files.appletviewerA Java interpreter that executes Java applet classes hosted by HTML files.javadocCreates HTML documentation based on Java source code and the comments it contains.rmicCreates class files that support Remote Method Invocation (RMI).rmiregistryRegistry used to gain access to RMI objects on a specific machine.rmidActivation system daemon for RMI object registration and activation.native2asciiSpecial program used to convert between standard Latin-1 Unicode characters and other international encoding schemes.jarJava Archive (JAR) file generator. JAR files allow multiple Java classes and resources to be distributed in one compressed file.keytoolUsed for security key generation and management.jarsignerImplements digital signing of JAR and class files. Allows applets to be certified by trusted authorities.policytoolAllows user-installation-level security policy configuration.
See the details of the compilation: use the verbose option
javac -verbose TestDrive.java
Set the memory available to the JVM
java -mx20m myApp // for max
java -ms20m myApp // for start
Some of the Options Supported by the javap Utility
Option Description
-b This command ensures backward compatibility with earlier versions of javap.
-bootclasspath This command, followed by a path, specifies the path from which to load the bootstrap classes. Normally these would be classes contained in the /lib/rt.jar archive.
-c This command prints the JVM instructions for the execution of each method. This tells you what the bytecode for each method actually does.
-classpath This command, followed by a user-specified class path, overrides the system CLASSPATH environment variable.
-extdirs This command, followed by a directory, overrides the location the system searches for installed extensions. The default location is /lib/ext.
-help This command prints information about the javap utility.
-Jflag This command passes the specified flag directly to the runtime system.
-l This command displays line and local variables.
-package This command shows only package, protected, and public classes and members. This is the default.
-private This command shows information about all classes and members.
-protected This command displays information about protected and public classes and members only.
-public This command shows information only about public classes and members.
-s This command prints internal type signatures.
-verbose This command prints additional information for each method including stack size, local variable information, and arguments.
The jarsignature Tool
The jarsigner tool enables you to sign Java ARchive (JAR) files and verify the signatures of signed JAR files.
The jarsigner tool uses key and certificate information from a keystore to generate digital signatures for JAR files.
A keystore is a database of private keys.
The jarsignature also uses an entity"s private key to generate a signature.
The syntax to use the jarsignature tool is:
jarsigner [ options ] jar-file alias
jarsigner -verify [ options ] jar-file
The jar Tool
The jar tool creates a JAR archive file by combining multiple files of a Java application.
The jar tool compresses content based on the ZIP and ZLIB compression formats.
You can also use the jar tool to extract the content of a JAR file.
The syntax to use the jar tool is:
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files
OptionDescriptioncCreates a new archive.tLists the contents of an archive.xExtracts contents from an archive.uUpdates an existing archive.vDisplays output at the command prompt while the jar tool performs an operation.fSpecifies the name of the archive file.mIncludes a specified manifest file in the archive.oInstructs the jar tool not to compress content.MInstructs the jar tool not to create a manifest file for an archive. The jar tool, by default, creates an empty manifest file in an archive.CSpecifies the directories to include in the archive.
The javadoc Tool
The javadoc tool generates HTML documentation from Java source files.
The javadoc tool locates and parses the documentation comments present in a Java source file and produces a set of HTML pages describing the class, methods, and variables present in the source file.
The syntax to use the javadoc tool is:
javadoc [options] [packagenames] [sourcefilenames] [-subpackages pkg1:pkg2:...] [@argfiles]
- options refers to the command line options that you can pass to the javadoc tool.
- packagenames refers to multiple packages, separated by spaces, that javadoc should use to generate documentation. For example:
- packagesnames java.lang java.lang.reflect java.awt
- sourcefilenames refers to the source files for which javadoc needs to generate documentation.
- -subpackages: Generates documentation from the source files in specified packages and recursively in their subpackages.
- @argfiles: Refers to a file that contains Javadoc options.
The javap Tool
The javap command displays information about the methods, variables, and parameters present in a class file.
The output of the javap tool depends on the options used. If you do not specify any options while using the jap tool, the javap tool prints the package, protected, and public fields and methods of the classes passed to the tool.
The syntax to use the javap tool is:
javap [options] class. . .
OptionDescription-helpDisplays a help message for the javap tool.publicShows only the public classes and members.protectedShows only the public and protected classes and members.privateShows all classes and members.packageShows the package, protected, and public classes and members. This is the default option of the javap tool.-classpath pathSpecifies the class path that javap should use to locate the class file to disassemble.
The java Tool
The java tool executes a Java class.
To execute a Java class, the java tool loads the bytecode of the specified class and invokes the main() method of the class.
You can also use the java tool to run executable JAR files.
The syntax to use the java tool to execute a Java class is:
java [options] <class-name>
options refers to the command line options that you can pass to the java tool.
The class-name specifies the name of the class file to execute.
OptionDescription-clientSelects the Java HotSpot Client Virtual Machine (VM) to use for executing a class.-serverSelects the Java HotSpot Server VM to use for executing a class.-cp classpathSpecifies a list of directories, JAR archives, and ZIP archives to search class files.-jarExecutes a JAR file.-versionDisplays the JVM version.
The jconsole Tool
The jconsoletool is a JMX-compliant graphical tool for monitoring a Java virtual machine.
The jconsoletool can monitor both local and remote JVMs.
The jconsoletool can monitor and manage an application.
The syntax to use jconsoletool is:
jconsole [ options ] [ connection ... ]
OptionDescription-interval=nAllows you to set the update interval to n seconds.-notileSpecifies not to tile windows initially.-pluginpath pluginsSpecifies a list of the directories or JAR files that are searched for JConsole plug-ins.-helpDescribes the jconsoletool option.
The native2ascii Tool
You can use the native2ascii tool to convert files with native encoded characters to a file with Unicode encoded characters.
The syntax to use the native2ascii tool is:
native2ascii [options] [inputfile [outputfile]]
- options: Refers to various options that you can use to pass information or configure the native2ascii tool.
- inputfile: Refers to the file that contains native encoded characters.
- outputfile: Represents the file that will contain the converted text.
Options of the native2ascii Tool
OptionDescription-reverseAllows you to perform the reverse operation, which reverse the sense of the conversion.-encoding encoding_nameSpecifies the encoding name that is used by the conversion procedure.-JoptionAllows you to pass configuration options to JVM.
The syntax to use the javac tool
javac [options] [sourcefiles] [classes]
- options: Refers to command line options.
- sourcefiles: Refers to the source files that need to be compiled.
- classes: Refers to one or more classes to be processed for annotations.
OptionDescription-cp path or -classpath pathSpecifies the Java classpath.-d directorySets the destination directory to store class files.-gGenerates debugging information.-g:noneInstructs the javac tool not to generate any debugging information.-helpPrints information about the options of the javac tool.-XlintDisplays warnings against the use of deprecated classes and methods.-Xlint:-nameDisables deprecation warnings for a specified class, interface, or method.-Xlint:pathDisplays a warning when you specify a directory to compile but the directory does not exist.