Java thousand asked _08jdk detailed (009) _java program how to run

Source: Internet
Author: User

Click to enter _ more _java thousand ask

1. How the Java program works

The Java code first needs to be compiled, compiled into a. class file, and then executed through a Java command (executor). Java commands are located in the Jdk/bin directory.

Learn how to compile look here: what is Javac
It does this by starting the Java Runtime Environment (JRE) and then loading the specified class (the JRE searches the following path for class loading at startup: The boot classpath, the extension package path, the user's classpath), and the main () method that invokes the class (learn more about the Main method here: What is the Main method).

The Java command can execute a jar, which must contain a main-class file that specifies the entry for the application. Learn how to hit a jar package look here: How to hit a jar package without using the IDE
Java commands can also be used to launch a JAVAFX application, as well as through the main () method or javafx.application.Application. By javafx.application.Application execution, the executor first constructs an instance of the class, then calls its init () method, and then calls the start (Javafx.stage.Stage) method.

The JAVAW command is the same as the Java command except for one point: JAVAW does not have a console window associated with it. Use JAVAW when you do not want a command prompt window to appear. Of course, if an error occurs with the JAVAW command, the information is displayed through a dialog box.

2. How to use Java commands

Java commands can be executed in the operating system where the JDK is installed. Learn how to install the JDK here: How to install and configure the JDK
Open the command terminal of the operating system, enter the appropriate command line, you can use Java, the following syntax:

java [options] classname [args]

java [options]-jar filename [args]

JAVAW [options] classname [args]

JAVAW [Options]-jar filename [args]

Where parameters can be arranged in any order. The parameters are described as follows:

Options
command-line options, directly executing Java or JAVA-HELP will display all options operations, mainly:

    1. -classpath
      Class path, which sets the path of the user class, overwriting the user class path in the CLASSPATH environment variable. If neither classpath is specified and no-classpath is specified, the user class path is composed of the current directory. Multiple path items with a semicolon ";" to separate.

    2. -version
      Output the product version and exit, typically to test whether the JDK is installed successfully and to view the JDK version used in the current environment.

    3. -version:< value >
      The specified version is required to run.

    4. -VERBOSE:[CLASS|GC|JNI]
      Verbose log output when enabled.

    5. -d< name >=< value >
      Set System Properties.

    6. Other JVM Configurations
      You can set JVM run parameters here, such as memory size-xms10m-xmx10m, and so on.
      See the common configuration of the JVM here: What are the common configuration of the JVM

    7. -esa | -enablesystemassertions
      Enable System assertion

    8. -DSA | -disablesystemassertions
      disabling system assertions

ClassName
The class name to execute, note that this refers to the class name, not the file name, so you cannot add a suffix name. For example:

Java Test

filename
The jar file name you want to execute, here is the file name, and you need the suffix name. For example:

Java-jar Test.jar

args
The input parameter (String type) of the main (string[] args) method is called, and multiple parameters are separated by a space, with no parameters to fill.

Examples are as follows:

public   Class  Testmain {public  static  void  main  (string[] args) throws Exception {if  (args.length > 0 ) {fo R  (String Arg:args) {system.            Out . println ( "args:"  + arg);            }} if  (args.length <= 0 ) { throw  new         Exception ( "Exception" ); }    }}

Compile first: Java Test.java
Then execute: java-xms10m-xmx10m Test 0 1 2
The results are as follows:

args:0
Args:1
Args:2

Java thousand asked _08jdk detailed (009) _java program how to run

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.