First, run the class file
Executes the class file with the main method, and the command behavior:
Java <class file name >
Note: The class file name does not have a file suffix. class
For example:
Copy Code code as follows:
If the executing class file is wrapped, that is, it is used in the class file: Package < package name >
That should be performed under the base path of the package, the command behavior:
Java < package name. Class filename
For example: In Packagetest.java, the package name is: Com.ee2ee.test, and the corresponding statement is:
Package com.ee2ee.test;
The Packagetest.java and compiled class file Packagetest.class directory is as follows:
Classes
|__com
|__ee2ee
|__test
|__packagetest.java
|__packagetest.class
To run Packagetest.class, you should execute it in the classes directory:
Copy Code code as follows:
Java com.ee2ee.test.PackageTest
Second, run the class in the Jar file
Principle and run class file, just add parameter-cp <jar filename > can.
For example, to perform the class com.ee2ee.test.PackageTest in Test.jar, the command line is as follows:
Copy Code code as follows:
JAVA-CP Test.jar Com.ee2ee.test.PackageTest
Third, display JDK version information
When you have more than one JDK version on a machine, you need to know that you are currently using that version of the JDK, using the parameter-version to know its version, command behavior:
Copy Code code as follows:
Iv. increase the maximum memory available to the virtual machine
The maximum memory that can be used by a Java Virtual machine is limited, and the default value is usually 64MB or 128MB. If an application uses more memory to load data into memory in order to improve performance, such as exceeding the default maximum of 128MB, you need to increase the maximum amount of memory available to the Java virtual machine, otherwise there will be an out of Memory (low system memory) exception. When you start Java, you need to use the following two parameters:
-XMS the memory size used when Java Virtual machine initialization
-XMX the maximum memory that Java virtual machines can use
The size set in the above two parameters can be in units, for example: 256m means 256MB
An example is provided:
Copy Code code as follows:
Indicates that the memory used for Java Virtual machine initialization is 128MB and the maximum memory available is 256MB.
For Tomcat, you can modify its script catalina.sh (Unix platform) or Catalina.bat (Windows platform) and set variable java_opts, for example:
Copy Code code as follows:
java_opts= '-xms128m-xmx256m '
In the console output information, there is a command of-X (note uppercase), which is the command to view the JVM configuration parameters.
Second, use the Java-x command to view the configuration instructions for the JVM:
1,-xmixed Mixed mode execution (default)
Mixed Mode execution
2,-xint interpreted mode execution only
Interpret mode execution
3.-xbootclasspath:<directories and Zip/jar files separated by;>
Set search path for bootstrap classes and resources
Set Zip/jar resource or Class (. class file) to store directory path
3.-xbootclasspath/a:<directories and Zip/jar files separated by;>
Append to end of bootstrap class path
Append Zip/jar resource or Class (. class file) to directory path
4.-xbootclasspath/p:<directories and Zip/jar files separated by;>
Prepend in front of bootstrap class path
Preload Zip/jar resources or classes (. class files) to store directory paths
5,-XNOCLASSGC disable Class garbage collection
Turn off the class garbage collection feature
6,-XINCGC enable incremental garbage collection
Turn on garbage collection for classes
7.-xloggc:<file> Log GC status to a file with time stamps
Log the garbage back to a file.
8,-xbatch Disable background compilation
Turn off background compilation
9,-xms<size> set initial Java heap size
Set JVM initialization heap memory size
10,-xmx<size> set maximum Java heap size
To set the maximum heap memory size for the JVM
11.-xss<size> set Java thread stack size
Set JVM stack memory size
12,-xprof output CPU profiling data
Enter CPU Summary table data
13,-xfuture enable strictest checks, anticipating future default
Perform rigorous code checks to anticipate possible scenarios
14.-xrs reduce use of the OS signals by JAVA/VM (documentation)
Restore operating system signals through the JVM
15,-xcheck:jni perform. Additional checks for JNI functions
Perform a check on a JNI function
16.-xshare:off do not attempt to use shared class data
Do not use the shared class data as much as possible
17.-xshare:auto use shared class data if possible (default)
Use the data of shared classes as much as possible
18,-xshare:on require using shared class data, otherwise fail.
Use shared class data as much as possible, otherwise the run fails
How do you use these parameters? In fact, all command lines are so used, I will give a simple example of helloworl to illustrate the use of this parameter, very simple.
Copy Code code as follows:
Helloworld.java
public class HelloWorld {
public static void Main (string[] args) {
System.out.println ("Hello world!");
}
}
Compile and run:
D:\j2sdk15\bin>javac Helloworld.java
d:\j2sdk15\bin>java-xms256m-xmx512m HelloWorld
Hello world!
The above mentioned is the entire content of this article, I hope you have a new understanding of the method of running Java class file.