1. Run the class file
Execute the class file with the main method and the Java Virtual Machine command parameter Behavior
Java <class file name>
Note: do not include the file Suffix in the class file name. Class
For example
Java Test
If the class file to be executed contains a package, it is used in the class file.
Package <package name>
It should be executed in the package's base path, Java VM command line parameters
Java <package name>. Class file name
For example
In packagetest. Java, the package name is com. ee2ee. test. The corresponding statement is
Package com. ee2ee. test;
The directory for packagetest. Java and the compiled class file packagetest. Class is as follows:
Classes
|__ Com
|__ Ee2ee
|__ Test
|__ Packagetest. Java
|__ Packagetest. Class
To run packagetest. Class, run it in the classes directory.
Java com. ee2ee. Test. packagetest
Ii. Run the class in the jar file
The principle is the same as running the class file. You only need to add the parameter-CP <JAR File Name>.
For example, run com. ee2ee. Test. packagetest in test. Jar. The command line is as follows:
Java-CP test. Jar com. ee2ee. Test. packagetest
3. Display JDK version information
When a machine has multiple JDK versions, you need to know which version of JDK is currently used. You can use the-version parameter to know the version and command behavior.
Java-version
4. Increase the maximum memory available for virtual machines
The maximum memory available for Java virtual machines is limited. The default value is usually 64 MB or 128 MB.
If an application loads data into memory to improve performance and occupies a large amount of memory, such as exceeding the default maximum of 128 MB, it needs to increase the maximum memory available for the Java Virtual Machine, otherwise, an out of Memory exception occurs. When starting Java, you must use the following two parameters:
-Memory size used for XMS Java VM Initialization
-Maximum memory available for xmx Java Virtual Machine
The size set in the preceding two command line parameters can be in units. For example, 256 MB indicates MB.
Example
Java-xms128m-xmx256m ......
Indicates that the memory used for Java VM Initialization is 128 MB, and the maximum memory available is 256 MB.
For tomcat, you can modify its script Catalina. Sh (UNIX platform) or Catalina. BAT (Windows platform) and set the variable java_opts. For example
Java_opts = '-xms128m-xmx256m'