Java cmd common commands

Source: Internet
Author: User

Familiar with common commands in Java

Interview Example 11: Use the jar command.

Use the jar command to compress the test folder into a. jar file and briefly describe the structure of its compressed package.

Test Center: For Java programmers, more often than not, the use of integrated Java development tools, such as JBuilder, Eclipse, etc., is not familiar to the most basic Java compilation and common command-line tools. This interview example examines the job seeker's use of the Java command-line basic tools to understand how familiar the job seeker is with Java programming.

Occurrence frequency: ★

Analytical

Skilled Java developers should be familiar with common Java command-line tools. Job seekers should be familiar with tools such as Javac, Java, and jars.

1. Javac

Javac is the standard compilation tool for JDK, common in the form of: Javac < options > < source files >. Some of its possible options include:

-G: Generates all debugging information.

-g:none: Generates no debug information.

-g:{lines,vars,source}: Generates only partial debug information.

-nowarn: Generates no warnings.

-verbose: Outputs information about what the compiler is doing.

-deprecation: The output uses the source program location of the API that is not encouraged to use.

-classpath < path;: Specifies the location of the user class file.

-sourcepath < path;: Specifies the location of the input source files.

-bootclasspath < path: Overwrites the location of the bootstrap file.

-extdirs < Directory (multiple): Overrides the location of the installed extension class.

-D < directory;: Specifies the location of the output class file.

-encoding < code;: Specifies the character set encoding used in the source file.

-target <: Generates a class file for the specified virtual machine version.

Common problem: If the jar package is not found when compiling the. Java source file using Javac, the-classpath option is required. For example:

Javac-classpath.; Jar01.jar;jar02.jar, ...; Jarn.jar Class_name.java

Using the-classpath option, specifies the location of the class library when compiling Java source code. Typically used for this class library is not in the current CLASSPATH environment variable.

2. Java

Java commands are the default Java executables for JDK, and it is worth noting here that the standard Java package form is required when executing a. class file with a package. For example:

Java Com.nsfc.hello

3. Jar

With the JDK installed, an executable file exists in the bin directory under the JDK installation directory, and the file name Jar.exe,linux under Windows is the jar. It is required to run the Tools.jar file in the Lib directory under the JDK installation directory. The jar command line format is:

jar {ctxu}[vfm0m] [jar-file] [manifest-file] [-C directory] file name

where {CTXU} is a sub-command of the jar command, each time the jar command can contain only one subcommand, these subcommands have the following meanings.

-C: Creates a new jar file package.

-T: Lists the list of contents of the jar file package.

-X: Expands the specified file or all files of the jar package.

-U: Update the existing JAR package (add file to jar package).


The options in [vfm0m] can be either optional or optional, and they are option parameters for the jar command.

-V: Generate a specific report and print to standard output.

-F: Specifies the jar file name, which is usually required.

-M: Specifies the manifest manifest file that needs to be included.

-0: Store only, not compress, so that the resulting jar file package will be larger than the volume without the parameter, but faster.

-M: does not produce a manifest for all items (the Manifest) file, this parameter ignores the-m parameter.)

[jar-file]: A jar file package that needs to be generated, viewed, updated, or unpacked, which is a subordinate parameter to the-f parameter.

[manifest-file]: The manifest manifest file, which is a subordinate parameter of the-m parameter.

[-C Directory]: Represents the move to the specified directory to perform the operation of this jar command. It is equivalent to using the CD command to go to the directory, and then execute the JAR command without the-c parameter, which can only be used when creating and updating jar packages.

File name: Specifies a list of files/directories that are files/directories to add to the jar file package. If a directory is specified, the jar command automatically packages all files and subdirectories in the directory when it is packaged.

Packaged with the JDK's Jar command, a meta-inf directory is automatically generated in the compressed package with a MANIFEST.MF file.

Use the jar command to compress as follows:

Jar CF Test.jar Test

To compress all files in the test directory under the current directory into the Test.jar file, use the WinRAR software to see the zip file as shown in the directory result 2.6.

(Click to view larger image) Figure 2.6 The structure of the jar compressed document
Answer

You can use the jar CF Test.jar Test command to complete the compression. The compressed package contains a test folder and a Meta-inf folder with a MANIFEST.MF file.

Interview Example 12: How to execute the main () method.

Which command in the Java SDK is used to execute the main () method of test?

(a) Java test.

(b) Javac test.

(c) Java Test.java.

(d) Java Test.class.

(e) Java Test.main.

Test Center: Examine how familiar the job seeker is with the Java command.

Occurrence frequency: ★

Analytical

Candidates are prone to the wrong choice (d), in fact, the Java command only requires the name of the class file, you do not have to join the. class full name. If you use the Java test.class command, the system will assume that this is the structure of a package and will look for the Test.class.class file. The following exception message appears:

Exception in thread "main" Java.lang.noclassdefaulterror:test/class
Tip the appropriate class file could not be found.

Answer: (a).

Java cmd common commands

Related Article

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.